blib/lib/Types/TypeTiny.pm

filter: Statementstmt 63.2% 323 / 482 (22 uncoverable) Branchbran 54.8% 125 / 228 Conditioncond 70.0% 91 / 130 MC/DCmcdc 52.9% 36 / 68 Subroutinesub 70.5% 84 / 119 Podpod 28.5% 8 / 28 totaltotal 61.5% 667 / 1055 (22 uncoverable) CC 163 SCAR 26.7
CC
163
Cov
62%
_TypeTinyFromMoose
156.0
_TypeTinyFromMoose_baseclass
56.0
_TypeTinyFromMouse
42.0
CRAP 14.4
« blib/lib/Eval/TypeTiny.pm ↑ Summary lib/Types/Standard/Tuple.pm »
1 package Types::TypeTiny;
2  
3 304 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 304 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 304 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 304 our $AUTHORITY = 'cpan:TOBYINK';
8 304 our $VERSION = '2.010001';
9  
10 304 $VERSION =~ tr/_//d;
11  
12 304 ▶use Scalar::Util qw< blessed refaddr weaken >;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 304 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=7.0
15 *__XS = eval {
16 304 require Type::Tiny::XS;
17 304 'Type::Tiny::XS'->VERSION( '0.022' );
18 304 1;
19 }
20 ? eval "sub () { '$Type::Tiny::XS::VERSION' }"
21 304 ▶ : sub () { !!0 };
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Type::Tiny::XS; 'Type::Tiny::XS'->VERSION('0.022'); 1 } } ? : 304 0 304
22 }
23  
24 our @EXPORT_OK = (
25 304 map( @{ [ $_, "is_$_", "assert_$_" ] }, __PACKAGE__->type_names ),
26 qw/to_TypeTiny/
27 );
28 304 our %EXPORT_TAGS = (
29 types => [ __PACKAGE__->type_names ],
30 is => [ map "is_$_", __PACKAGE__->type_names ],
31 assert => [ map "assert_$_", __PACKAGE__->type_names ],
32 );
33  
34 304 my %cache;
35  
36 # This `import` method is designed to avoid loading Exporter::Tiny.
37 # This is so that if you stick to only using the purely OO parts of
38 # Type::Tiny, you can skip loading the exporter.
39 #
40 158 ▶sub import {
Subroutine import: called CC=4 SCAR=19.0
41  
42 # If this sub succeeds, it will replace itself.
43 # uncoverable subroutine
44 158 ▶ return unless @_ > 1; # uncoverable statement
Branch: 1 branch
BranchTrueFalseTotal
unless @_ > 1 3 155 158
45 304 ▶ no warnings "redefine"; # uncoverable statement
Subroutine BEGIN: called CC=1 SCAR=0.4
46 155 our @ISA = qw( Exporter::Tiny ); # uncoverable statement
47 155 require Exporter::Tiny; # uncoverable statement
48 155 my $next = \&Exporter::Tiny::import; # uncoverable statement
49 155 *import = $next; # uncoverable statement
50 155 my $class = shift; # uncoverable statement
51 155 ▶ my $opts = { ref( $_[0] ) ? %{ +shift } : () }; # uncoverable statement
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 1 154 155
52 155 ▶ $opts->{into} ||= scalar( caller ); # uncoverable statement
Condition100%2/2
$opts->{"into"} ||= scalar caller
l!l
1154
MC/DC100%1/1
$opts->{"into"} ||= scalar caller
$opts->{"into"}
Truth table100%2/2
A
A= $opts->{"into"}
Aresult
11
00
53 155 _mkall(); # uncoverable statement
54 155 return $class->$next( $opts, @_ ); # uncoverable statement
55 } #/ sub import
56  
57 304 for ( __PACKAGE__->type_names ) { # uncoverable statement
58 0 ▶ eval qq{ # uncoverable statement
Subroutine assert_ArrayLike: not called CC=1 SCAR=1.0
Subroutine assert_BoolLike: not called CC=1 SCAR=1.0
Subroutine assert_CodeLike: not called CC=1 SCAR=1.0
Subroutine assert_HashLike: not called CC=1 SCAR=1.0
Subroutine assert_TypeTiny: called CC=1 SCAR=1.0
Subroutine assert__ForeignTypeConstraint: not called CC=1 SCAR=1.0
Subroutine is_ArrayLike: called CC=1 SCAR=1.0
Subroutine is_BoolLike: called CC=1 SCAR=1.0
Subroutine is_CodeLike: called CC=1 SCAR=1.0
Subroutine is_HashLike: not called CC=1 SCAR=1.0
Subroutine is_StringLike: called CC=1 SCAR=1.0
Subroutine is_TypeTiny: called CC=1 SCAR=1.0
Subroutine is__ForeignTypeConstraint: not called CC=1 SCAR=1.0
Subroutine assert_StringLike: not called CC=1 SCAR=1.0
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
Pod undocumented
59 sub is_$_ { $_()->check(shift) } # uncoverable statement
60 sub assert_$_ { $_()->assert_return(shift) } # uncoverable statement
61 }; # uncoverable statement
62 } # uncoverable statement
63  
64 757 ▶sub _reinstall_subs {
Subroutine _reinstall_subs: called CC=1 SCAR=1.2
65  
66 # uncoverable subroutine
67 757 my $type = shift; # uncoverable statement
68 304 ▶ no strict 'refs'; # uncoverable statement
Subroutine BEGIN: called CC=1 SCAR=0.4
69 304 ▶ no warnings 'redefine'; # uncoverable statement
Subroutine BEGIN: called CC=1 SCAR=0.4
70 757 *{ 'is_' . $type->name } = $type->compiled_check; # uncoverable statement
71 757 *{ 'assert_' . $type->name } = \&$type; # uncoverable statement
72 757 $type; # uncoverable statement
73 } # uncoverable statement
74  
75 155 ▶sub _mkall {
Subroutine _mkall: called CC=3 SCAR=14.2
76  
77 # uncoverable subroutine
78 155 ▶ return unless $INC{'Type/Tiny.pm'}; # uncoverable statement
Branch: 1 branch
BranchTrueFalseTotal
unless $INC{"Type/Tiny.pm"} 1 154 155
79 154 __PACKAGE__->get_type( $_ ) for __PACKAGE__->type_names; # uncoverable statement
80 } # uncoverable statement
81  
82 51 ▶sub meta {
Subroutine meta: called CC=1 SCAR=0.0
Pod documented
83 51 return $_[0];
84 }
85  
86 2965 ▶sub type_names {
Subroutine type_names: called CC=1 SCAR=0.0
Pod documented
87 2965 qw(
88 StringLike BoolLike
89 HashLike ArrayLike CodeLike
90 TypeTiny _ForeignTypeConstraint
91 );
92 }
93  
94 1264 ▶sub has_type {
Subroutine has_type: called CC=1 SCAR=0.0
Pod documented
95 1264 my %has = map +( $_ => 1 ), shift->type_names;
96 1264 !!$has{ $_[0] };
97 }
98  
99 1255 ▶sub get_type {
Subroutine get_type: called CC=2 SCAR=6.9
Pod documented
100 1255 my $self = shift;
101 1255 ▶ return unless $self->has_type( @_ );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_type(@_) 1 1254 1255
102 304 ▶ no strict qw(refs);
Subroutine BEGIN: called CC=1 SCAR=0.0
103 1254 &{ $_[0] }();
104 }
105  
106 29 ▶sub coercion_names {
Subroutine coercion_names: called CC=1 SCAR=0.0
Pod documented
107 29 qw();
108 }
109  
110 2 ▶sub has_coercion {
Subroutine has_coercion: called CC=1 SCAR=0.0
Pod documented
111 2 my %has = map +( $_ => 1 ), shift->coercion_names;
112 2 !!$has{ $_[0] };
113 }
114  
115 1 ▶sub get_coercion {
Subroutine get_coercion: called CC=2 SCAR=7.1
Pod documented
116 1 my $self = shift;
117 1 ▶ return unless $self->has_coercion( @_ );
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_coercion(@_) 1 0 1
118 304 ▶ no strict qw(refs);
Subroutine BEGIN: called CC=1 SCAR=0.0
119 0 &{ $_[0] }(); # uncoverable statement
120 }
121  
122 304 my ( $__get_linear_isa_dfs, $tried_mro );
123 7 ▶$__get_linear_isa_dfs = sub {
Subroutine __ANON__: called CC=6 SCAR=27.4
124 7 ▶ if ( !$tried_mro && eval { require mro } ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $tried_mro and eval { do { require mro } }) 7 0 7
Condition33%1/3
not $tried_mro and eval { do { require mro } }
!ll&&!rl&&r
007
MC/DC0%0/2
not $tried_mro and eval { do { require mro } }
not $tried_mro eval { do { require mro } }
Truth table33%1/3
not(A) and B
A= not $tried_mroB= eval { do { require mro } }
ABresult
0X0
100
111
125 7 $__get_linear_isa_dfs = \&mro::get_linear_isa;
126 7 goto $__get_linear_isa_dfs;
127 }
128 304 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
129 0 my $classname = shift;
130 0 my @lin = ( $classname );
131 0 my %stored;
132 0 foreach my $parent ( @{"$classname\::ISA"} ) {
133 0 my $plin = $__get_linear_isa_dfs->( $parent );
134 0 foreach ( @$plin ) {
135 0 ▶ next if exists $stored{$_};
Branch: 1 branch
BranchTrueFalseTotal
if exists $stored{$_} 0 0 0
136 0 push( @lin, $_ );
137 0 $stored{$_} = 1;
138 }
139 }
140 0 return \@lin;
141 304 };
142  
143 257 ▶sub _check_overload {
Subroutine _check_overload: called CC=5 SCAR=16.2
144 257 my $package = shift;
145 257 ▶ if ( ref $package ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $package) 257 0 257
146 257 $package = blessed( $package );
147 257 ▶ return !!0 if !defined $package;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $package 0 257 257
148 }
149 257 my $op = shift;
150 257 my $mro = $__get_linear_isa_dfs->( $package );
151 257 foreach my $p ( @$mro ) {
152 315 my $fqmeth = $p . q{::(} . $op;
153 315 ▶ return !!1 if defined &{$fqmeth};
Branch: 1 branch
BranchTrueFalseTotal
if defined &{$fqmeth;} 49 266 315
154 }
155 208 !!0;
156 } #/ sub _check_overload
157  
158 657 ▶sub _get_check_overload_sub {
Subroutine _get_check_overload_sub: called CC=2 SCAR=6.9
159 657 ▶ if ( $Type::Tiny::AvoidCallbacks ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Type::Tiny::AvoidCallbacks) 389 268 657
160 return
161 389 '(sub { require overload; overload::Overloaded(ref $_[0] or $_[0]) and overload::Method((ref $_[0] or $_[0]), $_[1]) })->';
162 }
163 268 return 'Types::TypeTiny::_check_overload';
164 }
165  
166 461 ▶sub StringLike () {
Subroutine StringLike: called CC=2 SCAR=6.9
Pod undocumented
167 461 ▶ return $cache{StringLike} if defined $cache{StringLike};
Branch: 1 branch
BranchTrueFalseTotal
if defined $cache{"StringLike"} 180 281 461
168 281 require Type::Tiny;
169 my %common = (
170 name => "StringLike",
171 library => __PACKAGE__,
172 61 ▶ constraint => sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
173 61 ▶ defined( $_ ) && !ref( $_ )
Branch: 1 branch
BranchTrueFalseTotal
defined $_ and not ref $_ or builtin::blessed($_) and _check_overload($_, "\"\"") 16 45 61
Condition100%9/9
defined $_ && !ref($_) || builtin::blessed($_) && _check_overload($_, '""')
l!l&&r!l&&!r
16639
defined $_ and not ref $_
!ll&&!rl&&r
24316
builtin::blessed($_) and _check_overload($_, "\"\"")
!ll&&!rl&&r
24156
MC/DC100%4/4
defined $_ && !ref($_) || builtin::blessed($_) && _check_overload($_, '""')
defined $_ not ref $_ builtin::blessed($_) _check_overload($_, "\"\"")
Truth table71%5/7
A and not(B) || C and D
A= defined $_B= not ref $_C= builtin::blessed($_)D= _check_overload($_, "\"\"")
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
174 or blessed( $_ ) && _check_overload( $_, q[""] );
175 },
176 61 ▶ inlined => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
177 61 qq/defined($_[1]) && !ref($_[1]) or Scalar::Util::blessed($_[1]) && ${\ +_get_check_overload_sub() }($_[1], q[""])/;
178 },
179 1 ▶ type_default => sub { return '' },
Subroutine __ANON__: called CC=1 SCAR=0.0
180 281 );
181 281 if ( __XS ) {
182 281 my $xsub = Type::Tiny::XS::get_coderef_for( 'StringLike' );
183 281 my $xsubname = Type::Tiny::XS::get_subname_for( 'StringLike' );
184 281 my $inlined = $common{inlined};
185 $cache{StringLike} = "Type::Tiny"->new(
186 %common,
187 compiled_type_constraint => $xsub,
188 404 ▶ inlined => sub {
Subroutine __ANON__: called CC=3 SCAR=11.1
189
190 # uncoverable subroutine
191 404 ▶ ( $Type::Tiny::AvoidCallbacks or not $xsubname )
Branch: 1 branch
BranchTrueFalseTotal
$Type::Tiny::AvoidCallbacks || !$xsubname ? : 61 343 404
Condition66%2/3
$Type::Tiny::AvoidCallbacks or not $xsubname
l!l&&r!l&&!r
610343
MC/DC50%1/2
$Type::Tiny::AvoidCallbacks or not $xsubname
$Type::Tiny::AvoidCallbacks not $xsubname
Truth table66%2/3
A or not(B)
A= $Type::Tiny::AvoidCallbacksB= not $xsubname
ABresult
1X1
011
000
192 ? goto( $inlined )
193 : qq/$xsubname($_[1])/ # uncoverable statement
194 },
195 281 );
196 281 _reinstall_subs $cache{StringLike};
197 } #/ if ( __XS )
198 else {
199 $cache{StringLike} = "Type::Tiny"->new( %common );
200 }
201 } #/ sub StringLike
202  
203 253 ▶sub HashLike (;@) {
Subroutine HashLike: called CC=4 SCAR=14.0
Pod undocumented
204 253 ▶ return $cache{HashLike} if defined( $cache{HashLike} ) && !@_;
Branch: 1 branch
BranchTrueFalseTotal
if defined $cache{"HashLike"} and not @_ 96 157 253
Condition100%3/3
defined $cache{"HashLike"} and not @_
!ll&&!rl&&r
155296
MC/DC100%2/2
defined $cache{"HashLike"} and not @_
defined $cache{"HashLike"} not @_
Truth table100%3/3
A and not(B)
A= defined $cache{"HashLike"}B= not @_
ABresult
0X0
100
111
205 157 require Type::Tiny;
206 my %common = (
207 name => "HashLike",
208 library => __PACKAGE__,
209 71 ▶ constraint => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
210 71 ▶ ref( $_ ) eq q[HASH]
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq "HASH" or builtin::blessed($_) and _check_overload($_, "%{}") 7 64 71
Condition100%6/6
ref $_ eq 'HASH' || builtin::blessed($_) && _check_overload($_, '%{}')
l!l&&r!l&&!r
7856
builtin::blessed($_) and _check_overload($_, "%{}")
!ll&&!rl&&r
37198
MC/DC100%3/3
ref $_ eq 'HASH' || builtin::blessed($_) && _check_overload($_, '%{}')
ref $_ eq 'HASH' builtin::blessed($_) _check_overload($_, "%{}")
Truth table100%4/4
A || B and C
A= ref $_ eq 'HASH'B= builtin::blessed($_)C= _check_overload($_, "%{}")
ABCresult
1XX1
0111
00X0
0100
211 or blessed( $_ ) && _check_overload( $_, q[%{}] );
212 },
213 71 ▶ inlined => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
214 71 qq/ref($_[1]) eq q[HASH] or Scalar::Util::blessed($_[1]) && ${\ +_get_check_overload_sub() }($_[1], q[\%{}])/;
215 },
216 1 ▶ type_default => sub { return {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
217 2 ▶ constraint_generator => sub {
Subroutine __ANON__: called CC=3 SCAR=14.7
218 2 my $param = TypeTiny()->assert_coerce( shift );
219 2 my $check = $param->compiled_check;
220 2 if ( __XS ge '0.025' ) {
221 2 my $paramname = Type::Tiny::XS::is_known( $check );
222 2 ▶ my $xsub = defined($paramname)
Branch: 1 branch
BranchTrueFalseTotal
defined $paramname ? : 2 0 2
223 ? Type::Tiny::XS::get_coderef_for( "HashLike[$paramname]" )
224 : undef;
225 2 ▶ return $xsub if $xsub;
Branch: 1 branch
BranchTrueFalseTotal
if $xsub 2 0 2
226 }
227 0 ▶ sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
228 0 my %hash = %$_;
229 0 for my $key ( sort keys %hash ) {
230 0 ▶ $check->( $hash{$key} ) or return 0;
Branch: 1 branch
BranchTrueFalseTotal
&$check($hash{$key}) or return 0 0 0 0
231 }
232 0 return 1;
233 0 };
234 },
235 2 ▶ inline_generator => sub {
Subroutine __ANON__: called CC=3 SCAR=11.1
236 2 my $param = TypeTiny()->assert_coerce( shift );
237 2 ▶ return unless $param->can_be_inlined;
Branch: 1 branch
BranchTrueFalseTotal
unless $param->can_be_inlined 0 2 2
238 2 my $check = $param->compiled_check;
239 2 my $xsubname;
240 2 if ( __XS ge '0.025' ) {
241 2 my $paramname = Type::Tiny::XS::is_known( $check );
242 2 ▶ $xsubname = defined($paramname)
Branch: 1 branch
BranchTrueFalseTotal
defined $paramname ? : 2 0 2
243 ? Type::Tiny::XS::get_subname_for( "HashLike[$paramname]" )
244 : undef;
245 }
246 23 ▶ sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
247 23 my $var = pop;
248 23 ▶ return "$xsubname($var)" if $xsubname && !$Type::Tiny::AvoidCallbacks;
Branch: 1 branch
BranchTrueFalseTotal
if $xsubname and not $Type::Tiny::AvoidCallbacks 13 10 23
Condition66%2/3
$xsubname and not $Type::Tiny::AvoidCallbacks
!ll&&!rl&&r
01013
MC/DC50%1/2
$xsubname and not $Type::Tiny::AvoidCallbacks
$xsubname not $Type::Tiny::AvoidCallbacks
Truth table66%2/3
A and not(B)
A= $xsubnameB= not $Type::Tiny::AvoidCallbacks
ABresult
0X0
100
111
249 10 my $code = sprintf(
250 'do { my $ok=1; my %%h = %%{%s}; for my $k (sort keys %%h) { ($ok=0,next) unless (%s) }; $ok }',
251 $var,
252 $param->inline_check( '$h{$k}' ),
253 );
254 10 return ( undef, $code );
255 2 };
256 },
257 1 ▶ coercion_generator => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
258 1 my ( $parent, $child, $param ) = @_;
259 1 ▶ return unless $param->has_coercion;
Branch: 1 branch
BranchTrueFalseTotal
unless $param->has_coercion 0 1 1
260 1 my $coercible = $param->coercion->_source_type_union->compiled_check;
261 1 my $C = "Type::Coercion"->new( type_constraint => $child );
262 $C->add_type_coercions(
263 4 ▶ $parent => sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
264 4 ▶ my $origref = @_ ? $_[0] : $_;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 4 0 4
265 4 my %orig = %$origref;
266 4 my %new;
267 4 for my $k ( sort keys %orig ) {
268 8 ▶ return $origref unless $coercible->( $orig{$k} );
Branch: 1 branch
BranchTrueFalseTotal
unless &$coercible($orig{$k}) 2 6 8
269 6 $new{$k} = $param->coerce( $orig{$k} );
270 }
271 2 \%new;
272 },
273 1 );
274 1 return $C;
275 },
276 157 );
277 157 if ( __XS ) {
278 157 my $xsub = Type::Tiny::XS::get_coderef_for( 'HashLike' );
279 157 my $xsubname = Type::Tiny::XS::get_subname_for( 'HashLike' );
280 157 my $inlined = $common{inlined};
281 $cache{HashLike} = "Type::Tiny"->new(
282 %common,
283 compiled_type_constraint => $xsub,
284 291 ▶ inlined => sub {
Subroutine __ANON__: called CC=3 SCAR=11.1
285
286 # uncoverable subroutine
287 291 ▶ ( $Type::Tiny::AvoidCallbacks or not $xsubname )
Branch: 1 branch
BranchTrueFalseTotal
$Type::Tiny::AvoidCallbacks || !$xsubname ? : 71 220 291
Condition66%2/3
$Type::Tiny::AvoidCallbacks or not $xsubname
l!l&&r!l&&!r
710220
MC/DC50%1/2
$Type::Tiny::AvoidCallbacks or not $xsubname
$Type::Tiny::AvoidCallbacks not $xsubname
Truth table66%2/3
A or not(B)
A= $Type::Tiny::AvoidCallbacksB= not $xsubname
ABresult
1X1
011
000
288 ? goto( $inlined )
289 : qq/$xsubname($_[1])/ # uncoverable statement
290 },
291 157 );
292 157 _reinstall_subs $cache{HashLike};
293 } #/ if ( __XS )
294 else {
295 $cache{HashLike} = "Type::Tiny"->new( %common );
296 }
297
298 157 ▶ @_ ? $cache{HashLike}->parameterize( @{ $_[0] } ) : $cache{HashLike};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 2 155 157
299 } #/ sub HashLike (;@)
300  
301 258 ▶sub ArrayLike (;@) {
Subroutine ArrayLike: called CC=4 SCAR=14.0
Pod undocumented
302 258 ▶ return $cache{ArrayLike} if defined( $cache{ArrayLike} ) && !@_;
Branch: 1 branch
BranchTrueFalseTotal
if defined $cache{"ArrayLike"} and not @_ 100 158 258
Condition100%3/3
defined $cache{"ArrayLike"} and not @_
!ll&&!rl&&r
1562100
MC/DC100%2/2
defined $cache{"ArrayLike"} and not @_
defined $cache{"ArrayLike"} not @_
Truth table100%3/3
A and not(B)
A= defined $cache{"ArrayLike"}B= not @_
ABresult
0X0
100
111
303 158 require Type::Tiny;
304 my %common = (
305 name => "ArrayLike",
306 library => __PACKAGE__,
307 71 ▶ constraint => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
308 71 ▶ ref( $_ ) eq q[ARRAY]
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq "ARRAY" or builtin::blessed($_) and _check_overload($_, "\@{}") 9 62 71
Condition100%6/6
ref $_ eq 'ARRAY' || builtin::blessed($_) && _check_overload($_, '@{}')
l!l&&r!l&&!r
9854
builtin::blessed($_) and _check_overload($_, "\@{}")
!ll&&!rl&&r
35198
MC/DC100%3/3
ref $_ eq 'ARRAY' || builtin::blessed($_) && _check_overload($_, '@{}')
ref $_ eq 'ARRAY' builtin::blessed($_) _check_overload($_, "\@{}")
Truth table100%4/4
A || B and C
A= ref $_ eq 'ARRAY'B= builtin::blessed($_)C= _check_overload($_, "\@{}")
ABCresult
1XX1
0111
00X0
0100
309 or blessed( $_ ) && _check_overload( $_, q[@{}] );
310 },
311 71 ▶ inlined => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
312 71 qq/ref($_[1]) eq q[ARRAY] or Scalar::Util::blessed($_[1]) && ${\ +_get_check_overload_sub() }($_[1], q[\@{}])/;
313 },
314 1 ▶ type_default => sub { return [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
315 2 ▶ constraint_generator => sub {
Subroutine __ANON__: called CC=3 SCAR=14.7
316 2 my $param = TypeTiny()->assert_coerce( shift );
317 2 my $check = $param->compiled_check;
318 2 if ( __XS ge '0.025' ) {
319 2 my $paramname = Type::Tiny::XS::is_known( $check );
320 2 ▶ my $xsub = defined($paramname)
Branch: 1 branch
BranchTrueFalseTotal
defined $paramname ? : 2 0 2
321 ? Type::Tiny::XS::get_coderef_for( "ArrayLike[$paramname]" )
322 : undef;
323 2 ▶ return $xsub if $xsub;
Branch: 1 branch
BranchTrueFalseTotal
if $xsub 2 0 2
324 }
325 0 ▶ sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
326 0 my @arr = @$_;
327 0 for my $val ( @arr ) {
328 0 ▶ $check->( $val ) or return 0;
Branch: 1 branch
BranchTrueFalseTotal
&$check($val) or return 0 0 0 0
329 }
330 0 return 1;
331 0 };
332 },
333 2 ▶ inline_generator => sub {
Subroutine __ANON__: called CC=3 SCAR=11.1
334 2 my $param = TypeTiny()->assert_coerce( shift );
335 2 ▶ return unless $param->can_be_inlined;
Branch: 1 branch
BranchTrueFalseTotal
unless $param->can_be_inlined 0 2 2
336 2 my $check = $param->compiled_check;
337 2 my $xsubname;
338 2 if ( __XS ge '0.025' ) {
339 2 my $paramname = Type::Tiny::XS::is_known( $check );
340 2 ▶ $xsubname = defined($paramname)
Branch: 1 branch
BranchTrueFalseTotal
defined $paramname ? : 2 0 2
341 ? Type::Tiny::XS::get_subname_for( "ArrayLike[$paramname]" )
342 : undef;
343 }
344 23 ▶ sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
345 23 my $var = pop;
346 23 ▶ return "$xsubname($var)" if $xsubname && !$Type::Tiny::AvoidCallbacks;
Branch: 1 branch
BranchTrueFalseTotal
if $xsubname and not $Type::Tiny::AvoidCallbacks 13 10 23
Condition66%2/3
$xsubname and not $Type::Tiny::AvoidCallbacks
!ll&&!rl&&r
01013
MC/DC50%1/2
$xsubname and not $Type::Tiny::AvoidCallbacks
$xsubname not $Type::Tiny::AvoidCallbacks
Truth table66%2/3
A and not(B)
A= $xsubnameB= not $Type::Tiny::AvoidCallbacks
ABresult
0X0
100
111
347 10 my $code = sprintf(
348 'do { my $ok=1; for my $v (@{%s}) { ($ok=0,next) unless (%s) }; $ok }',
349 $var,
350 $param->inline_check( '$v' ),
351 );
352 10 return ( undef, $code );
353 2 };
354 },
355 1 ▶ coercion_generator => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
356 1 my ( $parent, $child, $param ) = @_;
357 1 ▶ return unless $param->has_coercion;
Branch: 1 branch
BranchTrueFalseTotal
unless $param->has_coercion 0 1 1
358 1 my $coercible = $param->coercion->_source_type_union->compiled_check;
359 1 my $C = "Type::Coercion"->new( type_constraint => $child );
360 $C->add_type_coercions(
361 4 ▶ $parent => sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
362 4 ▶ my $origref = @_ ? $_[0] : $_;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 4 0 4
363 4 my @orig = @$origref;
364 4 my @new;
365 4 for my $v ( @orig ) {
366 10 ▶ return $origref unless $coercible->( $v );
Branch: 1 branch
BranchTrueFalseTotal
unless &$coercible($v) 2 8 10
367 8 push @new, $param->coerce( $v );
368 }
369 2 \@new;
370 },
371 1 );
372 1 return $C;
373 },
374 158 );
375 158 if ( __XS ) {
376 158 my $xsub = Type::Tiny::XS::get_coderef_for( 'ArrayLike' );
377 158 my $xsubname = Type::Tiny::XS::get_subname_for( 'ArrayLike' );
378 158 my $inlined = $common{inlined};
379 $cache{ArrayLike} = "Type::Tiny"->new(
380 %common,
381 compiled_type_constraint => $xsub,
382 292 ▶ inlined => sub {
Subroutine __ANON__: called CC=3 SCAR=11.1
383
384 # uncoverable subroutine
385 292 ▶ ( $Type::Tiny::AvoidCallbacks or not $xsubname )
Branch: 1 branch
BranchTrueFalseTotal
$Type::Tiny::AvoidCallbacks || !$xsubname ? : 71 221 292
Condition66%2/3
$Type::Tiny::AvoidCallbacks or not $xsubname
l!l&&r!l&&!r
710221
MC/DC50%1/2
$Type::Tiny::AvoidCallbacks or not $xsubname
$Type::Tiny::AvoidCallbacks not $xsubname
Truth table66%2/3
A or not(B)
A= $Type::Tiny::AvoidCallbacksB= not $xsubname
ABresult
1X1
011
000
386 ? goto( $inlined )
387 : qq/$xsubname($_[1])/ # uncoverable statement
388 },
389 158 );
390 158 _reinstall_subs $cache{ArrayLike};
391 } #/ if ( __XS )
392 else {
393 $cache{ArrayLike} = "Type::Tiny"->new( %common );
394 }
395
396 158 ▶ @_ ? $cache{ArrayLike}->parameterize( @{ $_[0] } ) : $cache{ArrayLike};
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 2 156 158
397 } #/ sub ArrayLike (;@)
398  
399 304 ▶if ( $] ge '5.014' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($] ge "5.014") 304 0 304
400 304 &Scalar::Util::set_prototype( $_, ';$' ) for \&HashLike, \&ArrayLike;
401 }
402  
403 259 ▶sub CodeLike () {
Subroutine CodeLike: called CC=2 SCAR=6.9
Pod undocumented
404 259 ▶ return $cache{CodeLike} if $cache{CodeLike};
Branch: 1 branch
BranchTrueFalseTotal
if $cache{"CodeLike"} 98 161 259
405 161 require Type::Tiny;
406 my %common = (
407 name => "CodeLike",
408 62 ▶ constraint => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
409 62 ▶ ref( $_ ) eq q[CODE]
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq "CODE" or builtin::blessed($_) and _check_overload($_, "&{}") 2 60 62
Condition100%6/6
ref $_ eq 'CODE' || builtin::blessed($_) && _check_overload($_, '&{}')
l!l&&r!l&&!r
2357
builtin::blessed($_) and _check_overload($_, "&{}")
!ll&&!rl&&r
38193
MC/DC100%3/3
ref $_ eq 'CODE' || builtin::blessed($_) && _check_overload($_, '&{}')
ref $_ eq 'CODE' builtin::blessed($_) _check_overload($_, "&{}")
Truth table100%4/4
A || B and C
A= ref $_ eq 'CODE'B= builtin::blessed($_)C= _check_overload($_, "&{}")
ABCresult
1XX1
0111
00X0
0100
410 or blessed( $_ ) && _check_overload( $_, q[&{}] );
411 },
412 62 ▶ inlined => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
413 62 qq/ref($_[1]) eq q[CODE] or Scalar::Util::blessed($_[1]) && ${\ +_get_check_overload_sub() }($_[1], q[\&{}])/;
414 },
415 1 ▶ type_default => sub { return sub {} },
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
416 161 library => __PACKAGE__,
417 );
418 161 if ( __XS ) {
419 161 my $xsub = Type::Tiny::XS::get_coderef_for( 'CodeLike' );
420 161 my $xsubname = Type::Tiny::XS::get_subname_for( 'CodeLike' );
421 161 my $inlined = $common{inlined};
422 $cache{CodeLike} = "Type::Tiny"->new(
423 %common,
424 compiled_type_constraint => $xsub,
425 286 ▶ inlined => sub {
Subroutine __ANON__: called CC=3 SCAR=11.1
426
427 # uncoverable subroutine
428 286 ▶ ( $Type::Tiny::AvoidCallbacks or not $xsubname )
Branch: 1 branch
BranchTrueFalseTotal
$Type::Tiny::AvoidCallbacks || !$xsubname ? : 62 224 286
Condition66%2/3
$Type::Tiny::AvoidCallbacks or not $xsubname
l!l&&r!l&&!r
620224
MC/DC50%1/2
$Type::Tiny::AvoidCallbacks or not $xsubname
$Type::Tiny::AvoidCallbacks not $xsubname
Truth table66%2/3
A or not(B)
A= $Type::Tiny::AvoidCallbacksB= not $xsubname
ABresult
1X1
011
000
429 ? goto( $inlined )
430 : qq/$xsubname($_[1])/ # uncoverable statement
431 },
432 161 );
433 161 _reinstall_subs $cache{CodeLike};
434 } #/ if ( __XS )
435 else {
436 $cache{CodeLike} = "Type::Tiny"->new( %common );
437 }
438 } #/ sub CodeLike
439  
440 482 ▶sub BoolLike () {
Subroutine BoolLike: called CC=2 SCAR=6.9
Pod undocumented
441 482 ▶ return $cache{BoolLike} if $cache{BoolLike};
Branch: 1 branch
BranchTrueFalseTotal
if $cache{"BoolLike"} 328 154 482
442 154 require Type::Tiny;
443 $cache{BoolLike} = "Type::Tiny"->new(
444 name => "BoolLike",
445 62 ▶ constraint => sub {
Subroutine __ANON__: called CC=12 SCAR=25.0
446 !defined( $_ )
447 or !ref( $_ ) && ( $_ eq '' || $_ eq '0' || $_ eq '1' )
448 or blessed( $_ ) && (
449 _check_overload( $_, q[bool] )
450 4 ▶ or _check_overload( $_, q[0+] ) && do { my $n = sprintf('%d', $_); $n==0 or $n==1 }
Condition66%2/3
$n == 0 || $n == 1
l!l&&r!l&&!r
220
MC/DC0%0/2
$n == 0 || $n == 1
$n == 0 $n == 1
Truth table66%2/3
A || B
A= $n == 0B= $n == 1
ABresult
1X1
011
000
451 62 ▶ or do { my $d = $_->can('DOES') || $_->can('isa'); $_->$d('boolean') }
Branch: 1 branch
BranchTrueFalseTotal
not defined $_ or not ref $_ and $_ eq "" || $_ eq 0 || $_ eq 1 or builtin::blessed($_) and _check_overload($_, "bool") || _check_overload($_, "0+") && do { my $n = sprintf("%d", $_); $n == 0 or $n == 1 } || do { my $d = $_->can("DOES") || $_->can("isa"); $_->$d("boolean") } 12 50 62
Condition90%27/30
!defined($_) || !ref($_) && ($_ eq '' || $_ eq '0' || $_ eq '1') || builtin::blessed($_) && (_check_overload($_, 'bool') || _check_overload($_, '0+') && do { my $n = sprintf('%d', $_); $n == 0 or $n == 1 } || do { my $d = $_->can('DOES') || $_->can('isa'); $_->$d('boolean') })
l!l&&r!l&&!r
12842
not defined $_ or not ref $_ and $_ eq "" || $_ eq 0 || $_ eq 1
l!l&&r!l&&!r
21050
not ref $_ and $_ eq "" || $_ eq 0 || $_ eq 1
!ll&&!rl&&r
42810
$_ eq "" or $_ eq 0 or $_ eq 1
l!l&&r!l&&!r
648
$_ eq "" or $_ eq 0
l!l&&r!l&&!r
4212
builtin::blessed($_) and _check_overload($_, "bool") || _check_overload($_, "0+") && do { my $n = sprintf("%d", $_); $n == 0 or $n == 1 } || do { my $d = $_->can("DOES") || $_->can("isa"); $_->$d("boolean") }
!ll&&!rl&&r
29138
_check_overload($_, "bool") or _check_overload($_, "0+") and do { my $n = sprintf("%d", $_); $n == 0 or $n == 1 } or do { my $d = $_->can("DOES") || $_->can("isa"); $_->$d("boolean") }
l!l&&r!l&&!r
6213
_check_overload($_, "bool") or _check_overload($_, "0+") and do { my $n = sprintf("%d", $_); $n == 0 or $n == 1 }
l!l&&r!l&&!r
2415
_check_overload($_, "0+") and do { my $n = sprintf("%d", $_); $n == 0 or $n == 1 }
!ll&&!rl&&r
1504
$_->can('DOES') || $_->can('isa')
l!l&&r!l&&!r
1500
MC/DC90%9/10
!defined($_) || !ref($_) && ($_ eq '' || $_ eq '0' || $_ eq '1') || builtin::blessed($_) && (_check_overload($_, 'bool') || _check_overload($_, '0+') && do { my $n = sprintf('%d', $_); $n == 0 or $n == 1 } || do { my $d = $_->can('DOES') || $_->can('isa'); $_->$d('boolean') })
not defined $_ not ref $_ $_ eq "" $_ eq 0 $_ eq 1 builtin::blessed($_) _check_overload($_, "bool") _check_overload($_, "0+") do { my $n = sprintf("%d", $_); $n == 0 or $n == 1 } do { my $d = $_->can("DOES") || $_->can("isa"); $_->$d("boolean") }
MC/DC0%0/2
$_->can('DOES') || $_->can('isa')
$_->can('DOES') $_->can('isa')
Truth table55%10/18
not(A) or not(B) and C or D or E || F and G or H and I or J
A= not defined $_B= not ref $_C= $_ eq ""D= $_ eq 0E= $_ eq 1F= builtin::blessed($_)G= _check_overload($_, "bool")H= _check_overload($_, "0+")I= do { my $n = sprintf("%d", $_); $n == 0 or $n == 1 }J= do { my $d = $_->can("DOES") || $_->can("isa"); $_->$d("boolean") }
ABCDEFGHIJresult
1XXXXXXXXX1
011XXXXXXX1
0101XXXXXX1
01001XXXXX1
00XXX11XXX1
00XXX1011X1
00XXX100X11
00XXX101011
0100011XXX1
010001011X1
01000100X11
01000101011
00XXX0XXXX0
00XXX100X00
00XXX101000
010000XXXX0
01000100X00
01000101000
Truth table33%1/3
A || B
A= $_->can('DOES')B= $_->can('isa')
ABresult
1X1
011
000
452 )
453 },
454 196 ▶ inlined => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
455 196 qq/do {
456 local \$_ = $_;
457 !defined()
458 or !ref() && ( \$_ eq '' || \$_ eq '0' || \$_ eq '1' )
459 or Scalar::Util::blessed(\$_) && (
460 196 ${\ +_get_check_overload_sub() }(\$_, q[bool])
461 196 or ${\ +_get_check_overload_sub() }(\$_, q[0+]) && do { my \$n = sprintf('%d', $_); \$n==0 or \$n==1 }
462 or do { my \$d = \$_->can('DOES') || \$_->can('isa'); \$_->\$d('boolean') }
463 )
464 }/;
465 },
466 1 ▶ type_default => sub { return !!0 },
Subroutine __ANON__: called CC=1 SCAR=0.0
467 154 library => __PACKAGE__,
468 );
469 } #/ sub BoolLike
470  
471 131790 ▶sub TypeTiny () {
Subroutine TypeTiny: called CC=2 SCAR=6.9
Pod undocumented
472 131790 ▶ return $cache{TypeTiny} if defined $cache{TypeTiny};
Branch: 1 branch
BranchTrueFalseTotal
if defined $cache{"TypeTiny"} 131508 282 131790
473 282 require Type::Tiny;
474 $cache{TypeTiny} = "Type::Tiny"->new(
475 name => "TypeTiny",
476 62 ▶ constraint => sub { blessed( $_ ) && $_->isa( q[Type::Tiny] ) },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
builtin::blessed($_) and $_->isa("Type::Tiny") 22 40 62
477 454 ▶ inlined => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
478 454 my $var = $_[1];
479 454 "Scalar::Util::blessed($var) && $var\->isa(q[Type::Tiny])";
480 },
481 1 ▶ type_default => sub { require Types::Standard; return Types::Standard::Any() },
Subroutine __ANON__: called CC=1 SCAR=0.0
482 library => __PACKAGE__,
483 28 ▶ _build_coercion => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
484 28 my $c = shift;
485 28 $c->add_type_coercions( _ForeignTypeConstraint(), \&to_TypeTiny );
486 28 $c->freeze;
487 },
488 282 );
489 } #/ sub TypeTiny
490  
491 276 ▶sub _ForeignTypeConstraint () {
Subroutine _ForeignTypeConstraint: called CC=2 SCAR=6.9
492 276 ▶ return $cache{_ForeignTypeConstraint} if defined $cache{_ForeignTypeConstraint};
Branch: 1 branch
BranchTrueFalseTotal
if defined $cache{"_ForeignTypeConstraint"} 122 154 276
493 154 require Type::Tiny;
494 $cache{_ForeignTypeConstraint} = "Type::Tiny"->new(
495 name => "_ForeignTypeConstraint",
496 constraint => \&_is_ForeignTypeConstraint,
497 197 ▶ inlined => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
498 197 qq/ref($_[1]) && do { require Types::TypeTiny; Types::TypeTiny::_is_ForeignTypeConstraint($_[1]) }/;
499 },
500 154 library => __PACKAGE__,
501 );
502 } #/ sub _ForeignTypeConstraint
503  
504 304 my %ttt_cache;
505  
506 222 ▶sub _is_ForeignTypeConstraint {
Subroutine _is_ForeignTypeConstraint: called CC=10 SCAR=24.0
507 222 ▶ my $t = @_ ? $_[0] : $_;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 222 0 222
508 222 ▶ return !!1 if ref $t eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
if ref $t eq "CODE" 6 216 222
509 216 ▶ if ( my $class = blessed $t ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $class = builtin::blessed($t)) 100 116 216
510 100 ▶ return !!0 if $class->isa( "Type::Tiny" );
Branch: 1 branch
BranchTrueFalseTotal
if $class->isa("Type::Tiny") 0 100 100
511 100 ▶ return !!1 if $class->isa( "Moose::Meta::TypeConstraint" );
Branch: 1 branch
BranchTrueFalseTotal
if $class->isa("Moose::Meta::TypeConstraint") 0 100 100
512 100 ▶ return !!1 if $class->isa( "MooseX::Types::TypeDecorator" );
Branch: 1 branch
BranchTrueFalseTotal
if $class->isa("MooseX::Types::TypeDecorator") 0 100 100
513 100 ▶ return !!1 if $class->isa( "Validation::Class::Simple" );
Branch: 1 branch
BranchTrueFalseTotal
if $class->isa("Validation::Class::Simple") 0 100 100
514 100 ▶ return !!1 if $class->isa( "Validation::Class" );
Branch: 1 branch
BranchTrueFalseTotal
if $class->isa("Validation::Class") 0 100 100
515 100 ▶ return !!1 if $t->can( "check" );
Branch: 1 branch
BranchTrueFalseTotal
if $t->can("check") 5 95 100
516 }
517 211 !!0;
518 } #/ sub _is_ForeignTypeConstraint
519  
520 156104 ▶sub to_TypeTiny {
Subroutine to_TypeTiny: called CC=18 SCAR=30.5
Pod documented
521 156104 ▶ my $t = @_ ? $_[0] : $_;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 156104 0 156104
522
523 156104 ▶ return $t unless ( my $ref = ref $t );
Branch: 1 branch
BranchTrueFalseTotal
unless my $ref = ref $t 4670 151434 156104
524 151434 ▶ return $t if $ref =~ /^Type::Tiny\b/;
Branch: 1 branch
BranchTrueFalseTotal
if $ref =~ /^Type::Tiny\b/ 111339 40095 151434
525
526 40095 ▶ return $ttt_cache{ refaddr( $t ) } if $ttt_cache{ refaddr( $t ) };
Branch: 1 branch
BranchTrueFalseTotal
if $ttt_cache{builtin::refaddr($t)} 0 40095 40095
527
528 #<<<
529 40095 ▶ if ( my $class = blessed $t) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $class = builtin::blessed($t)) 53 40042 40095
530 53 ▶ return $t if $class->isa( "Type::Tiny" );
Branch: 1 branch
BranchTrueFalseTotal
if $class->isa("Type::Tiny") 0 53 53
531 53 ▶ return _TypeTinyFromMoose( $t ) if $class eq "MooseX::Types::TypeDecorator"; # needed before MooseX::Types 0.35.
Branch: 1 branch
BranchTrueFalseTotal
if $class eq "MooseX::Types::TypeDecorator" 0 53 53
532 53 ▶ return _TypeTinyFromMoose( $t ) if $class->isa( "Moose::Meta::TypeConstraint" );
Branch: 1 branch
BranchTrueFalseTotal
if $class->isa("Moose::Meta::TypeConstraint") 0 53 53
533 53 ▶ return _TypeTinyFromMoose( $t ) if $class->isa( "MooseX::Types::TypeDecorator" );
Branch: 1 branch
BranchTrueFalseTotal
if $class->isa("MooseX::Types::TypeDecorator") 0 53 53
534 53 ▶ return _TypeTinyFromMouse( $t ) if $class->isa( "Mouse::Meta::TypeConstraint" );
Branch: 1 branch
BranchTrueFalseTotal
if $class->isa("Mouse::Meta::TypeConstraint") 0 53 53
535 53 ▶ return _TypeTinyFromValidationClass( $t ) if $class->isa( "Validation::Class::Simple" );
Branch: 1 branch
BranchTrueFalseTotal
if $class->isa("Validation::Class::Simple") 0 53 53
536 53 ▶ return _TypeTinyFromValidationClass( $t ) if $class->isa( "Validation::Class" );
Branch: 1 branch
BranchTrueFalseTotal
if $class->isa("Validation::Class") 0 53 53
537 53 ▶ return $t->to_TypeTiny if $t->can( "DOES" ) && $t->DOES( "Type::Library::Compiler::TypeConstraint" ) && $t->can( "to_TypeTiny" );
Branch: 1 branch
BranchTrueFalseTotal
if $t->can("DOES") and $t->DOES("Type::Library::Compiler::TypeConstraint") and $t->can("to_TypeTiny") 6 47 53
Condition66%4/6
$t->can("DOES") and $t->DOES("Type::Library::Compiler::TypeConstraint") and $t->can("to_TypeTiny")
!ll&&!rl&&r
4706
$t->can("DOES") and $t->DOES("Type::Library::Compiler::TypeConstraint")
!ll&&!rl&&r
0476
MC/DC33%1/3
$t->can("DOES") and $t->DOES("Type::Library::Compiler::TypeConstraint") and $t->can("to_TypeTiny")
$t->can("DOES") $t->DOES("Type::Library::Compiler::TypeConstraint") $t->can("to_TypeTiny")
Truth table50%2/4
A and B and C
A= $t->can("DOES")B= $t->DOES("Type::Library::Compiler::TypeConstraint")C= $t->can("to_TypeTiny")
ABCresult
0XX0
10X0
1100
1111
538 47 ▶ return _TypeTinyFromGeneric( $t ) if $t->can( "check" ); # i.e. Type::API::Constraint
Branch: 1 branch
BranchTrueFalseTotal
if $t->can("check") 3 44 47
539 } #/ if ( my $class = blessed...)
540 #>>>
541
542 40086 ▶ return _TypeTinyFromCodeRef( $t ) if $ref eq q(CODE);
Branch: 1 branch
BranchTrueFalseTotal
if $ref eq "CODE" 40019 67 40086
543
544 67 $t;
545 } #/ sub to_TypeTiny
546  
547 0 ▶sub _TypeTinyFromMoose {
Subroutine _TypeTinyFromMoose: not called CC=12 SCAR=50.5
548 0 my $t = $_[0];
549
550 0 ▶ if ( ref $t->{"Types::TypeTiny::to_TypeTiny"} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $t->{"Types::TypeTiny::to_TypeTiny"}) 0 0 0
551 0 return $t->{"Types::TypeTiny::to_TypeTiny"};
552 }
553
554 0 ▶ if ( $t->name ne '__ANON__' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->name ne "__ANON__") 0 0 0
555 0 require Types::Standard;
556 0 my $ts = 'Types::Standard'->get_type( $t->name );
557 0 ▶ return $ts if $ts->{_is_core};
Branch: 1 branch
BranchTrueFalseTotal
if $ts->{"_is_core"} 0 0 0
558 }
559
560 #<<<
561 0 ▶ my ( $tt_class, $tt_opts ) =
Branch: 6 branches
BranchTrueFalseTotal
$t->can('parameterize') ? : 0 0 0
$t->isa('Moose::Meta::TypeConstraint::Enum') ? : 0 0 0
$t->isa('Moose::Meta::TypeConstraint::Class') ? : 0 0 0
$t->isa('Moose::Meta::TypeConstraint::Role') ? : 0 0 0
$t->isa('Moose::Meta::TypeConstraint::Union') ? : 0 0 0
$t->isa('Moose::Meta::TypeConstraint::DuckType') ? : 0 0 0
562 $t->can( 'parameterize' ) ? _TypeTinyFromMoose_parameterizable( $t ) :
563 $t->isa( 'Moose::Meta::TypeConstraint::Enum' ) ? _TypeTinyFromMoose_enum( $t ) :
564 $t->isa( 'Moose::Meta::TypeConstraint::Class' ) ? _TypeTinyFromMoose_class( $t ) :
565 $t->isa( 'Moose::Meta::TypeConstraint::Role' ) ? _TypeTinyFromMoose_role( $t ) :
566 $t->isa( 'Moose::Meta::TypeConstraint::Union' ) ? _TypeTinyFromMoose_union( $t ) :
567 $t->isa( 'Moose::Meta::TypeConstraint::DuckType' ) ? _TypeTinyFromMoose_ducktype( $t ) :
568 _TypeTinyFromMoose_baseclass( $t );
569 #>>>
570
571 # Standard stuff to do with all type constraints from Moose,
572 # regardless of variety.
573 0 $tt_opts->{moose_type} = $t;
574 0 $tt_opts->{display_name} = $t->name;
575 0 ▶ $tt_opts->{message} = sub { $t->get_message( $_ ) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
576 0 ▶ if $t->has_message;
Branch: 1 branch
BranchTrueFalseTotal
if $t->has_message 0 0 0
577
578 0 my $new = $tt_class->new( %$tt_opts );
579 0 $ttt_cache{ refaddr( $t ) } = $new;
580 0 weaken( $ttt_cache{ refaddr( $t ) } );
581
582 0 ▶ $new->{coercion} = do {
Branch: 1 branch
BranchTrueFalseTotal
if $t->has_coercion 0 0 0
583 0 require Type::Coercion::FromMoose;
584 0 'Type::Coercion::FromMoose'->new(
585 type_constraint => $new,
586 moose_coercion => $t->coercion,
587 );
588 } if $t->has_coercion;
589
590 0 return $new;
591 } #/ sub _TypeTinyFromMoose
592  
593 0 ▶sub _TypeTinyFromMoose_baseclass {
Subroutine _TypeTinyFromMoose_baseclass: not called CC=7 SCAR=40.3
594 0 my $t = shift;
595 0 my %opts;
596 0 ▶ $opts{parent} = to_TypeTiny( $t->parent ) if $t->has_parent;
Branch: 1 branch
BranchTrueFalseTotal
if $t->has_parent 0 0 0
597 0 $opts{constraint} = $t->constraint;
598 0 ▶ $opts{inlined} = sub { shift; $t->_inline_check( @_ ) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
599 0 ▶ if $t->can( "can_be_inlined" ) && $t->can_be_inlined;
Branch: 1 branch
BranchTrueFalseTotal
if $t->can("can_be_inlined") and $t->can_be_inlined 0 0 0
Condition0%0/3
$t->can("can_be_inlined") and $t->can_be_inlined
!ll&&!rl&&r
000
MC/DC0%0/2
$t->can("can_be_inlined") and $t->can_be_inlined
$t->can("can_be_inlined") $t->can_be_inlined
Truth table0%0/3
A and B
A= $t->can("can_be_inlined")B= $t->can_be_inlined
ABresult
0X0
100
111
600
601 # Cowardly refuse to inline types that need to close over stuff
602 0 ▶ if ( $opts{inlined} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($opts{"inlined"}) 0 0 0
603 0 ▶ my %env = %{ $t->inline_environment || {} };
Condition0%0/2
$t->inline_environment || {}
l!l
00
MC/DC0%0/1
$t->inline_environment || {}
$t->inline_environment
Truth table0%0/2
A
A= $t->inline_environment
Aresult
11
00
604 0 ▶ delete( $opts{inlined} ) if keys %env;
Branch: 1 branch
BranchTrueFalseTotal
if keys %env 0 0 0
605 }
606
607 0 require Type::Tiny;
608 0 return 'Type::Tiny' => \%opts;
609 } #/ sub _TypeTinyFromMoose_baseclass
610  
611 0 ▶sub _TypeTinyFromMoose_union {
Subroutine _TypeTinyFromMoose_union: not called CC=1 SCAR=6.9
612 0 my $t = shift;
613 0 my @mapped = map _TypeTinyFromMoose( $_ ), @{ $t->type_constraints };
614 0 require Type::Tiny::Union;
615 0 return 'Type::Tiny::Union' => { type_constraints => \@mapped };
616 }
617  
618 0 ▶sub _TypeTinyFromMoose_enum {
Subroutine _TypeTinyFromMoose_enum: not called CC=1 SCAR=6.9
619 0 my $t = shift;
620 0 require Type::Tiny::Enum;
621 0 return 'Type::Tiny::Enum' => { values => [ @{ $t->values } ] };
622 }
623  
624 0 ▶sub _TypeTinyFromMoose_class {
Subroutine _TypeTinyFromMoose_class: not called CC=1 SCAR=6.9
625 0 my $t = shift;
626 0 require Type::Tiny::Class;
627 0 return 'Type::Tiny::Class' => { class => $t->class };
628 }
629  
630 0 ▶sub _TypeTinyFromMoose_role {
Subroutine _TypeTinyFromMoose_role: not called CC=1 SCAR=6.9
631 0 my $t = shift;
632 0 require Type::Tiny::Role;
633 0 return 'Type::Tiny::Role' => { role => $t->role };
634 }
635  
636 0 ▶sub _TypeTinyFromMoose_ducktype {
Subroutine _TypeTinyFromMoose_ducktype: not called CC=1 SCAR=6.9
637 0 my $t = shift;
638 0 require Type::Tiny::Duck;
639 0 return 'Type::Tiny::Duck' => { methods => [ @{ $t->methods } ] };
640 }
641  
642 0 ▶sub _TypeTinyFromMoose_parameterizable {
Subroutine _TypeTinyFromMoose_parameterizable: not called CC=1 SCAR=6.9
643 0 my $t = shift;
644 0 my ( $class, $opts ) = _TypeTinyFromMoose_baseclass( $t );
645 0 ▶ $opts->{constraint_generator} = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
646
647 # convert args into Moose native types; not strictly necessary
648 0 ▶ my @args = map { is_TypeTiny( $_ ) ? $_->moose_type : $_ } @_;
Branch: 1 branch
BranchTrueFalseTotal
is_TypeTiny($_) ? : 0 0 0
649 0 _TypeTinyFromMoose( $t->parameterize( @args ) );
650 0 };
651 0 return ( $class, $opts );
652 } #/ sub _TypeTinyFromMoose_parameterizable
653  
654 0 ▶sub _TypeTinyFromValidationClass {
Subroutine _TypeTinyFromValidationClass: not called CC=2 SCAR=16.2
655 0 my $t = $_[0];
656
657 0 require Type::Tiny;
658 0 require Types::Standard;
659
660 0 my %opts = (
661 parent => Types::Standard::HashRef(),
662 _validation_class => $t,
663 );
664
665 0 ▶ if ( $t->VERSION >= "7.900048" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->VERSION >= '7.900048') { } 0 0 0
666 0 ▶ $opts{constraint} = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
667 0 $t->params->clear;
668 0 $t->params->add( %$_ );
669 0 my $f = $t->filtering;
670 0 $t->filtering( 'off' );
671 0 my $r = eval { $t->validate };
672 0 ▶ $t->filtering( $f || 'pre' );
Condition0%0/2
$f || 'pre'
l!l
00
MC/DC0%0/1
$f || 'pre'
$f
Truth table0%0/2
A
A= $f
Aresult
11
00
673 0 return $r;
674 0 };
675 0 ▶ $opts{message} = sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
676 0 $t->params->clear;
677 0 $t->params->add( %$_ );
678 0 my $f = $t->filtering;
679 0 $t->filtering( 'off' );
680 0 ▶ my $r = ( eval { $t->validate } ? "OK" : $t->errors_to_string );
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $t->validate } } ? : 0 0 0
681 0 ▶ $t->filtering( $f || 'pre' );
Condition0%0/2
$f || 'pre'
l!l
00
MC/DC0%0/1
$f || 'pre'
$f
Truth table0%0/2
A
A= $f
Aresult
11
00
682 0 return $r;
683 0 };
684 } #/ if ( $t->VERSION >= "7.900048")
685 else # need to use hackish method
686 {
687 0 ▶ $opts{constraint} = sub {
Subroutine __ANON__: not called CC=1 SCAR=2.6
688 0 $t->params->clear;
689 0 $t->params->add( %$_ );
690 304 ▶ no warnings "redefine";
Subroutine BEGIN: called CC=1 SCAR=0.0
691 0 ▶ local *Validation::Class::Directive::Filters::execute_filtering = sub { $_[0] };
Subroutine __ANON__: not called CC=1 SCAR=6.9
692 0 eval { $t->validate };
693 0 };
694 0 ▶ $opts{message} = sub {
Subroutine __ANON__: not called CC=2 SCAR=12.6
695 0 $t->params->clear;
696 0 $t->params->add( %$_ );
697 304 ▶ no warnings "redefine";
Subroutine BEGIN: called CC=1 SCAR=0.0
698 0 ▶ local *Validation::Class::Directive::Filters::execute_filtering = sub { $_[0] };
Subroutine __ANON__: not called CC=1 SCAR=6.9
699 0 ▶ eval { $t->validate } ? "OK" : $t->errors_to_string;
Branch: 1 branch
BranchTrueFalseTotal
eval { do { $t->validate } } ? : 0 0 0
700 0 };
701 } #/ else [ if ( $t->VERSION >= "7.900048")]
702
703 0 require Type::Tiny;
704 0 my $new = "Type::Tiny"->new( %opts );
705
706 $new->coercion->add_type_coercions(
707 0 ▶ Types::Standard::HashRef() => sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
708 0 my %params = %$_;
709 0 ▶ for my $k ( keys %params ) { delete $params{$_} unless $t->get_fields( $k ) }
Branch: 1 branch
BranchTrueFalseTotal
unless $t->get_fields($k) 0 0 0
710 0 $t->params->clear;
711 0 $t->params->add( %params );
712 0 eval { $t->validate };
713 0 $t->get_hash;
714 },
715 0 );
716
717 0 $ttt_cache{ refaddr( $t ) } = $new;
718 0 weaken( $ttt_cache{ refaddr( $t ) } );
719 0 return $new;
720 } #/ sub _TypeTinyFromValidationClass
721  
722 3 ▶sub _TypeTinyFromGeneric {
Subroutine _TypeTinyFromGeneric: called CC=9 SCAR=24.8
723 3 my $t = $_[0];
724
725 my %opts = (
726 30 ▶ constraint => sub { $t->check( @_ ? @_ : $_ ) },
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 30 0 30
727 3 );
728
729 2 ▶ $opts{message} = sub { $t->get_message( @_ ? @_ : $_ ) }
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 2 0 2
730 3 ▶ if $t->can( "get_message" );
Branch: 1 branch
BranchTrueFalseTotal
if $t->can("get_message") 3 0 3
731
732 3 ▶ $opts{display_name} = $t->name if $t->can( "name" );
Branch: 1 branch
BranchTrueFalseTotal
if $t->can("name") 0 3 3
733
734 1 ▶ $opts{coercion} = sub { $t->coerce( @_ ? @_ : $_ ) }
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 1 0 1
735 3 ▶ if $t->can( "has_coercion" )
Branch: 1 branch
BranchTrueFalseTotal
if $t->can("has_coercion") and $t->has_coercion and $t->can("coerce") 1 2 3
Condition66%4/6
$t->can("has_coercion") and $t->has_coercion and $t->can("coerce")
!ll&&!rl&&r
201
$t->can("has_coercion") and $t->has_coercion
!ll&&!rl&&r
201
MC/DC33%1/3
$t->can("has_coercion") and $t->has_coercion and $t->can("coerce")
$t->can("has_coercion") $t->has_coercion $t->can("coerce")
Truth table50%2/4
A and B and C
A= $t->can("has_coercion")B= $t->has_coercionC= $t->can("coerce")
ABCresult
0XX0
10X0
1100
1111
736 && $t->has_coercion
737 && $t->can( "coerce" );
738
739 3 ▶ if ( $t->can( 'can_be_inlined' )
Branch: 1 branch
BranchTrueFalseTotal
if ($t->can("can_be_inlined") and $t->can_be_inlined and $t->can("inline_check")) 0 3 3
Condition33%2/6
$t->can("can_be_inlined") and $t->can_be_inlined and $t->can("inline_check")
!ll&&!rl&&r
300
$t->can("can_be_inlined") and $t->can_be_inlined
!ll&&!rl&&r
300
MC/DC0%0/3
$t->can("can_be_inlined") and $t->can_be_inlined and $t->can("inline_check")
$t->can("can_be_inlined") $t->can_be_inlined $t->can("inline_check")
Truth table25%1/4
A and B and C
A= $t->can("can_be_inlined")B= $t->can_be_inlinedC= $t->can("inline_check")
ABCresult
0XX0
10X0
1100
1111
740 && $t->can_be_inlined
741 && $t->can( 'inline_check' ) )
742 {
743 0 ▶ $opts{inlined} = sub { $t->inline_check( $_[1] ) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
744 }
745
746 3 require Type::Tiny;
747 3 my $new = "Type::Tiny"->new( %opts );
748 3 $ttt_cache{ refaddr( $t ) } = $new;
749 3 weaken( $ttt_cache{ refaddr( $t ) } );
750 3 return $new;
751 } #/ sub _TypeTinyFromGeneric
752  
753 0 ▶sub _TypeTinyFromMouse {
Subroutine _TypeTinyFromMouse: not called CC=6 SCAR=37.4
754 0 my $t = $_[0];
755
756 my %opts = (
757 0 ▶ constraint => sub { $t->check( @_ ? @_ : $_ ) },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
758 0 ▶ message => sub { $t->get_message( @_ ? @_ : $_ ) },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
759 0 );
760
761 0 ▶ $opts{display_name} = $t->name if $t->can( "name" );
Branch: 1 branch
BranchTrueFalseTotal
if $t->can("name") 0 0 0
762
763 0 ▶ $opts{coercion} = sub { $t->coerce( @_ ? @_ : $_ ) }
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
764 0 ▶ if $t->can( "has_coercion" )
Branch: 1 branch
BranchTrueFalseTotal
if $t->can("has_coercion") and $t->has_coercion and $t->can("coerce") 0 0 0
Condition0%0/6
$t->can("has_coercion") and $t->has_coercion and $t->can("coerce")
!ll&&!rl&&r
000
$t->can("has_coercion") and $t->has_coercion
!ll&&!rl&&r
000
MC/DC0%0/3
$t->can("has_coercion") and $t->has_coercion and $t->can("coerce")
$t->can("has_coercion") $t->has_coercion $t->can("coerce")
Truth table0%0/4
A and B and C
A= $t->can("has_coercion")B= $t->has_coercionC= $t->can("coerce")
ABCresult
0XX0
10X0
1100
1111
765 && $t->has_coercion
766 && $t->can( "coerce" );
767
768 0 ▶ if ( $t->{'constraint_generator'} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($t->{"constraint_generator"}) 0 0 0
769 0 ▶ $opts{constraint_generator} = sub {
Subroutine __ANON__: not called CC=2 SCAR=17.9
770
771 # convert args into Moose native types; not strictly necessary
772 0 ▶ my @args = map { is_TypeTiny( $_ ) ? $_->mouse_type : $_ } @_;
Branch: 1 branch
BranchTrueFalseTotal
is_TypeTiny($_) ? : 0 0 0
773 0 _TypeTinyFromMouse( $t->parameterize( @args ) );
774 0 };
775 }
776
777 0 require Type::Tiny;
778 0 my $new = "Type::Tiny"->new( %opts );
779 0 $ttt_cache{ refaddr( $t ) } = $new;
780 0 weaken( $ttt_cache{ refaddr( $t ) } );
781 0 return $new;
782 } #/ sub _TypeTinyFromMouse
783  
784 my $QFS;
785  
786 40019 ▶sub _TypeTinyFromCodeRef {
Subroutine _TypeTinyFromCodeRef: called CC=7 SCAR=19.9
787 40019 my $t = $_[0];
788
789 my %opts = (
790 93 ▶ constraint => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
791 93 return !!eval { $t->( $_ ) };
792 },
793 2 ▶ message => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
794 2 local $@;
795 2 ▶ eval { $t->( $_ ); 1 } or do { chomp $@; return $@ if $@ };
Branch: 2 branches
BranchTrueFalseTotal
eval { do { &$t($_); 1 } } or do { chomp $@; return $@ if $@ } 1 1 2
if $@ 1 0 1
796 1 return sprintf( '%s did not pass type constraint', Type::Tiny::_dd( $_ ) );
797 },
798 40019 );
799
800 40019 ▶ if ( $QFS ||= "Sub::Quote"->can( "quoted_from_sub" ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($QFS ||= "Sub::Quote"->can("quoted_from_sub")) 1 40018 40019
Condition66%2/3
$QFS ||= "Sub::Quote"->can("quoted_from_sub")
l!l&&r!l&&!r
0140018
MC/DC50%1/2
$QFS ||= "Sub::Quote"->can("quoted_from_sub")
$QFS "Sub::Quote"->can("quoted_from_sub")
Truth table66%2/3
A ||= B
A= $QFSB= "Sub::Quote"->can("quoted_from_sub")
ABresult
1X1
011
000
801 1 ▶ my ( undef, $perlstring, $captures ) = @{ $QFS->( $t ) || [] };
Condition50%1/2
&$QFS($t) || []
l!l
10
MC/DC0%0/1
&$QFS($t) || []
&$QFS($t)
Truth table50%1/2
A
A= &$QFS($t)
Aresult
11
00
802 1 ▶ if ( $perlstring ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($perlstring) 1 0 1
803 1 $perlstring = "!!eval{ $perlstring }";
804 11 ▶ $opts{inlined} = sub {
Subroutine __ANON__: called CC=2 SCAR=7.2
805 11 my $var = $_[1];
806 11 ▶ Sub::Quote::inlinify(
Branch: 1 branch
BranchTrueFalseTotal
$var eq '$_' ? : 0 11 11
807 $perlstring,
808 $var,
809 $var eq q($_) ? '' : "local \$_ = $var;",
810 1,
811 );
812 }
813 1 ▶ if $perlstring && !$captures;
Branch: 1 branch
BranchTrueFalseTotal
if $perlstring and not $captures 1 0 1
Condition33%1/3
$perlstring and not $captures
!ll&&!rl&&r
001
MC/DC0%0/2
$perlstring and not $captures
$perlstring not $captures
Truth table33%1/3
A and not(B)
A= $perlstringB= not $captures
ABresult
0X0
100
111
814 } #/ if ( $perlstring )
815 } #/ if ( $QFS ||= "Sub::Quote"...)
816
817 40019 require Type::Tiny;
818 40019 my $new = "Type::Tiny"->new( %opts );
819 40019 $ttt_cache{ refaddr( $t ) } = $new;
820 40019 weaken( $ttt_cache{ refaddr( $t ) } );
821 40019 return $new;
822 } #/ sub _TypeTinyFromCodeRef
823  
824 304 1;
825  
826 __END__
« blib/lib/Eval/TypeTiny.pm ↑ Summary lib/Types/Standard/Tuple.pm »