LINQ/FieldSet/Selection.pm

filter: Statementstmt 97.8% 45 / 46 Branchbran 100% 4 / 4 Conditioncond 100% 6 / 6 MC/DCmcdc 100% 4 / 4 Subroutinesub 92.8% 13 / 14 Podpod 100% 3 / 3 totaltotal 97.4% 75 / 77 SCAR 17.9
CC
6
Cov
98%
__ANON__
4.0
__ANON__
2.0
target_class
2.0
CRAP 6.0
« LINQ/Util/Internal.pm ↑ Summary LINQ/Exception.pm »
1 2 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 package LINQ::FieldSet::Selection;
6  
7 2 our $AUTHORITY = 'cpan:TOBYINK';
8 2 our $VERSION = '0.002';
9  
10 2 ▶use Class::Tiny;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 2 ▶use parent qw( LINQ::FieldSet );
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 use overload (
14 'fallback' => !!1,
15 0 ▶ q[bool] => sub { !! 1 },
Subroutine __ANON__: not called CC=1 SCAR=6.9
16 2 q[""] => 'to_string',
17 q[&{}] => 'coderef',
18 2 ▶);
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 sub _known_parameter_names {
21 10 ▶ my ( $self ) = ( shift );
Subroutine _known_parameter_names: called CC=1 SCAR=0.0
22
23 return (
24 10 $self->SUPER::_known_parameter_names,
25 'as' => 1,
26 );
27 }
28  
29 sub target_class {
30 9 ▶ my ( $self ) = ( shift );
Subroutine target_class: called CC=2 SCAR=6.9
Pod documented
31 9 ▶ $self->{target_class} ||= $self->_build_target_class;
Condition100%3/3
$self->{"target_class"} ||= $self->_build_target_class
l!l&&r!l&&!r
162
MC/DC100%2/2
$self->{"target_class"} ||= $self->_build_target_class
$self->{"target_class"} $self->_build_target_class
Truth table100%3/3
A ||= B
A= $self->{"target_class"}B= $self->_build_target_class
ABresult
1X1
011
000
32 }
33  
34 sub _build_target_class {
35 6 ▶ my ( $self ) = ( shift );
Subroutine _build_target_class: called CC=1 SCAR=0.0
36 6 require Object::Adhoc;
37 6 return Object::Adhoc::make_class( [ keys %{ $self->fields_hash } ] );
38 }
39  
40 sub coderef {
41 8 ▶ my ( $self ) = ( shift );
Subroutine coderef: called CC=2 SCAR=6.9
Pod documented
42 8 ▶ $self->{coderef} ||= $self->_build_coderef;
Condition100%3/3
$self->{"coderef"} ||= $self->_build_coderef
l!l&&r!l&&!r
152
MC/DC100%2/2
$self->{"coderef"} ||= $self->_build_coderef
$self->{"coderef"} $self->_build_coderef
Truth table100%3/3
A ||= B
A= $self->{"coderef"}B= $self->_build_coderef
ABresult
1X1
011
000
43 }
44  
45 sub _build_coderef {
46 5 ▶ my ( $self ) = ( shift );
Subroutine _build_coderef: called CC=1 SCAR=0.0
47 5 my @fields = @{ $self->fields };
48 5 my $bless = $self->target_class;
49 5 my $asterisk = $self->seen_asterisk;
50 return sub {
51 6 ▶ my %output = ();
Subroutine __ANON__: called CC=4 SCAR=13.9
52 6 ▶ if ( $asterisk ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($asterisk) 1 5 6
53 1 %output = %$_;
54 }
55 6 for my $field ( @fields ) {
56 16 $output{ $field->name } = $field->getter->( $_ );
57 }
58 6 ▶ $asterisk ? Object::Adhoc::object( \%output ) : bless( \%output, $bless );
Branch: 1 branch
BranchTrueFalseTotal
$asterisk ? : 1 5 6
59 5 };
60 } #/ sub _build_coderef
61  
62 sub to_string {
63 1 ▶ my ( $self ) = ( shift );
Subroutine to_string: called CC=1 SCAR=0.0
Pod documented
64 1 sprintf 'fields(%s)', join q[, ], map $_->name, @{ $self->fields };
65 }
66  
67 2 1;
68  
69 __END__
70  
71 =pod
72  
73 =encoding utf-8
74  
75 =head1 NAME
76  
77 LINQ::FieldSet::Selection - represents an SQL-SELECT-like transformation
78  
79 =head1 DESCRIPTION
80  
81 LINQ::FieldSet::Selection is a subclass of L<LINQ::FieldSet>.
82  
83 This is used internally by LINQ and you probably don't need to know about it
84 unless you're writing very specific extensions for LINQ. The end user
85 interface is the C<fields> function in L<LINQ::Util>.
86  
87 =head1 CONSTRUCTOR
88  
89 =over
90  
91 =item C<< new( ARGSLIST ) >>
92  
93 Constructs a fieldset from a list of fields like:
94  
95 'LINQ::FieldSet::Selection'->new(
96 'field1', -param1 => 'value1', -param2,
97 'field2', -param1 => 'value2',
98 );
99  
100 Allowed parameters are:
101 C<< -as >> (followed by a value).
102  
103 =back
104  
105 =head1 METHODS
106  
107 =over
108  
109 =item C<target_class>
110  
111 The class data selected by this selection will be blessed into.
112  
113 =item C<coderef>
114  
115 Gets a coderef for this assertion; the coderef operates on C<< $_ >>.
116  
117 =item C<to_string>
118  
119 Basic string representation of the fieldset.
120  
121 =back
122  
123 =head1 OVERLOADING
124  
125 This class overloads
126 C<< "" >> to call the C<< to_string >> method and
127 C<< &{} >> to call the C<< coderef >> method.
128  
129 =head1 BUGS
130  
131 Please report any bugs to
132 L<http://rt.cpan.org/Dist/Display.html?Queue=LINQ>.
133  
134 =head1 SEE ALSO
135  
136 L<LINQ::FieldSet>, L<LINQ::Util>.
137  
138 =head1 AUTHOR
139  
140 Toby Inkster E<lt>tobyink@cpan.orgE<gt>.
141  
142 =head1 COPYRIGHT AND LICENCE
143  
144 This software is copyright (c) 2021 by Toby Inkster.
145  
146 This is free software; you can redistribute it and/or modify it under
147 the same terms as the Perl 5 programming language system itself.
148  
149 =head1 DISCLAIMER OF WARRANTIES
150  
151 THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED
152 WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
153 MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE.
« LINQ/Util/Internal.pm ↑ Summary LINQ/Exception.pm »