Skip site navigation (1)Skip section navigation (2)

FreeBSD Manual Pages

  
 
  

home | help
DBIx::Custom::Mapper(3User Contributed Perl DocumentatiDBIx::Custom::Mapper(3)

NAME
       DBIx::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
	 );

ATTRIBUTES
   param
	 my $param = $mapper->param;
	 $mapper = $mapper->param({title => 'Perl', author => 'Ken'});

       Parameter.

   pass
	 my $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".

       o   exists

	     condition => 'exists'

	   If key exists, key and value	is mapped.

       o   defined

	     condition => 'defined';

	   If value is defined,	key and	value is mapped.

       o   length

	     condition => 'length';

	   If value is defined and has length, key and value is	mapped.

       o   code	reference

	     condition => sub {	defined	$_[0] }

	   You can set code reference to "condtion".  The subroutine return
	   true, key and value is mapped.

METHODS
       DBIx::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 ERRORS
       Hey! The	above document had some	coding errors, which are explained
       below:

       Around line 201:
	   You forgot a	'=back'	before '=head1'

       Around line 239:
	   You can't have =items (as at	line 243) unless the first thing after
	   the =over is	an =item

perl v5.32.1			  2017-03-28	       DBIx::Custom::Mapper(3)

NAME | SYNOPSYS | ATTRIBUTES | METHODS | POD ERRORS

Want to link to this manual page? Use this URL:
<https://www.freebsd.org/cgi/man.cgi?query=DBIx::Custom::Mapper&sektion=3&manpath=FreeBSD+13.0-RELEASE+and+Ports>

home | help