Transfigure/Value.pm

filter: Statementstmt 75.0% 6 / 8 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 3 / 3 Podpod n/a totaltotal 81.8% 9 / 11 CC 1 SCAR 0.9
CC
1
Cov
75%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
« Transfigure/Type/DBIx/Recursive.pm ↑ Summary
1 package Data::Transfigure::Value 1.03;
2 2 ▶use v5.26;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 # ABSTRACT: a transfigurator that filters by node value
6  
7 =encoding UTF-8
8  
9 =head1 NAME
10  
11 Data::Transfigure::Value - a transfigurator that filters by node value
12  
13 =head1 DESCRIPTION
14  
15 C<Data::Transfigure::Value> is a transfigurator that applies to one or more node
16 values. It can either match exactly if the node value and the supplied value are
17 equal, or it can match loosely if the supplied value is a compiled regular
18 expression, or a callback CODEREF.
19  
20 =cut
21  
22 0 ▶use Object::Pad;
Subroutine BEGIN: called CC=1 SCAR=2.6
23  
24 class Data::Transfigure::Value : does(Data::Transfigure::Node) {
25 use Data::Transfigure::Constants;
26  
27 =head1 FIELDS
28  
29 =head2 value (required param)
30  
31 C<value> is required and can either be a simple scalar value, or a CODE
32 reference, or a compiled regular expression.
33  
34 =cut
35  
36 field $value : param;
37  
38 ADJUST {
39 die(ref($value) . ' is not acceptable for Data::Transfigure::Value(value)')
40 if (ref($value) && ref($value) ne 'CODE' && ref($value) ne 'Regexp');
41 }
42  
43 =head1 METHODS
44  
45 =head2 applies_to( %params )
46  
47 Requires C<$params{value}> to exist
48  
49 Returns C<$MATCH_EXACT_VALUE> if neither C<$params{value}> nor C<value> are
50 defined, or if C<$params{value}> is not a reference and C<$params{value}> equals
51 C<value>.
52  
53 Returns C<$MATCH_LIKE_VALUE> if C<value> is a regular expression and it matches
54 C<$params{value}> or if C<value> is a CODE reference and returns a truth-y value
55 when given C<$params{value}>.
56  
57 Returns C<$NO_MATCH> otherwise.
58  
59 =cut
60  
61 method applies_to (%params) {
62 die('value is a required parameter for Data::Transfigure::Value->applies_to') unless (exists($params{value}));
63 my $node = $params{value};
64  
65 return $MATCH_EXACT_VALUE if (!defined($node) && !defined($value));
66 return $NO_MATCH if (!defined($node) || !defined($value));
67 return $MATCH_EXACT_VALUE if (!ref($value) && $node eq $value);
68 return $MATCH_LIKE_VALUE if (ref($value) eq 'Regexp' && $node =~ /$value/);
69 return $MATCH_LIKE_VALUE if (ref($value) eq 'CODE' && $value->($node));
70 return $NO_MATCH;
71 }
72  
73 }
74  
75 =pod
76  
77 =head1 AUTHOR
78  
79 Mark Tyrrell C<< <mark@tyrrminal.dev> >>
80  
81 =head1 LICENSE
82  
83 Copyright (c) 2024 Mark Tyrrell
84  
85 Permission is hereby granted, free of charge, to any person obtaining a copy
86 of this software and associated documentation files (the "Software"), to deal
87 in the Software without restriction, including without limitation the rights
88 to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
89 copies of the Software, and to permit persons to whom the Software is
90 furnished to do so, subject to the following conditions:
91  
92 The above copyright notice and this permission notice shall be included in all
93 copies or substantial portions of the Software.
94  
95 THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
96 IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
97 FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
98 AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
99 LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
100 OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
101 SOFTWARE.
102  
103 =cut
104  
105 1;
106  
107 __END__
« Transfigure/Type/DBIx/Recursive.pm ↑ Summary