blib/lib/CXC/Gnuplot/V0/Bound.pm

filter: Statementstmt 71.5% 63 / 88 Branchbran 12.5% 5 / 40 Conditioncond 3.7% 1 / 27 MC/DCmcdc 0.0% 0 / 14 Subroutinesub 71.4% 20 / 28 Podpod 100% 5 / 5 totaltotal 46.5% 94 / 202 CC 30 SCAR 40.4
CC
30
Cov
45%
assert_coerce
171.7
new_from_string
57.4
to_hash
20.0
CRAP 56.7
« blib/lib/CXC/Gnuplot/V0/Axis.pm ↑ Summary blib/lib/CXC/Gnuplot/V0/ColorSpec.pm »
1 package CXC::Gnuplot::V0::Bound;
2  
3 6 ▶use v5.38;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 6 ▶use experimental 'builtin';
Subroutine BEGIN: called CC=1 SCAR=0.0
5 6 ▶use Feature::Compat::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 6 our $VERSION = 'v0.29.3';
8 ## no critic(Community::MultidimensionalArrayEmulation)
9  
10 class CXC::Gnuplot::V0::Bound;
11  
12 6 ▶no namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 6 ▶use Ref::Util 'is_plain_hashref', 'is_ref';
Subroutine BEGIN: called CC=1 SCAR=0.0
15 6 ▶use List::Util 'reduce';
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 6 ▶use namespace::clean;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19 6 ▶use CXC::Gnuplot::V0::Types -lexical => qw(is_Num);
Subroutine BEGIN: called CC=1 SCAR=0.0
20 6 ▶use CXC::Gnuplot::V0::Util -lexical => 'clone_object', 'to_hash_r';
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 6 ▶use Text::Balanced;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 use overload
25 q{""} => 'to_string',
26 0 ▶ bool => sub { builtin::true },
Subroutine __ANON__: not called CC=1 SCAR=6.9
27 6 ▶ fallback => builtin::false;
Subroutine BEGIN: called CC=1 SCAR=0.0
28  
29 my sub croak {
30 0 ▶ require Carp;
Subroutine croak: not called CC=1 SCAR=6.9
31 0 goto \&Carp::croak;
32 }
33  
34 #<<< no tidy
35 6 field $lower_bound :param :reader = undef;
36 6 field $bound :param :reader = q{*};
37 6 field $upper_bound :param :reader = undef;
38 #>>>
39  
40  
41  
42  
43  
44  
45  
46  
47  
48  
49  
50  
51  
52  
53  
54  
55  
56  
57  
58 method to_hash {
59 0 ▶ to_hash_r( {
Subroutine to_hash: not called CC=4 SCAR=30.0
Pod documented
Branch: 3 branches
BranchTrueFalseTotal
defined $lower_bound ? : 0 0 0
defined $upper_bound ? : 0 0 0
defined $bound ? : 0 0 0
60 ( defined $lower_bound ? ( lower_bound => $lower_bound ) : () ),
61 ( defined $upper_bound ? ( upper_bound => $upper_bound ) : () ),
62 ( defined $bound ? ( bound => $bound ) : () ),
63 } );
64 }
65  
66  
67  
68  
69  
70 ▶method clone ( %args ) {
Subroutine clone: not called CC=1 SCAR=6.9
Pod documented
71 0 return clone_object( $self, \%args );
72 }
73  
74  
75 ▶my sub is_delimited ( $str ) {
Subroutine is_delimited: not called CC=1 SCAR=6.9
76 0 return defined( ( Text::Balanced::extract_delimited( $str ) )[0] );
77 }
78  
79 ▶my sub is_timedate( $str ) {
Subroutine is_timedate: not called CC=1 SCAR=6.9
80 0 return defined( ( Text::Balanced::extract_delimited( $str ) )[0] );
81 }
82  
83  
84  
85  
86  
87 ▶sub assert_coerce ( $class, @arg ) {
Subroutine assert_coerce: called CC=15 SCAR=51.5
Pod documented
88  
89 6 require CXC::Gnuplot::V0::Bound::Numeric;
90 6 require CXC::Gnuplot::V0::Bound::TimeDate;
91  
92 6 ▶ return $class->new_from_string( $arg[0] )
Branch: 1 branch
BranchTrueFalseTotal
if @arg == 1 and not Ref::Util::XS::is_ref($arg[0]) 6 0 6
Condition33%1/3
@arg == 1 and not Ref::Util::XS::is_ref($arg[0])
!ll&&!rl&&r
006
MC/DC0%0/2
@arg == 1 and not Ref::Util::XS::is_ref($arg[0])
@arg == 1 not Ref::Util::XS::is_ref($arg[0])
Truth table33%1/3
A and not(B)
A= @arg == 1B= not Ref::Util::XS::is_ref($arg[0])
ABresult
0X0
100
111
93 if @arg == 1 && !is_ref( $arg[0] );
94  
95 0 ▶ return $arg[0]
Branch: 1 branch
BranchTrueFalseTotal
if @arg == 1 and $arg[0] isa $class 0 0 0
Condition0%0/3
@arg == 1 and $arg[0] isa $class
!ll&&!rl&&r
000
MC/DC0%0/2
@arg == 1 and $arg[0] isa $class
@arg == 1 $arg[0] isa $class
Truth table0%0/3
A and B
A= @arg == 1B= $arg[0] isa $class
ABresult
0X0
100
111
96 if @arg == 1 && $arg[0] isa $class;
97  
98 0 ▶ my %arg
Branch: 2 branches
BranchTrueFalseTotal
@arg == 1 ? : 0 0 0
Ref::Util::XS::is_plain_hashref($arg[0]) ? : 0 0 0
99 = @arg == 1
100 ? is_plain_hashref( $arg[0] )
101 ? $arg[0]->%*
102 : croak( 'unable to coerce ' . ref $arg[0] )
103 : @arg;
104  
105 return CXC::Gnuplot::V0::Bound::Numeric->new( %arg )
106 if ( !defined $arg{min} || is_Num( $arg{min} ) )
107 0 ▶ && ( !defined $arg{max} || is_Num( $arg{max} ) );
Branch: 1 branch
BranchTrueFalseTotal
if !defined($arg{"min"}) || is_Num($arg{"min"}) and !defined($arg{"max"}) || is_Num($arg{"max"}) 0 0 0
Condition0%0/9
!defined($arg{"min"}) || is_Num($arg{"min"}) and !defined($arg{"max"}) || is_Num($arg{"max"})
!ll&&!rl&&r
000
not defined $arg{"min"} or is_Num($arg{"min"})
l!l&&r!l&&!r
000
not defined $arg{"max"} or is_Num($arg{"max"})
l!l&&r!l&&!r
000
MC/DC0%0/4
!defined($arg{"min"}) || is_Num($arg{"min"}) and !defined($arg{"max"}) || is_Num($arg{"max"})
not defined $arg{"min"} is_Num($arg{"min"}) not defined $arg{"max"} is_Num($arg{"max"})
Truth table0%0/7
not(A) or B and not(C) or D
A= not defined $arg{"min"}B= is_Num($arg{"min"})C= not defined $arg{"max"}D= is_Num($arg{"max"})
ABCDresult
00XX0
1X000
01000
1X1X1
1X011
011X1
01011
108  
109 return CXC::Gnuplot::V0::Bound::TimeDate->new( %arg )
110 if ( !defined $arg{min} || is_delimited( $arg{min} ) )
111 0 ▶ && ( !defined $arg{max} || is_delimited( $arg{max} ) );
Branch: 1 branch
BranchTrueFalseTotal
if !defined($arg{"min"}) || is_delimited($arg{"min"}) and !defined($arg{"max"}) || is_delimited($arg{"max"}) 0 0 0
Condition0%0/9
!defined($arg{"min"}) || is_delimited($arg{"min"}) and !defined($arg{"max"}) || is_delimited($arg{"max"})
!ll&&!rl&&r
000
not defined $arg{"min"} or is_delimited $arg{"min"}
l!l&&r!l&&!r
000
not defined $arg{"max"} or is_delimited $arg{"max"}
l!l&&r!l&&!r
000
MC/DC0%0/4
!defined($arg{"min"}) || is_delimited($arg{"min"}) and !defined($arg{"max"}) || is_delimited($arg{"max"})
not defined $arg{"min"} is_delimited $arg{"min"} not defined $arg{"max"} is_delimited $arg{"max"}
Truth table0%0/7
not(A) or B and not(C) or D
A= not defined $arg{"min"}B= is_delimited $arg{"min"}C= not defined $arg{"max"}D= is_delimited $arg{"max"}
ABCDresult
00XX0
1X000
01000
1X1X1
1X011
011X1
01011
112  
113 0 croak( 'unable to coerce' );
114  
115 # what about geographic??
116  
117 }
118  
119  
120  
121  
122  
123 6 ▶use Regexp::Common 'number', 'delimited';
Subroutine BEGIN: called CC=1 SCAR=0.0
124  
125 6 my $RE_quoted;
126 my $RE_real;
127 BEGIN {
128 6 ▶ $RE_real = ${RE}{num}{real};
Subroutine BEGIN: called CC=1 SCAR=0.0
129 6 ▶ use feature 'multidimensional';
Subroutine BEGIN: called CC=1 SCAR=0.0
130 6 $RE_quoted = ${RE}{quoted}{ -delim => q{'"} }{-esc};
131 }
132  
133 ## no critic(RegularExpressions::ProhibitComplexRegexes)
134 6 ▶use constant RE_BOUND_REAL => qr/^$RE_real$/;
Subroutine BEGIN: called CC=1 SCAR=0.0
135 6 ▶use constant RE_BOUND_QUOTED => qr/^$RE_quoted$/;
Subroutine BEGIN: called CC=1 SCAR=0.0
136  
137 6 use constant RE_BOUND => qr{
138 ^
139 (?:
140 (?<lower_bound> (?<lb_real>$RE_real) | (?<lb_q>$RE_quoted))
141 \s* <
142 )?
143 \s* (?<bound>[*]) \s*
144 (?: <
145 \s*
146 (?<upper_bound> (?<ub_real>$RE_real) | (?<ub_q>$RE_quoted))
147 )?
148 6 ▶ $ }x;
Subroutine BEGIN: called CC=1 SCAR=0.0
149  
150  
151 ▶sub new_from_string( $class, $str ) {
Subroutine new_from_string: called CC=9 SCAR=40.5
Pod documented
152  
153 6 require CXC::Gnuplot::V0::Bound::Numeric;
154 6 require CXC::Gnuplot::V0::Bound::TimeDate;
155  
156  
157 6 ▶ croak( '"str" argument is not a scalar' )
Branch: 1 branch
BranchTrueFalseTotal
if Ref::Util::XS::is_ref($str) 0 6 6
158 if is_ref( $str );
159  
160 6 ▶ return CXC::Gnuplot::V0::Bound::Numeric->new( bound => $str )
Branch: 1 branch
BranchTrueFalseTotal
if $str =~ /^(?:(?i)(?:[-+]?)(?:(?=[.]?[0123456789])(?:[0123456789]*)(?:(?:[.])(?:[0123456789]{0,}))?)(?:(?:[E])(?:(?:[-+]?)(?:[0123456789]+))|))$/u 6 0 6
161 if $str =~ RE_BOUND_REAL;
162  
163 0 ▶ return CXC::Gnuplot::V0::Bound::TimeDate->new( bound => $str )
Branch: 1 branch
BranchTrueFalseTotal
if $str =~ /^(?:(?|(?:\")(?:[^\"]*)(?:\")|(?:\')(?:[^\']*)(?:\')|(?:\`)(?:[^\`]*)(?:\`)))$/u 0 0 0
164 if $str =~ RE_BOUND_QUOTED;
165  
166 0 ▶ croak "illegal bounds specification: $str"
Branch: 1 branch
BranchTrueFalseTotal
unless $str =~ / ^ (?: (?<lower_bound> (?<lb_real>(?:(?i)(?:[-+]?)(?:(?=[.]?[0123456789])(?:[0123456789]*)(?:(?:[.])(?:[0123456789]{0,}))?)(?:(?:[E])(?:(?:[-+]?)(?:[0123456789]+))|))) | (?<lb_q>(?:(?|(?:\")(?:[^\"]*)(?:\")|(?:\')(?:[^\']*)(?:\')|(?:\`)(?:[^\`]*)(?:\`))))) \s* < )? \s* (?<bound>[*]) \s* (?: < \s* (?<upper_bound> (?<ub_real>(?:(?i)(?:[-+]?)(?:(?=[.]?[0123456789])(?:[0123456789]*)(?:(?:[.])(?:[0123456789]{0,}))?)(?:(?:[E])(?:(?:[-+]?)(?:[0123456789]+))|))) | (?<ub_q>(?:(?|(?:\")(?:[^\"]*)(?:\")|(?:\')(?:[^\']*)(?:\')|(?:\`)(?:[^\`]*)(?:\`))))) )? $ /u 0 0 0
167 unless $str =~ RE_BOUND;
168  
169 0 my %args = %+;
170  
171 # need to delete these from %args, so can't use short-circuit boolean
172 0 ▶ my $is_number = reduce { $a || $b } map { defined delete( $args{$_} ) } 'lb_real', 'ub_real';
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$a or $b 0 0 0
173 0 ▶ my $is_quoted = reduce { $a || $b } map { defined delete( $args{$_} ) } 'lb_q', 'ub_q';
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$a or $b 0 0 0
174  
175 0 ▶ croak q{illegal bounds specification: can't mix numeric and timedate}
Branch: 1 branch
BranchTrueFalseTotal
if $is_number and $is_quoted 0 0 0
Condition0%0/3
$is_number and $is_quoted
!ll&&!rl&&r
000
MC/DC0%0/2
$is_number and $is_quoted
$is_number $is_quoted
Truth table0%0/3
A and B
A= $is_numberB= $is_quoted
ABresult
0X0
100
111
176 if $is_number && $is_quoted;
177  
178 0 ▶ return CXC::Gnuplot::V0::Bound::Numeric->new( %args )
Branch: 1 branch
BranchTrueFalseTotal
if $is_number 0 0 0
179 if $is_number;
180  
181 0 ▶ return CXC::Gnuplot::V0::Bound::TimeDate->new( %args )
Branch: 1 branch
BranchTrueFalseTotal
if $is_quoted 0 0 0
182 if $is_quoted;
183  
184 0 return CXC::Gnuplot::V0::Bound::Numeric->new( %+ );
185 }
186  
187  
188  
189  
190  
191  
192 method to_string {
193  
194 2 ▶ return join(
Subroutine to_string: called CC=3 SCAR=12.7
Pod documented
Branch: 2 branches
BranchTrueFalseTotal
defined $lower_bound ? : 0 2 2
defined $upper_bound ? : 0 2 2
195 q{ < }, #
196 ( defined $lower_bound ? $lower_bound : () ),
197 $bound,
198 ( defined $upper_bound ? $upper_bound : () ),
199 );
200 }
201  
202 6 1;
203  
204 #
205 # This file is part of CXC-Gnuplot
206 #
207 # This software is Copyright (c) 2024 by Smithsonian Astrophysical Observatory.
208 #
209 # This is free software, licensed under:
210 #
211 # The GNU General Public License, Version 3, June 2007
212 #
213  
214 __END__
« blib/lib/CXC/Gnuplot/V0/Axis.pm ↑ Summary blib/lib/CXC/Gnuplot/V0/ColorSpec.pm »