ResultSet/CallbackInflator.pm

filter: Statementstmt 100% 13 / 13 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod 100% 1 / 1 totaltotal 100% 18 / 18 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.0
« ResultClass/CallbackInflator.pm ↑ Summary
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package DBIx::Class::ResultSet::CallbackInflator;
5  
6 1 ▶use DBIx::Class::ResultClass::CallbackInflator;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 sub inflator {
9 1 ▶ my ($self, $callback, @args) = @_;
Subroutine inflator: called CC=1 SCAR=0.0
Pod documented
10 1 my $result_instance = DBIx::Class::ResultClass::CallbackInflator
11 ->new(callback=>$callback, args=>\@args);
12 1 return $self->search(+{}, +{result_class=>$result_instance});
13 }
14  
15 1 1;
16  
17 =head1 NAME
18  
19 DBIx::Class::ResultSet::CallbackInflator - Easy way to use DBIx::Class::ResultClass::CallbackInflator
20  
21 =head1 SYNOPSIS
22  
23 Given a L<DBIx::Class::ResultSet> that consumes this component, such as the
24 following:
25  
26 package MySchema::ResultSet::Peson;
27  
28 use strict;
29 use warnings;
30 use parent 'DBIx::Class::ResultSet';
31  
32 __PACKAGE__->load_components('ResultSet::CallbackInflator');
33  
34 ## Additional custom resultset methods, if any
35  
36 1;
37  
38 Then later when you have a resultset of that class:
39  
40 my $rs = $schema->resultset('Person')
41 ->inflator(sub {
42 my ($cb, $source, $data, $optional_prefetch, @args) = @_;
43 return $data;
44 }, @args);
45  
46 When the resultset in C<$rs> is unrolled the callback will be run for each row returned from
47 the query and you can customize the response (must be a reference). For example you might use
48 this to change or add to the existing C<$data> for a purpose that is meaningful to your
49 application.
50
51 =head1 DESCRIPTION
52  
53 Lets you decide how a resultset inflates any data in rows from the database table
54 it is pointing at (with any prefetch information included) by using a coderef
55 which will in in place of 'inflate_result'.
56  
57 This is basically sugar for L<DBIx::Class::ResultClass::CallbackInflator>
58  
59 =head1 METHODS
60  
61 This component defines the following methods.
62  
63 =head2 inflator
64  
65 Allows you to use a callback as a custom inflator class. Example:
66  
67 $rs->inflator(sub {
68 my ($cb, $result_source, \%columndata, \%prefetcheddata, @args) = @_;
69 return ...
70 })->all;
71  
72 Should return a reference to the representation of the row that you are seeking.
73  
74 B<NOTE>: The last argument C<\%prefetcheddata> is optional. If there isn't any the
75 location in C<@_> will be undef so that any @args passed will be in expected position.
76  
77 B<NOTE>: The call to ->inflator returns the original resultset to allow for easy
78 chaining.
79  
80 =head1 AUTHOR
81  
82 See L<DBIx::Class::ResultClass::CallbackInflator>.
83  
84 =head1 COPYRIGHT & LICENSE
85  
86 See L<DBIx::Class::ResultClass::CallbackInflator>.
87  
88 =cut
« ResultClass/CallbackInflator.pm ↑ Summary