GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
DBIx::Custom::Mapper(3) User Contributed Perl Documentation DBIx::Custom::Mapper(3)

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.

  my $condition = $mapper->condition;
  $mapper = $mapper->condition('exists');

Mapping condtion, default to "length".

You can set the following values to "condition".

  • exists

      condition => 'exists'
        

    If key exists, key and value is mapped.

  • defined

      condition => 'defined';
        

    If value is defined, key and value is mapped.

  • length

      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.

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.

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}

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
2017-03-28 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.