ResultClass/CallbackInflator.pm

filter: Statementstmt 92.3% 12 / 13 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 80.0% 4 / 5 Podpod 100% 1 / 1 totaltotal 89.4% 17 / 19 SCAR 0.0
CC
1
Cov
92%
__ANON__
2.0
BEGIN
1.0
__ANON__
1.0
CRAP 1.0
↑ Summary ResultSet/CallbackInflator.pm »
1 package DBIx::Class::ResultClass::CallbackInflator;
2  
3 1 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 has 'callback' => (
6 is=>'ro',
7 1 ▶ isa=>sub { ref($_[0]) eq 'CODE' },
Subroutine __ANON__: called CC=1 SCAR=0.0
8 1 required=>1);
9  
10 has 'args' => (
11 is=>'ro',
12 1 ▶ isa=>sub { ref($_[0]) eq 'ARRAY' },
Subroutine __ANON__: called CC=1 SCAR=0.0
13 0 ▶ default=>sub { [] },
Subroutine __ANON__: not called CC=1 SCAR=6.9
14 1 required=>1);
15  
16 sub inflate_result {
17 5 ▶ my ($self, $result_source, $columndata, $prefetcheddata) = @_;
Subroutine inflate_result: called CC=1 SCAR=0.0
Pod documented
18 5 my @args = ($self->callback, $result_source, $columndata, $prefetcheddata, @{$self->args});
19 5 return $self->callback->(@args);
20 }
21  
22 1 1;
23  
24 =head1 NAME
25  
26 DBIx::Class::ResultClass::CallbackInflator - Easier way to make a quick, custom inflator
27  
28 =head1 SYNOPSIS
29  
30 use DBIx::Class::ResultClass::CallbackInflator;
31  
32 my $result_instance = DBIx::Class::ResultClass::CallbackInflator
33 ->new(callback=>$callback, args=>\@args);
34  
35 my $person_resultset = $schema
36 ->resultset('Person')
37 ->resultclass($result_instance);
38  
39 # Alternatively
40 my $person_resultset = $schema
41 ->resultset('Person')
42 ->search(+{}, +{result_class=>$result_instance});
43  
44 =head1 DESCRIPTION
45  
46 You might wish to review L<DBIx::Class::ResultSet::CallbackInflator> which is probably
47 the most easy way to actually make use of this in a resultset.
48  
49 =head1 ATTRIBUTES
50  
51 This class defines the following attributes.
52  
53 =head2 callback
54  
55 This is the callback with receives the row level data for the resultset as it gets it
56 from the database and is responsible for returning a reference to a version of that
57 data suitable for a user.
58  
59 =head2 args
60  
61 Arguments passed to the callback.
62  
63 =head1 METHODS
64  
65 This component defines the following methods.
66  
67 =head2 inflate_result
68  
69 Provides the method needed to call table data on your custom callback (with any passed
70 arguments).
71  
72 =head1 AUTHOR
73  
74 John Napiorkowski L<email:jjnapiork@cpan.org>
75  
76 With thanks to mst for the original code suggestion!
77  
78 =head1 SEE ALSO
79  
80 L<DBIx::Class>, L<DBIx::Class::ResultClass::HashRefInflator>.
81  
82 =head1 COPYRIGHT & LICENSE
83  
84 Copyright 2017, John Napiorkowski L<email:jjnapiork@cpan.org>
85  
86 This library is free software; you can redistribute it and/or modify it under
87 the same terms as Perl itself.
88  
89 =cut
↑ Summary ResultSet/CallbackInflator.pm »