| 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::Single; | ||||||||||||||||||||
| 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 new { | ||||||||||||||||||||
| 21 | 4 | ▶ | my $class = shift; | ||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=14.2
Pod
documented
| |||||||||||||||||||||
| 22 | 4 | my $field = shift; | |||||||||||||||||||
| 23 | 4 | my $self = $class->SUPER::new( $field ); | |||||||||||||||||||
| 24 | |||||||||||||||||||||
| 25 | 4 | ▶ | if ( wantarray ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 26 | 4 | return ( $self, @_ ); | |||||||||||||||||||
| 27 | } | ||||||||||||||||||||
| 28 | |||||||||||||||||||||
| 29 | 0 | ▶ | if ( @_ ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 30 | 0 | LINQ::Util::Internal::throw( | |||||||||||||||||||
| 31 | 'CallerError', | ||||||||||||||||||||
| 32 | 'message' => 'Unexpected extra parameters; single field name expected', | ||||||||||||||||||||
| 33 | ); | ||||||||||||||||||||
| 34 | } | ||||||||||||||||||||
| 35 | |||||||||||||||||||||
| 36 | 0 | return $self; | |||||||||||||||||||
| 37 | } | ||||||||||||||||||||
| 38 | |||||||||||||||||||||
| 39 | sub coderef { | ||||||||||||||||||||
| 40 | 24 | ▶ | my ( $self ) = ( shift ); | ||||||||||||||||||
|
Subroutine
coderef: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||
| 41 | 24 | ▶ | $self->{coderef} ||= $self->_build_coderef; | ||||||||||||||||||
|
Condition66%2/3
$self->{"coderef"} ||= $self->_build_coderef
MC/DC0%0/2
$self->{"coderef"} ||= $self->_build_coderef
$self->{"coderef"}
$self->_build_coderef
Truth table66%2/3
A ||= B
A= $self->{"coderef"}B= $self->_build_coderef
| |||||||||||||||||||||
| 42 | } | ||||||||||||||||||||
| 43 | |||||||||||||||||||||
| 44 | sub _build_coderef { | ||||||||||||||||||||
| 45 | 4 | ▶ | my ( $self ) = ( shift ); | ||||||||||||||||||
|
Subroutine
_build_coderef: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 46 | 4 | my ( $field ) = @{ $self->fields }; | |||||||||||||||||||
| 47 | 4 | return $field->getter; | |||||||||||||||||||
| 48 | } | ||||||||||||||||||||
| 49 | |||||||||||||||||||||
| 50 | sub to_string { | ||||||||||||||||||||
| 51 | 0 | ▶ | my ( $self ) = ( shift ); | ||||||||||||||||||
|
Subroutine
to_string: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 52 | 0 | sprintf 'field(%s)', join q[, ], map $_->name, @{ $self->fields }; | |||||||||||||||||||
| 53 | } | ||||||||||||||||||||
| 54 | |||||||||||||||||||||
| 55 | 2 | 1; | |||||||||||||||||||
| 56 | |||||||||||||||||||||
| 57 | __END__ | ||||||||||||||||||||
| 58 | |||||||||||||||||||||
| 59 | =pod | ||||||||||||||||||||
| 60 | |||||||||||||||||||||
| 61 | =encoding utf-8 | ||||||||||||||||||||
| 62 | |||||||||||||||||||||
| 63 | =head1 NAME | ||||||||||||||||||||
| 64 | |||||||||||||||||||||
| 65 | LINQ::FieldSet::Single - similar to LINQ::FieldSet::Selection, but only selects one field | ||||||||||||||||||||
| 66 | |||||||||||||||||||||
| 67 | =head1 DESCRIPTION | ||||||||||||||||||||
| 68 | |||||||||||||||||||||
| 69 | LINQ::FieldSet::Single is a subclass of L<LINQ::FieldSet>. | ||||||||||||||||||||
| 70 | |||||||||||||||||||||
| 71 | This is used internally by LINQ and you probably don't need to know about it | ||||||||||||||||||||
| 72 | unless you're writing very specific extensions for LINQ. The end user | ||||||||||||||||||||
| 73 | interface is the C<field> function in L<LINQ::Util>. | ||||||||||||||||||||
| 74 | |||||||||||||||||||||
| 75 | =head1 CONSTRUCTOR | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | =over | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | =item C<< new( NAME, EXTRAARGS ) >> | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | Constructs a fieldset like: | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | 'LINQ::FieldSet::Single'->new( 'name', @stuff ); | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | If called in scalar context, and C<< @stuff >> isn't the empty list, then | ||||||||||||||||||||
| 86 | will throw an exception. | ||||||||||||||||||||
| 87 | |||||||||||||||||||||
| 88 | If called in list context, will return the newly constructed object followed | ||||||||||||||||||||
| 89 | by unadulterated C<< @stuff >>. | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | =back | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | =head1 METHODS | ||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | =over | ||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | =item C<coderef> | ||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | Gets a coderef for this assertion; the coderef operates on C<< $_ >>. | ||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | =item C<to_string> | ||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | Basic string representation of the fieldset. | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | =back | ||||||||||||||||||||
| 106 | |||||||||||||||||||||
| 107 | =head1 OVERLOADING | ||||||||||||||||||||
| 108 | |||||||||||||||||||||
| 109 | This class overloads | ||||||||||||||||||||
| 110 | C<< "" >> to call the C<< to_string >> method and | ||||||||||||||||||||
| 111 | C<< &{} >> to call the C<< coderef >> method. | ||||||||||||||||||||
| 112 | |||||||||||||||||||||
| 113 | =head1 BUGS | ||||||||||||||||||||
| 114 | |||||||||||||||||||||
| 115 | Please report any bugs to | ||||||||||||||||||||
| 116 | L<http://rt.cpan.org/Dist/Display.html?Queue=LINQ>. | ||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | =head1 SEE ALSO | ||||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | L<LINQ::FieldSet>, L<LINQ::Util>. | ||||||||||||||||||||
| 121 | |||||||||||||||||||||
| 122 | =head1 AUTHOR | ||||||||||||||||||||
| 123 | |||||||||||||||||||||
| 124 | Toby Inkster E<lt>tobyink@cpan.orgE<gt>. | ||||||||||||||||||||
| 125 | |||||||||||||||||||||
| 126 | =head1 COPYRIGHT AND LICENCE | ||||||||||||||||||||
| 127 | |||||||||||||||||||||
| 128 | This software is copyright (c) 2021 by Toby Inkster. | ||||||||||||||||||||
| 129 | |||||||||||||||||||||
| 130 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||
| 131 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||
| 132 | |||||||||||||||||||||
| 133 | =head1 DISCLAIMER OF WARRANTIES | ||||||||||||||||||||
| 134 | |||||||||||||||||||||
| 135 | THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED | ||||||||||||||||||||
| 136 | WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF | ||||||||||||||||||||
| 137 | MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||||||||||||||||||||