| 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::Field; | ||||||||||||||||||||
| 6 | |||||||||||||||||||||
| 7 | 4 | our $AUTHORITY = 'cpan:TOBYINK'; | |||||||||||||||||||
| 8 | 4 | our $VERSION = '0.002'; | |||||||||||||||||||
| 9 | |||||||||||||||||||||
| 10 | 4 | ▶ | use Class::Tiny qw( index name value params ); | ||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||
| 11 | |||||||||||||||||||||
| 12 | sub BUILD { | ||||||||||||||||||||
| 13 | 78 | ▶ | my ( $self ) = ( shift ); | ||||||||||||||||||
|
Subroutine
BUILD: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||
| 14 | |||||||||||||||||||||
| 15 | 78 | ▶ | if ( not $self->{params} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 16 | 7 | $self->{params} = {}; | |||||||||||||||||||
| 17 | } | ||||||||||||||||||||
| 18 | |||||||||||||||||||||
| 19 | 78 | ▶ | if ( not defined $self->{name} ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 20 | 74 | ▶ | if ( defined $self->{params}{as} ) { | ||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||
| 21 | 11 | $self->{name} = $self->{params}{as}; | |||||||||||||||||||
| 22 | } | ||||||||||||||||||||
| 23 | ▶ | elsif ( !ref $self->{value} and $self->{value} =~ /\A[^\W0-9]\w*\z/ ) { | |||||||||||||||||||
|
Condition100%3/3
not ref $self->{"value"} and $self->{"value"} =~ /\A[^\W0-9]\w*\z/
MC/DC100%2/2
not ref $self->{"value"} and $self->{"value"} =~ /\A[^\W0-9]\w*\z/
not ref $self->{"value"}
$self->{"value"} =~ /\A[^\W0-9]\w*\z/
Truth table100%3/3
not(A) and B
A= not ref $self->{"value"}B= $self->{"value"} =~ /\A[^\W0-9]\w*\z/
| |||||||||||||||||||||
| 24 | 61 | $self->{name} = $self->{value}; | |||||||||||||||||||
| 25 | } | ||||||||||||||||||||
| 26 | else { | ||||||||||||||||||||
| 27 | 2 | $self->{name} = sprintf( '_%d', $self->{index} ); | |||||||||||||||||||
| 28 | } | ||||||||||||||||||||
| 29 | } #/ if ( not defined $self...) | ||||||||||||||||||||
| 30 | |||||||||||||||||||||
| 31 | } #/ sub BUILD | ||||||||||||||||||||
| 32 | |||||||||||||||||||||
| 33 | sub getter { | ||||||||||||||||||||
| 34 | 68 | ▶ | my ( $self ) = @_; | ||||||||||||||||||
|
Subroutine
getter: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||
| 35 | 68 | ▶ | $self->{getter} ||= $self->_build_getter; | ||||||||||||||||||
|
Condition100%3/3
$self->{"getter"} ||= $self->_build_getter
MC/DC100%2/2
$self->{"getter"} ||= $self->_build_getter
$self->{"getter"}
$self->_build_getter
Truth table100%3/3
A ||= B
A= $self->{"getter"}B= $self->_build_getter
| |||||||||||||||||||||
| 36 | } | ||||||||||||||||||||
| 37 | |||||||||||||||||||||
| 38 | sub _build_getter { | ||||||||||||||||||||
| 39 | 63 | ▶ | my ( $self ) = @_; | ||||||||||||||||||
|
Subroutine
_build_getter: called CC=2 SCAR=6.9
| |||||||||||||||||||||
| 40 | |||||||||||||||||||||
| 41 | 63 | my $attr = $self->value; | |||||||||||||||||||
| 42 | |||||||||||||||||||||
| 43 | 63 | ▶ | if ( ref( $attr ) eq 'CODE' ) { | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 44 | 4 | return $attr; | |||||||||||||||||||
| 45 | } | ||||||||||||||||||||
| 46 | |||||||||||||||||||||
| 47 | 59 | require Scalar::Util; | |||||||||||||||||||
| 48 | |||||||||||||||||||||
| 49 | return sub { | ||||||||||||||||||||
| 50 | 130 | ▶ | my $blessed = Scalar::Util::blessed( $_ ); | ||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||
| 51 | 130 | ▶ | if ( ( $blessed || '' ) =~ /\AObject::Adhoc::__ANON__::/ ) { | ||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
$blessed || ''
MC/DC100%1/1
$blessed || ''
$blessed
Truth table100%2/2
A
A= $blessed
| |||||||||||||||||||||
| 52 | 86 | $blessed = undef; | |||||||||||||||||||
| 53 | } | ||||||||||||||||||||
| 54 | 130 | ▶ | scalar( $blessed ? $_->$attr : $_->{$attr} ); | ||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||
| 55 | 59 | }; | |||||||||||||||||||
| 56 | } #/ sub _build_getter | ||||||||||||||||||||
| 57 | |||||||||||||||||||||
| 58 | 4 | 1; | |||||||||||||||||||
| 59 | |||||||||||||||||||||
| 60 | __END__ | ||||||||||||||||||||
| 61 | |||||||||||||||||||||
| 62 | =pod | ||||||||||||||||||||
| 63 | |||||||||||||||||||||
| 64 | =encoding utf-8 | ||||||||||||||||||||
| 65 | |||||||||||||||||||||
| 66 | =head1 NAME | ||||||||||||||||||||
| 67 | |||||||||||||||||||||
| 68 | LINQ::Field - represents a single field in a LINQ::FieldSet | ||||||||||||||||||||
| 69 | |||||||||||||||||||||
| 70 | =head1 DESCRIPTION | ||||||||||||||||||||
| 71 | |||||||||||||||||||||
| 72 | See L<LINQ::FieldSet> for details. | ||||||||||||||||||||
| 73 | |||||||||||||||||||||
| 74 | This is used internally by LINQ and you probably don't need to know about it | ||||||||||||||||||||
| 75 | unless you're writing very specific extensions for LINQ. | ||||||||||||||||||||
| 76 | |||||||||||||||||||||
| 77 | =head1 CONSTRUCTOR | ||||||||||||||||||||
| 78 | |||||||||||||||||||||
| 79 | =over | ||||||||||||||||||||
| 80 | |||||||||||||||||||||
| 81 | =item C<< new( ARGSHASH ) >> | ||||||||||||||||||||
| 82 | |||||||||||||||||||||
| 83 | =back | ||||||||||||||||||||
| 84 | |||||||||||||||||||||
| 85 | =begin trustme | ||||||||||||||||||||
| 86 | |||||||||||||||||||||
| 87 | =item BUILD | ||||||||||||||||||||
| 88 | |||||||||||||||||||||
| 89 | =end trustme | ||||||||||||||||||||
| 90 | |||||||||||||||||||||
| 91 | =head1 METHODS | ||||||||||||||||||||
| 92 | |||||||||||||||||||||
| 93 | =over | ||||||||||||||||||||
| 94 | |||||||||||||||||||||
| 95 | =item C<index> | ||||||||||||||||||||
| 96 | |||||||||||||||||||||
| 97 | The order of a field within a fieldset. Starts at zero. | ||||||||||||||||||||
| 98 | |||||||||||||||||||||
| 99 | =item C<name> | ||||||||||||||||||||
| 100 | |||||||||||||||||||||
| 101 | The name of a field. | ||||||||||||||||||||
| 102 | |||||||||||||||||||||
| 103 | =item C<value> | ||||||||||||||||||||
| 104 | |||||||||||||||||||||
| 105 | The hashref key or method name used to find the value for the field from | ||||||||||||||||||||
| 106 | a hashref or object; or a coderef which will get the value from C<< $_ >>. | ||||||||||||||||||||
| 107 | |||||||||||||||||||||
| 108 | =item C<params> | ||||||||||||||||||||
| 109 | |||||||||||||||||||||
| 110 | Additional metadata for the field. | ||||||||||||||||||||
| 111 | |||||||||||||||||||||
| 112 | =item C<getter> | ||||||||||||||||||||
| 113 | |||||||||||||||||||||
| 114 | A coderef which will get the value of a field from C<< $_ >>. | ||||||||||||||||||||
| 115 | |||||||||||||||||||||
| 116 | =back | ||||||||||||||||||||
| 117 | |||||||||||||||||||||
| 118 | =head1 BUGS | ||||||||||||||||||||
| 119 | |||||||||||||||||||||
| 120 | Please report any bugs to | ||||||||||||||||||||
| 121 | L<http://rt.cpan.org/Dist/Display.html?Queue=LINQ>. | ||||||||||||||||||||
| 122 | |||||||||||||||||||||
| 123 | =head1 SEE ALSO | ||||||||||||||||||||
| 124 | |||||||||||||||||||||
| 125 | L<LINQ::FieldSet>. | ||||||||||||||||||||
| 126 | |||||||||||||||||||||
| 127 | =head1 AUTHOR | ||||||||||||||||||||
| 128 | |||||||||||||||||||||
| 129 | Toby Inkster E<lt>tobyink@cpan.orgE<gt>. | ||||||||||||||||||||
| 130 | |||||||||||||||||||||
| 131 | =head1 COPYRIGHT AND LICENCE | ||||||||||||||||||||
| 132 | |||||||||||||||||||||
| 133 | This software is copyright (c) 2021 by Toby Inkster. | ||||||||||||||||||||
| 134 | |||||||||||||||||||||
| 135 | This is free software; you can redistribute it and/or modify it under | ||||||||||||||||||||
| 136 | the same terms as the Perl 5 programming language system itself. | ||||||||||||||||||||
| 137 | |||||||||||||||||||||
| 138 | =head1 DISCLAIMER OF WARRANTIES | ||||||||||||||||||||
| 139 | |||||||||||||||||||||
| 140 | THIS PACKAGE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED | ||||||||||||||||||||
| 141 | WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF | ||||||||||||||||||||
| 142 | MERCHANTIBILITY AND FITNESS FOR A PARTICULAR PURPOSE. | ||||||||||||||||||||