| 1 | 4 | ▶ | use 5.006; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 2 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | package LINQ::FieldSet; | ||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | 4 | our $AUTHORITY = 'cpan:TOBYINK'; | |||||||||||||||||||||||||||||||||||||||||
| 8 | 4 | our $VERSION = '0.002'; | |||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 4 | ▶ | use Class::Tiny qw( fields seen_asterisk ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 4 | ▶ | use LINQ::Util::Internal (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | sub _known_parameter_names { | ||||||||||||||||||||||||||||||||||||||||||
| 14 | 55 | ▶ | my ( $self ) = ( shift ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_known_parameter_names: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | 55 | return (); | |||||||||||||||||||||||||||||||||||||||||
| 16 | } | ||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | sub BUILDARGS { | ||||||||||||||||||||||||||||||||||||||||||
| 19 | 56 | ▶ | my ( $class, @args ) = ( shift, @_ ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BUILDARGS: called CC=10 SCAR=23.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 56 | ▶ | if ( @args == 1 and ref( $args[0] ) eq 'HASH' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@args == 1 and ref $args[0] eq "HASH"
MC/DC100%2/2
@args == 1 and ref $args[0] eq "HASH"
@args == 1
ref $args[0] eq "HASH"
Truth table100%3/3
A and B
A= @args == 1B= ref $args[0] eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 1 | return $args[0]; | |||||||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||||||||||
| 25 | 55 | require LINQ::Field; | |||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 55 | my %known = $class->_known_parameter_names; | |||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | 55 | my @fields; | |||||||||||||||||||||||||||||||||||||||||
| 30 | 55 | my $idx = 0; | |||||||||||||||||||||||||||||||||||||||||
| 31 | 55 | my $seen_asterisk; | |||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 55 | ▶ | ARG: while ( @args ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 34 | 73 | my $value = shift @args; | |||||||||||||||||||||||||||||||||||||||||
| 35 | 73 | ▶ | if ( $value eq '*' ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 5 | $seen_asterisk = 1; | |||||||||||||||||||||||||||||||||||||||||
| 37 | 5 | next ARG; | |||||||||||||||||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||||||||||||||||
| 39 | 68 | my %params = (); | |||||||||||||||||||||||||||||||||||||||||
| 40 | 68 | ▶ | while ( @args and !ref $args[0] and $args[0] =~ /\A-/ ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
@args and not ref $args[0] and $args[0] =~ /\A-/
@args and not ref $args[0]
MC/DC100%3/3
@args and not ref $args[0] and $args[0] =~ /\A-/
@args
not ref $args[0]
$args[0] =~ /\A-/
Truth table100%4/4
A and not(B) and C
A= @argsB= not ref $args[0]C= $args[0] =~ /\A-/
| |||||||||||||||||||||||||||||||||||||||||||
| 41 | 77 | my $p_name = substr( shift( @args ), 1 ); | |||||||||||||||||||||||||||||||||||||||||
| 42 | 77 | ▶ | if ( $known{$p_name} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 60 | $params{$p_name} = shift( @args ); | |||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||
| 45 | elsif ( exists $known{$p_name} ) { | ||||||||||||||||||||||||||||||||||||||||||
| 46 | 16 | $params{$p_name} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||
| 48 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 1 | LINQ::Util::Internal::throw( | |||||||||||||||||||||||||||||||||||||||||
| 50 | 'CallerError', | ||||||||||||||||||||||||||||||||||||||||||
| 51 | message => "Unknown field parameter '$p_name'", | ||||||||||||||||||||||||||||||||||||||||||
| 52 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | } #/ while ( @args and !ref $args...) | ||||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 67 | my $field = 'LINQ::Field'->new( | |||||||||||||||||||||||||||||||||||||||||
| 57 | value => $value, | ||||||||||||||||||||||||||||||||||||||||||
| 58 | index => ++$idx, | ||||||||||||||||||||||||||||||||||||||||||
| 59 | params => \%params, | ||||||||||||||||||||||||||||||||||||||||||
| 60 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 61 | 67 | push @fields, $field; | |||||||||||||||||||||||||||||||||||||||||
| 62 | } #/ ARG: while ( @args ) | ||||||||||||||||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||||||||||||||||
| 64 | return { | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 54 | fields => \@fields, | |||||||||||||||||||||||||||||||||||||||||
| 66 | seen_asterisk => $seen_asterisk, | ||||||||||||||||||||||||||||||||||||||||||
| 67 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 68 | } #/ sub BUILDARGS | ||||||||||||||||||||||||||||||||||||||||||
| 69 | |||||||||||||||||||||||||||||||||||||||||||
| 70 | sub fields_hash { | ||||||||||||||||||||||||||||||||||||||||||
| 71 | 10 | ▶ | my ( $self ) = ( shift ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fields_hash: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 72 | 10 | ▶ | $self->{fields_hash} ||= $self->_build_fields_hash; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$self->{"fields_hash"} ||= $self->_build_fields_hash
MC/DC100%2/2
$self->{"fields_hash"} ||= $self->_build_fields_hash
$self->{"fields_hash"}
$self->_build_fields_hash
Truth table100%3/3
A ||= B
A= $self->{"fields_hash"}B= $self->_build_fields_hash
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | sub _build_fields_hash { | ||||||||||||||||||||||||||||||||||||||||||
| 76 | 6 | ▶ | my ( $self ) = ( shift ); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_build_fields_hash: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 6 | my %fields; | |||||||||||||||||||||||||||||||||||||||||
| 78 | 6 | foreach my $field ( @{ $self->fields } ) { | |||||||||||||||||||||||||||||||||||||||||
| 79 | 15 | $fields{ $field->name } = $field; | |||||||||||||||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||||||||||||||||
| 81 | 6 | return \%fields; | |||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | __END__ | ||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||
| 89 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | =encoding utf-8 | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | LINQ::FieldSet - base class for LINQ::FieldSet::{Selection,Assertion} | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | This is used internally by LINQ and you probably don't need to know about it | ||||||||||||||||||||||||||||||||||||||||||
| 100 | unless you're writing very specific extensions for LINQ. | ||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | =head1 CONSTRUCTOR | ||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||
| 104 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | =item C<< new( ARGSLIST ) >> | ||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | Constructs a fieldset from a list of fields like: | ||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 'LINQ::FieldSet'->new( | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 'field1', -param1 => 'value1', -param2, | ||||||||||||||||||||||||||||||||||||||||||
| 112 | 'field2', -param1 => 'value2', | ||||||||||||||||||||||||||||||||||||||||||
| 113 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||||||||||||||
| 115 | The list of allowed parameters and whether each one takes a value is returned | ||||||||||||||||||||||||||||||||||||||||||
| 116 | by the C<_known_parameter_names> method. This is empty in LINQ::FieldSet itself | ||||||||||||||||||||||||||||||||||||||||||
| 117 | so doing anything interesting with this class probably requires subclassing. | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||||||||||||||
| 121 | =begin trustme | ||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||
| 123 | =item BUILDARGS | ||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | =end trustme | ||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||||||||||||||||
| 129 | =over | ||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | =item C<fields> | ||||||||||||||||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||||||||||||||||
| 133 | An arrayref of fields in this fieldset. | ||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||
| 135 | =item C<fields_hash> | ||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||
| 137 | The same, but as a hashref keyed on field name. | ||||||||||||||||||||||||||||||||||||||||||
| 138 | |||||||||||||||||||||||||||||||||||||||||||
| 139 | =item C<seen_asterisk> | ||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | Whether "*" was seen by the constructor. | ||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||||||||||||||||
| 145 | =head1 BUGS | ||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | Please report any bugs to | ||||||||||||||||||||||||||||||||||||||||||
| 148 | L<http://rt.cpan.org/Dist/Display.html?Queue=LINQ>. | ||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | L<LINQ::FieldSet>. | ||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | Toby Inkster E<lt>tobyink@cpan.orgE<gt>. | ||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||
| 158 | =head1 COPYRIGHT AND LICENCE | ||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | This software is copyright (c) 2021 by Toby Inkster. | ||||||||||||||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||||||||||||||
| 162 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||||||||||||||||||||||||
| 163 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | =head1 DISCLAIMER OF WARRANTIES | ||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||
| 167 | THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED | ||||||||||||||||||||||||||||||||||||||||||
| 168 | WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF | ||||||||||||||||||||||||||||||||||||||||||
| 169 | MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||||||||||||||||||||||||||||||||||||||||||