DBIx::Custom::Mapper - Mapper of parameter
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 );
my $param = $mapper->param; $mapper = $mapper->param({title => 'Perl', author => 'Ken'});
Parameter.
my $pass = $mapper->pass; $mapper = $mapper->pass([qw/title author/]);
the key and value is copied without change when map method is executed.
map
my $condition = $mapper->condition; $mapper = $mapper->condition('exists');
Mapping condtion, default to length.
length
You can set the following values to condition.
condition
exists
condition => 'exists'
If key exists, key and value is mapped.
defined
condition => 'defined';
If value is defined, key and value is mapped.
condition => 'length';
If value is defined and has length, key and value is mapped.
code reference
condition => sub { defined $_[0] }
You can set code reference to condtion. The subroutine return true, key and value is mapped.
condtion
DBIx::Custom::Mapper inherits all methods from Object::Simple and implements the following new ones.
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.
param
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
key
# Rule price => {key => 'book.price'} # Parameter price => 1900, # New parameter 'book.price' => 1900,
If value is used, only value is mapped to new parameter
value
# 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 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 condtion 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.
pass
$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}
2 POD Errors
The following errors were encountered while parsing the POD:
You forgot a '=back' before '=head1'
You can't have =items (as at line 243) unless the first thing after the =over is an =item
To install DBIx::Custom, copy and paste the appropriate command in to your terminal.
cpanm
cpanm DBIx::Custom
CPAN shell
perl -MCPAN -e shell install DBIx::Custom
For more information on module installation, please visit the detailed CPAN module installation guide.