NAME
DBIx::Class::ResultSet::CallbackInflator - Easy way to use DBIx::Class::ResultClass::CallbackInflator
SYNOPSIS
Given a DBIx::Class::ResultSet that consumes this component, such as the following:
package MySchema::ResultSet::Peson;
use strict;
use warnings;
use parent 'DBIx::Class::ResultSet';
__PACKAGE__->load_components('ResultSet::CallbackInflator');
## Additional custom resultset methods, if any
1;
Then later when you have a resultset of that class:
my $rs = $schema->resultset('Person')
->inflator(sub {
my ($cb, $source, $data, $optional_prefetch, @args) = @_;
return $data;
}, @args);
When the resultset in $rs
is unrolled the callback will be run for each row returned from the query and you can customize the response (must be a reference). For example you might use this to change or add to the existing $data
for a purpose that is meaningful to your application.
NOTE Currently we localize %_
in the callback coderef to be %$data
to make it easier to do the most standard (I think) types of transformations.
DESCRIPTION
Lets you decide how a resultset inflates any data in rows from the database table it is pointing at (with any prefetch information included) by using a coderef which will in in place of 'inflate_result'.
This is basically sugar for DBIx::Class::ResultClass::CallbackInflator
METHODS
This component defines the following methods.
inflator
Allows you to use a callback as a custom inflator class. Example:
$rs->inflator(sub {
my ($cb, $result_source, \%columndata, \%prefetcheddata, @args) = @_;
return ...
})->all;
Should return a reference to the representation of the row that you are seeking.
NOTE: The last argument \%prefetcheddata
is optional. If there isn't any the location in @_
will be undef so that any @args passed will be in expected position.
NOTE: The call to ->inflator returns the original resultset to allow for easy chaining.
AUTHOR
See DBIx::Class::ResultClass::CallbackInflator.