The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.

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.

  • 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.

METHODS

DBIx::Custom::Mapper inherits all methods from Object::Simple and implements the following new ones.

map

    my $new_param = $mapper->map(
        price => 'book.price', # Key
        title => sub { '%' . $_[0] . '%'}, # Value
        author => ['book.author', sub { '%' . $_[0] . '%'}] # Key and value
    );

Map param's key and value and return 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%',
    }

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 => ['book.price', {condition => 'defined'}]
        title => [sub { '%' . $_[0] . '%'}, {condition => 'defined'}] # Value
        author => ['book.author', sub { '%' . $_[0] . '%'}, condtion => 'exists']
    );

If pass attrivute is set, the keys and value is copied without change.

    $mapper->pass([qw/title author/]);
    my $new_param = $mapper->map(price => 'book.price');

The following hash reference

    {title => 'Perl', author => 'Ken', price => 1900}

is mapped to

    {title => 'Perl', author => 'Ken', 'book.price' => 1900}

1 POD Error

The following errors were encountered while parsing the POD:

Around line 174:

You forgot a '=back' before '=head1'