ResultClass/CallbackInflator.pm

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