|
NAMEDBIx::Custom::Mapper - Mapper of parameter SYNOPSYS my $mapper = $dbi->mapper(param => $param);
my $new_param = $mapper->map(
title => 'book.title', # Key
author => sub { '%' . $_[0] . '%'} # Value
price => ['book.price' => sub { '%' . $_[0] . '%' }], # Key and value
);
ATTRIBUTESparam my $param = $mapper->param;
$mapper = $mapper->param({title => 'Perl', author => 'Ken'});
Parameter. passmy $pass = $mapper->pass; $mapper = $mapper->pass([qw/title author/]); the key and value is copied without change when "map" method is executed. condition my $condition = $mapper->condition;
$mapper = $mapper->condition('exists');
Mapping condtion, default to "length". You can set the following values to "condition".
METHODSDBIx::Custom::Mapper inherits all methods from Object::Simple and implements the following new ones. map my $new_param = $mapper->map(
price => {key => 'book.price'}
title => {value => '%<value>%'}
author => ['book.author' => '%<value>%']
);
my $new_param = $mapper->map(
price => {key => 'book.price'}
title => {value => sub { '%' . shift . '%'}}
author => ['book.author' => sub { '%' . shift . '%'}]
);
Map parameter in "param" attribute into new parameter. For example, if "param" is set to {
price => 1900,
title => 'Perl',
author => 'Ken',
issue_date => '2010-11-11'
}
The following hash reference is returned. {
'book.price' => 1900,
title => '%Perl%',
'book.author' => '%Ken%',
}
Syntax:
* String => Hash reference # String => Hash reference
price => {key => 'book.price'}
title => {value => '%<value>%'}
title => {value => sub { '%' . shift . '%'}}
If "key" is used, only key name is mapped to new parameter # Rule
price => {key => 'book.price'}
# Parameter
price => 1900,
# New parameter
'book.price' => 1900,
If "value" is used, only value is mapped to new parameter # Rule
title => {value => '%<value>%'}
title => {value => sub { '%' . shift . '%'}}
# Parameter
title => 'Perl',
# New parameter
title => '%Perl%',
"<"value>> is replaced by original value. You can use code reference to convert original value. * String => Array reference # String => Array reference author => ['book.author' => '%<value>%'] Both key name and value is mapped to new parameter. This is same as the following syntax. # Rule
{key => 'book.author', value => '%<value>%'}
By default, If the value has length, key and value is mapped. title => 'Perl' # Mapped
{title => '' } # Not mapped
{title => undef} # Not mapped
{} # Not mapped
You can set change mapping condition by "condition" attribute. $mapper->condition('defined');
Or you can set "condition" option for each key. my $new_param = $mapper->map(
price => {key => 'book.price', condition => 'defined'}]
title => {value => sub { '%' . $_[0] . '%'}, condition => 'defined'}
author => ['book.author', sub { '%' . $_[0] . '%'}, 'exists']
);
If "pass" attribute is set, the keys and value is copied without change. $mapper->pass([qw/title author/]);
my $new_param = $mapper->map(price => {key => 'book.price'});
The following hash reference {title => 'Perl', author => 'Ken', price => 1900}
is mapped to {title => 'Perl', author => 'Ken', 'book.price' => 1900}
POD ERRORSHey! The above document had some coding errors, which are explained below:
|