blib/lib/Type/Tiny.pm

filter: Statementstmt 92.2% 755 / 821 (4 uncoverable) Branchbran 78.7% 414 / 526 Conditioncond 68.2% 217 / 318 MC/DCmcdc 38.6% 75 / 194 Subroutinesub 91.0% 172 / 189 Podpod 98.8% 86 / 87 totaltotal 80.6% 1719 / 2135 (4 uncoverable) CC 395 SCAR 24.9
CC
395
Cov
83%
_build_moose_type
90.0
isa
56.6
_build_mouse_type
56.0
CRAP 12.1
« lib/Types/Standard/Tuple.pm ↑ Summary lib/Types/Standard/Dict.pm »
1 package Type::Tiny;
2  
3 303 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 303 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 303 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 303 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=9.2
8 0 ▶ if ( $] < 5.010 ) { require Devel::TypeTiny::Perl58Compat }
Branch: 1 branch
BranchTrueFalseTotal
if ($] < "5.01") 0 303 303
9 }
10  
11 303 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
12 303 $Type::Tiny::AUTHORITY = 'cpan:TOBYINK';
13 303 $Type::Tiny::VERSION = '2.010001';
14 303 $Type::Tiny::XS_VERSION = '0.016';
15 }
16  
17 303 $Type::Tiny::VERSION =~ tr/_//d;
18 303 $Type::Tiny::XS_VERSION =~ tr/_//d;
19  
20 303 our @InternalPackages = qw(
21 Devel::TypeTiny::Perl56Compat
22 Devel::TypeTiny::Perl58Compat
23 Error::TypeTiny
24 Error::TypeTiny::Assertion
25 Error::TypeTiny::Compilation
26 Error::TypeTiny::WrongNumberOfParameters
27 Eval::TypeTiny
28 Eval::TypeTiny::CodeAccumulator
29 Eval::TypeTiny::Sandbox
30 Exporter::Tiny
31 Reply::Plugin::TypeTiny
32 Test::TypeTiny
33 Type::Coercion
34 Type::Coercion::FromMoose
35 Type::Coercion::Union
36 Type::Library
37 Type::Params
38 Type::Params::Alternatives
39 Type::Params::Parameter
40 Type::Params::Signature
41 Type::Parser
42 Type::Parser::AstBuilder
43 Type::Parser::Token
44 Type::Parser::TokenStream
45 Type::Registry
46 Types::Common
47 Types::Common::Numeric
48 Types::Common::String
49 Types::Standard
50 Types::Standard::_Stringable
51 Types::Standard::ArrayRef
52 Types::Standard::CycleTuple
53 Types::Standard::Dict
54 Types::Standard::HashRef
55 Types::Standard::Map
56 Types::Standard::ScalarRef
57 Types::Standard::StrMatch
58 Types::Standard::Tied
59 Types::Standard::Tuple
60 Types::TypeTiny
61 Type::Tie
62 Type::Tie::ARRAY
63 Type::Tie::BASE
64 Type::Tie::HASH
65 Type::Tie::SCALAR
66 Type::Tiny
67 Type::Tiny::_DeclaredType
68 Type::Tiny::_HalfOp
69 Type::Tiny::Bitfield
70 Type::Tiny::Class
71 Type::Tiny::ConstrainedObject
72 Type::Tiny::Duck
73 Type::Tiny::Enum
74 Type::Tiny::Intersection
75 Type::Tiny::Role
76 Type::Tiny::Union
77 Type::Utils
78 );
79  
80 303 ▶use Scalar::Util qw( blessed );
Subroutine BEGIN: called CC=1 SCAR=0.0
81 303 ▶use Types::TypeTiny ();
Subroutine BEGIN: called CC=1 SCAR=0.0
82  
83 303 our $SafePackage = sprintf 'package %s;', __PACKAGE__;
84  
85 15 ▶sub _croak ($;@) { require Error::TypeTiny; goto \&Error::TypeTiny::croak }
Subroutine _croak: called CC=1 SCAR=0.0
86  
87 40150 ▶sub _swap { $_[2] ? @_[ 1, 0 ] : @_[ 0, 1 ] }
Subroutine _swap: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$_[2] ? : 0 40150 40150
88  
89 303 ▶BEGIN {
Subroutine BEGIN: called CC=10 SCAR=23.2
90 303 ▶ my $support_smartmatch = 0+ !!( $] >= 5.010001 && $] <= 5.041002 );
Condition33%1/3
$] >= 5.010001 && $] <= 5.041002
!ll&&!rl&&r
03030
MC/DC0%0/2
$] >= 5.010001 && $] <= 5.041002
$] >= 5.010001 $] <= 5.041002
Truth table33%1/3
A && B
A= $] >= 5.010001B= $] <= 5.041002
ABresult
0X0
100
111
91 303 eval qq{ sub SUPPORT_SMARTMATCH () { !! $support_smartmatch } };
92
93 303 my $fixed_precedence = 0+ !!( $] >= 5.014 );
94 303 eval qq{ sub _FIXED_PRECEDENCE () { !! $fixed_precedence } };
95
96 my $try_xs =
97 exists( $ENV{PERL_TYPE_TINY_XS} ) ? !!$ENV{PERL_TYPE_TINY_XS}
98 : exists( $ENV{PERL_ONLY} ) ? !$ENV{PERL_ONLY}
99 303 ▶ : 1;
Branch: 2 branches
BranchTrueFalseTotal
exists $ENV{'PERL_TYPE_TINY_XS'} ? : 2 301 303
exists $ENV{'PERL_ONLY'} ? : 0 301 301
100
101 303 my $use_xs = 0;
102 303 ▶ $try_xs and eval {
Branch: 1 branch
BranchTrueFalseTotal
$try_xs and eval { do { require Type::Tiny::XS; "Type::Tiny::XS"->VERSION($Type::Tiny::XS_VERSION); ++$use_xs } } 301 2 303
103 301 require Type::Tiny::XS;
104 301 'Type::Tiny::XS'->VERSION( $Type::Tiny::XS_VERSION );
105 301 $use_xs++;
106 };
107
108 *_USE_XS =
109 $use_xs
110 ? sub () { !!1 }
111 303 ▶ : sub () { !!0 };
Branch: 1 branch
BranchTrueFalseTotal
$use_xs ? : 301 2 303
112
113 *_USE_MOUSE =
114 $try_xs
115 281 ▶ ? sub () { $INC{'Mouse/Util.pm'} and Mouse::Util::MOUSE_XS() }
Subroutine __ANON__: called CC=2 SCAR=7.6
Branch: 1 branch
BranchTrueFalseTotal
$INC{"Mouse/Util.pm"} and Mouse::Util::MOUSE_XS() 0 281 281
116 303 ▶ : sub () { !!0 };
Branch: 1 branch
BranchTrueFalseTotal
$try_xs ? : 301 2 303
117
118 303 my $strict_mode = 0;
119 303 ▶ $ENV{$_} && ++$strict_mode for qw(
Branch: 1 branch
BranchTrueFalseTotal
$ENV{$_} and ++$strict_mode 300 912 1212
120 EXTENDED_TESTING
121 AUTHOR_TESTING
122 RELEASE_TESTING
123 PERL_STRICT
124 );
125 303 ▶ *_STRICT_MODE = $strict_mode ? sub () { !!1 } : sub () { !!0 };
Branch: 1 branch
BranchTrueFalseTotal
$strict_mode ? : 300 3 303
126 } #/ BEGIN
127  
128 {
129  
130 1615 ▶ sub _install_overloads {
Subroutine _install_overloads: called CC=4 SCAR=13.9
131 303 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
132 303 ▶ no warnings 'redefine', 'once';
Subroutine BEGIN: called CC=1 SCAR=0.0
133
134 # Coverage is checked on Perl 5.26
135 1615 ▶ if ( $] < 5.010 ) { # uncoverable statement
Branch: 1 branch
BranchTrueFalseTotal
if ($] < "5.01") 0 1615 1615
136 0 require overload; # uncoverable statement
137 0 push @_, fallback => 1; # uncoverable statement
138 0 goto \&overload::OVERLOAD; # uncoverable statement
139 }
140
141 1615 my $class = shift;
142 1615 ▶ *{ $class . '::((' } = sub { };
Subroutine __ANON__: not called CC=1 SCAR=0.0
143 1615 ▶ *{ $class . '::()' } = sub { };
Subroutine __ANON__: not called CC=1 SCAR=0.0
144 1615 *{ $class . '::()' } = do { my $x = 1; \$x };
145 1615 ▶ while ( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 7100 1615 8715
146 7100 my $f = shift;
147 7100 ▶ *{ $class . '::(' . $f } = ref $_[0] ? shift : do {
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] ? : 6431 669 7100
148 669 my $m = shift;
149 848 ▶ sub { shift->$m( @_ ) }
Subroutine __ANON__: called CC=1 SCAR=0.0
150 669 };
151 }
152 } #/ sub _install_overloads
153 }
154  
155 303 __PACKAGE__->_install_overloads(
156 49916 ▶ q("") => sub {
Subroutine __ANON__: called CC=2 SCAR=7.6
157 49916 ▶ caller =~ m{^(Moo::HandleMoose|Sub::Quote)}
Branch: 1 branch
BranchTrueFalseTotal
(caller) =~ /^(Moo::HandleMoose|Sub::Quote)/ ? : 0 49916 49916
158 ? $_[0]->_stringify_no_magic
159 : $_[0]->display_name;
160 },
161 23619 ▶ q(bool) => sub { 1 },
Subroutine __ANON__: called CC=1 SCAR=0.0
162 q(&{}) => "_overload_coderef",
163 60 ▶ q(|) => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
164 60 my @tc = _swap @_;
165 60 if ( !_FIXED_PRECEDENCE && $_[2] ) {
166 if ( blessed $tc[0] ) {
167 if ( blessed $tc[0] eq "Type::Tiny::_HalfOp" ) {
168 my $type = $tc[0]->{type};
169 my $param = $tc[0]->{param};
170 my $op = $tc[0]->{op};
171 require Type::Tiny::Union;
172 return "Type::Tiny::_HalfOp"->new(
173 $op,
174 $param,
175 "Type::Tiny::Union"->new_by_overload( type_constraints => [ $type, $tc[1] ] ),
176 );
177 } #/ if ( blessed $tc[0] eq...)
178 } #/ if ( blessed $tc[0] )
179 elsif ( ref $tc[0] eq 'ARRAY' ) {
180 require Type::Tiny::_HalfOp;
181 return "Type::Tiny::_HalfOp"->new( '|', @tc );
182 }
183 } #/ if ( !_FIXED_PRECEDENCE...)
184 60 require Type::Tiny::Union;
185 60 return "Type::Tiny::Union"->new_by_overload( type_constraints => \@tc );
186 },
187 40060 ▶ q(&) => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
188 40060 my @tc = _swap @_;
189 40060 if ( !_FIXED_PRECEDENCE && $_[2] ) {
190 if ( blessed $tc[0] ) {
191 if ( blessed $tc[0] eq "Type::Tiny::_HalfOp" ) {
192 my $type = $tc[0]->{type};
193 my $param = $tc[0]->{param};
194 my $op = $tc[0]->{op};
195 require Type::Tiny::Intersection;
196 return "Type::Tiny::_HalfOp"->new(
197 $op,
198 $param,
199 "Type::Tiny::Intersection"->new_by_overload( type_constraints => [ $type, $tc[1] ] ),
200 );
201 } #/ if ( blessed $tc[0] eq...)
202 } #/ if ( blessed $tc[0] )
203 elsif ( ref $tc[0] eq 'ARRAY' ) {
204 require Type::Tiny::_HalfOp;
205 return "Type::Tiny::_HalfOp"->new( '&', @tc );
206 }
207 } #/ if ( !_FIXED_PRECEDENCE...)
208 40060 require Type::Tiny::Intersection;
209 40060 "Type::Tiny::Intersection"->new_by_overload( type_constraints => \@tc );
210 },
211 74 ▶ q(~) => sub { shift->complementary_type },
Subroutine __ANON__: called CC=1 SCAR=0.0
212 715 ▶ q(==) => sub { $_[0]->equals( $_[1] ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
213 1 ▶ q(!=) => sub { not $_[0]->equals( $_[1] ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
214 8 ▶ q(<) => sub { my $m = $_[0]->can( 'is_subtype_of' ); $m->( _swap @_ ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
215 10 ▶ q(>) => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
216 10 my $m = $_[0]->can( 'is_subtype_of' );
217 10 $m->( reverse _swap @_ );
218 },
219 6 ▶ q(<=) => sub { my $m = $_[0]->can( 'is_a_type_of' ); $m->( _swap @_ ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
220 6 ▶ q(>=) => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
221 6 my $m = $_[0]->can( 'is_a_type_of' );
222 6 $m->( reverse _swap @_ );
223 },
224 41 ▶ q(eq) => sub { "$_[0]" eq "$_[1]" },
Subroutine __ANON__: called CC=1 SCAR=0.0
225 0 ▶ q(cmp) => sub { $_[2] ? ( "$_[1]" cmp "$_[0]" ) : ( "$_[0]" cmp "$_[1]" ) },
Subroutine __ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
BranchTrueFalseTotal
$_[2] ? : 0 0 0
226 1 ▶ q(0+) => sub { $_[0]{uniq} },
Subroutine __ANON__: called CC=1 SCAR=0.0
227 4 ▶ q(/) => sub { ( _STRICT_MODE xor $_[2] ) ? $_[0] : $_[1] },
Subroutine __ANON__: called CC=3 SCAR=11.7
Branch: 1 branch
BranchTrueFalseTotal
!0 ^^ $_[2] ? : 2 2 4
Condition50%2/4
xor $_[2]
l&&rl&&!r!l&&r!l&&!r
0202
MC/DC50%1/2
xor $_[2]
$_[2]
Truth table50%2/4
A xor B
A= B= $_[2]
ABresult
110
101
011
000
228 303 );
229  
230 __PACKAGE__->_install_overloads(
231 0 ▶ q(~~) => sub { $_[0]->check( $_[1] ) },
Subroutine __ANON__: not called CC=1 SCAR=6.9
232 303 ) if Type::Tiny::SUPPORT_SMARTMATCH;
233  
234 # Would be easy to just return sub { $self->assert_return(@_) }
235 # but try to build a more efficient coderef whenever possible.
236 #
237 14671 ▶sub _overload_coderef {
Subroutine _overload_coderef: called CC=9 SCAR=22.0
238 14671 my $self = shift;
239
240 # Bypass generating a coderef if we've already got the best possible one.
241 #
242 14671 ▶ return $self->{_overload_coderef} if $self->{_overload_coderef_no_rebuild};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_overload_coderef_no_rebuild"} 19 14652 14671
243
244 # Subclasses of Type::Tiny might override assert_return to do some kind
245 # of interesting thing. In that case, we can't rely on it having identical
246 # behaviour to Type::Tiny::inline_assert.
247 #
248 $self->{_overrides_assert_return} =
249 ( $self->can( 'assert_return' ) != \&assert_return )
250 14652 ▶ unless exists $self->{_overrides_assert_return};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"_overrides_assert_return"} 12231 2421 14652
251
252 14652 ▶ if ( $self->{_overrides_assert_return} ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'_overrides_assert_return'}) { } 1 14651 14652
elsif (exists &Sub::Quote::quote_sub) { } 162 14489 14651
253 1 ▶ $self->{_overload_coderef} ||= do {
Condition33%1/3
$self->{"_overload_coderef"} ||= do { builtin::weaken(my $weak = $self); sub { $weak->assert_return(@_); } }
l!l&&r!l&&!r
010
MC/DC0%0/2
$self->{"_overload_coderef"} ||= do { builtin::weaken(my $weak = $self); sub { $weak->assert_return(@_); } }
$self->{"_overload_coderef"} do { builtin::weaken(my $weak = $self); sub { $weak->assert_return(@_); } }
Truth table33%1/3
A ||= B
A= $self->{"_overload_coderef"}B= do { builtin::weaken(my $weak = $self); sub { $weak->assert_return(@_); } }
ABresult
1X1
011
000
254 1 Scalar::Util::weaken( my $weak = $self );
255 1 ▶ sub { $weak->assert_return( @_ ) };
Subroutine __ANON__: called CC=1 SCAR=0.0
256 };
257 1 ++$self->{_overload_coderef_no_rebuild};
258 }
259 elsif ( exists( &Sub::Quote::quote_sub ) ) {
260
261 # Use `=` instead of `||=` because we want to overwrite non-Sub::Quote
262 # coderef if possible.
263 162 ▶ $self->{_overload_coderef} = $self->can_be_inlined
Branch: 1 branch
BranchTrueFalseTotal
$self->can_be_inlined ? : 155 7 162
264 ? Sub::Quote::quote_sub(
265 $self->inline_assert( '$_[0]' ),
266 )
267 : Sub::Quote::quote_sub(
268 $self->inline_assert( '$_[0]', '$type' ),
269 { '$type' => \$self },
270 );
271 162 ++$self->{_overload_coderef_no_rebuild};
272 } #/ elsif ( exists( &Sub::Quote::quote_sub...))
273 else {
274 14489 require Eval::TypeTiny;
275 14489 ▶ $self->{_overload_coderef} ||= $self->can_be_inlined
Branch: 1 branch
BranchTrueFalseTotal
$self->can_be_inlined ? : 11988 88 12076
Condition66%2/3
$self->{"_overload_coderef"} ||= $self->can_be_inlined ? Eval::TypeTiny::eval_closure("source", sprintf("sub { %s }", $self->inline_assert("\$_[0]", undef, "no_wrapper", 1)), "description", sprintf(q[compiled assertion 'assert_%s'], $self)) : Eval::TypeTiny::eval_closure("source", sprintf("sub { %s }", $self->inline_assert("\$_[0]", "\$type", "no_wrapper", 1)), "description", sprintf(q[compiled assertion 'assert_%s'], $self), "environment", {"\$type", \$self})
l!l&&r!l&&!r
2413120760
MC/DC0%0/2
$self->{"_overload_coderef"} ||= $self->can_be_inlined ? Eval::TypeTiny::eval_closure("source", sprintf("sub { %s }", $self->inline_assert("\$_[0]", undef, "no_wrapper", 1)), "description", sprintf(q[compiled assertion 'assert_%s'], $self)) : Eval::TypeTiny::eval_closure("source", sprintf("sub { %s }", $self->inline_assert("\$_[0]", "\$type", "no_wrapper", 1)), "description", sprintf(q[compiled assertion 'assert_%s'], $self), "environment", {"\$type", \$self})
$self->{"_overload_coderef"} $self->can_be_inlined ? Eval::TypeTiny::eval_closure("source", sprintf("sub { %s }", $self->inline_assert("\$_[0]", undef, "no_wrapper", 1)), "description", sprintf(q[compiled assertion 'assert_%s'], $self)) : Eval::TypeTiny::eval_closure("source", sprintf("sub { %s }", $self->inline_assert("\$_[0]", "\$type", "no_wrapper", 1)), "description", sprintf(q[compiled assertion 'assert_%s'], $self), "environment", {"\$type", \$self})
Truth table66%2/3
A ||= B
A= $self->{"_overload_coderef"}B= $self->can_be_inlined ? Eval::TypeTiny::eval_closure("source", sprintf("sub { %s }", $self->inline_assert("\$_[0]", undef, "no_wrapper", 1)), "description", sprintf(q[compiled assertion 'assert_%s'], $self)) : Eval::TypeTiny::eval_closure("source", sprintf("sub { %s }", $self->inline_assert("\$_[0]", "\$type", "no_wrapper", 1)), "description", sprintf(q[compiled assertion 'assert_%s'], $self), "environment", {"\$type", \$self})
ABresult
1X1
011
000
276 ? Eval::TypeTiny::eval_closure(
277 source => sprintf(
278 'sub { %s }', $self->inline_assert( '$_[0]', undef, no_wrapper => 1 )
279 ),
280 description => sprintf( "compiled assertion 'assert_%s'", $self ),
281 )
282 : Eval::TypeTiny::eval_closure(
283 source => sprintf(
284 'sub { %s }', $self->inline_assert( '$_[0]', '$type', no_wrapper => 1 )
285 ),
286 description => sprintf( "compiled assertion 'assert_%s'", $self ),
287 environment => { '$type' => \$self },
288 );
289 } #/ else [ if ( $self->{_overrides_assert_return...})]
290
291 14652 $self->{_overload_coderef};
292 } #/ sub _overload_coderef
293  
294 303 our %ALL_TYPES;
295  
296 303 my $QFS;
297 303 my $uniq = 1;
298  
299 95461 ▶sub new {
Subroutine new: called CC=44 SCAR=38.3
Pod documented
300 95461 my $class = shift;
301 0 ▶ my %params = ( @_ == 1 ) ? %{ $_[0] } : @_;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 1 ? : 0 95461 95461
302
303 95461 for ( qw/ name display_name library / ) {
304 286383 ▶ $params{$_} = $params{$_} . '' if defined $params{$_};
Branch: 1 branch
BranchTrueFalseTotal
if defined $params{$_} 27695 258688 286383
305 }
306
307 95461 my $level = 0;
308 95461 ▶ while ( not exists $params{definition_context} and $level < 20 ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $params{"definition_context"} and $level < 20) 234222 95461 329683
Condition66%2/3
not exists $params{"definition_context"} and $level < 20
!ll&&!rl&&r
954610234222
MC/DC50%1/2
not exists $params{"definition_context"} and $level < 20
not exists $params{"definition_context"} $level < 20
Truth table66%2/3
not(A) and B
A= not exists $params{"definition_context"}B= $level < 20
ABresult
0X0
100
111
309 234222 ▶ our $_TT_GUTS ||= do {
Condition66%2/3
our $_TT_GUTS ||= do { my $g = join("|", map(quotemeta($_), grep((!/^Types::/), @Type::Tiny::InternalPackages))); qr/\A(?:$g)\z/o }
l!l&&r!l&&!r
2339322900
MC/DC0%0/2
our $_TT_GUTS ||= do { my $g = join("|", map(quotemeta($_), grep((!/^Types::/), @Type::Tiny::InternalPackages))); qr/\A(?:$g)\z/o }
our $_TT_GUTS do { my $g = join("|", map(quotemeta($_), grep((!/^Types::/), @Type::Tiny::InternalPackages))); qr/\A(?:$g)\z/o }
Truth table66%2/3
A ||= B
A= our $_TT_GUTSB= do { my $g = join("|", map(quotemeta($_), grep((!/^Types::/), @Type::Tiny::InternalPackages))); qr/\A(?:$g)\z/o }
ABresult
1X1
011
000
310 290 my $g = join '|', map quotemeta, grep !m{^Types::}, @InternalPackages;
311 290 qr/\A(?:$g)\z/o
312 };
313 234222 my $package = caller $level;
314 234222 ▶ if ( $package !~ $_TT_GUTS ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($package =~ /$Type::Tiny::_TT_GUTS/) 95461 138761 234222
315 95461 @{ $params{definition_context} = {} }{ qw/ package file line / } = caller $level;
316 }
317 234222 ++$level;
318 }
319
320 95461 ▶ if ( exists $params{parent} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $params{"parent"}) 12443 83018 95461
321 $params{parent} =
322 ref( $params{parent} ) =~ /^Type::Tiny\b/
323 ? $params{parent}
324 12443 ▶ : Types::TypeTiny::to_TypeTiny( $params{parent} );
Branch: 1 branch
BranchTrueFalseTotal
ref($params{'parent'}) =~ /^Type::Tiny\b/ ? : 12443 0 12443
325
326 _croak "Parent must be an instance of %s", __PACKAGE__
327 unless blessed( $params{parent} )
328 12443 ▶ && $params{parent}->isa( __PACKAGE__ );
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($params{"parent"}) and $params{"parent"}->isa(__PACKAGE__) 0 12443 12443
Condition33%1/3
builtin::blessed($params{"parent"}) and $params{"parent"}->isa(__PACKAGE__)
!ll&&!rl&&r
0012443
MC/DC0%0/2
builtin::blessed($params{"parent"}) and $params{"parent"}->isa(__PACKAGE__)
builtin::blessed($params{"parent"}) $params{"parent"}->isa(__PACKAGE__)
Truth table33%1/3
A and B
A= builtin::blessed($params{"parent"})B= $params{"parent"}->isa(__PACKAGE__)
ABresult
0X0
100
111
329
330 12443 ▶ if ( $params{parent}->deprecated and not exists $params{deprecated} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params{"parent"}->deprecated and not exists $params{"deprecated"}) 3 12440 12443
Condition100%3/3
$params{"parent"}->deprecated and not exists $params{"deprecated"}
!ll&&!rl&&r
1243733
MC/DC100%2/2
$params{"parent"}->deprecated and not exists $params{"deprecated"}
$params{"parent"}->deprecated not exists $params{"deprecated"}
Truth table100%3/3
A and not(B)
A= $params{"parent"}->deprecatedB= not exists $params{"deprecated"}
ABresult
0X0
100
111
331 3 $params{deprecated} = 1;
332 }
333 } #/ if ( exists $params{parent...})
334
335 95461 ▶ if ( exists $params{constraint}
Branch: 1 branch
BranchTrueFalseTotal
if (exists $params{"constraint"} and defined $params{"constraint"} and not ref $params{"constraint"}) 83 95378 95461
Condition83%5/6
exists $params{"constraint"} and defined $params{"constraint"} and not ref $params{"constraint"}
!ll&&!rl&&r
452785010083
exists $params{"constraint"} and defined $params{"constraint"}
!ll&&!rl&&r
45278050183
MC/DC66%2/3
exists $params{"constraint"} and defined $params{"constraint"} and not ref $params{"constraint"}
exists $params{"constraint"} defined $params{"constraint"} not ref $params{"constraint"}
Truth table75%3/4
A and B and not(C)
A= exists $params{"constraint"}B= defined $params{"constraint"}C= not ref $params{"constraint"}
ABCresult
0XX0
10X0
1100
1111
336 and defined $params{constraint}
337 and not ref $params{constraint} )
338 {
339 83 require Eval::TypeTiny;
340 83 my $code = $params{constraint};
341 83 $params{constraint} = Eval::TypeTiny::eval_closure(
342 source => sprintf( 'sub ($) { %s }', $code ),
343 description => "anonymous check",
344 );
345 278 ▶ $params{inlined} ||= sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
346 278 my ( $type ) = @_;
347 278 ▶ my $inlined = $_ eq '$_' ? "do { $code }" : "do { local \$_ = $_; $code }";
Branch: 1 branch
BranchTrueFalseTotal
$_ eq '$_' ? : 1 277 278
348 278 ▶ $type->has_parent ? ( undef, $inlined ) : $inlined;
Branch: 1 branch
BranchTrueFalseTotal
$type->has_parent ? : 259 19 278
349 }
350 83 ▶ if ( !exists $params{parent} or $params{parent}->can_be_inlined );
Branch: 1 branch
BranchTrueFalseTotal
if not exists $params{"parent"} or $params{"parent"}->can_be_inlined 83 0 83
Condition50%3/6
not exists $params{"parent"} or $params{"parent"}->can_be_inlined
l!l&&r!l&&!r
3800
$params{"inlined"} ||= sub { my($type) = @_; my $inlined = $_ eq "\$_" ? "do { $code }" : "do { local \$_ = $_; $code }"; $type->has_parent ? (undef, $inlined) : $inlined; }
l!l&&r!l&&!r
0830
MC/DC0%0/2
not exists $params{"parent"} or $params{"parent"}->can_be_inlined
not exists $params{"parent"} $params{"parent"}->can_be_inlined
MC/DC0%0/2
$params{"inlined"} ||= sub { my($type) = @_; my $inlined = $_ eq "\$_" ? "do { $code }" : "do { local \$_ = $_; $code }"; $type->has_parent ? (undef, $inlined) : $inlined; }
$params{"inlined"} sub { my($type) = @_; my $inlined = $_ eq "\$_" ? "do { $code }" : "do { local \$_ = $_; $code }"; $type->has_parent ? (undef, $inlined) : $inlined; }
Truth table66%2/3
not(A) or B
A= not exists $params{"parent"}B= $params{"parent"}->can_be_inlined
ABresult
1X1
011
000
Truth table33%1/3
A ||= B
A= $params{"inlined"}B= sub { my($type) = @_; my $inlined = $_ eq "\$_" ? "do { $code }" : "do { local \$_ = $_; $code }"; $type->has_parent ? (undef, $inlined) : $inlined; }
ABresult
1X1
011
000
351 } #/ if ( exists $params{constraint...})
352
353 # canonicalize to a boolean
354 95461 $params{deprecated} = !!$params{deprecated};
355
356 95461 ▶ $params{name} = "__ANON__" unless exists $params{name};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $params{"name"} 82519 12942 95461
357 95461 $params{uniq} = $uniq++;
358
359 95461 ▶ if ( $params{name} ne "__ANON__" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params{"name"} ne "__ANON__") 12916 82545 95461
360
361 # First try a fast ASCII-only expression, but fall back to Unicode
362 $params{name} =~ /^_{0,2}[A-Z][A-Za-z0-9_]+$/sm
363 or eval q( use 5.008; $params{name} =~ /^_{0,2}\p{Lu}[\p{L}0-9_]+$/sm )
364 12916 ▶ or _croak '"%s" is not a valid type name', $params{name};
Branch: 1 branch
BranchTrueFalseTotal
$params{"name"} =~ /^_{0,2}[A-Z][A-Za-z0-9_]+$/ms or eval " use 5.008; \$params{name} =~ /^_{0,2}\\p{Lu}[\\p{L}0-9_]+\$/sm " or &_croak("\"%s\" is not a valid type name", $params{"name"}) 12915 1 12916
Condition66%2/3
$params{"name"} =~ /^_{0,2}[A-Z][A-Za-z0-9_]+$/ms or eval " use 5.008; \$params{name} =~ /^_{0,2}\\p{Lu}[\\p{L}0-9_]+\$/sm "
l!l&&r!l&&!r
1291501
MC/DC50%1/2
$params{"name"} =~ /^_{0,2}[A-Z][A-Za-z0-9_]+$/ms or eval " use 5.008; \$params{name} =~ /^_{0,2}\\p{Lu}[\\p{L}0-9_]+\$/sm "
$params{"name"} =~ /^_{0,2}[A-Z][A-Za-z0-9_]+$/ms eval " use 5.008; \$params{name} =~ /^_{0,2}\\p{Lu}[\\p{L}0-9_]+\$/sm "
Truth table66%2/3
A or B
A= $params{"name"} =~ /^_{0,2}[A-Z][A-Za-z0-9_]+$/msB= eval " use 5.008; \$params{name} =~ /^_{0,2}\\p{Lu}[\\p{L}0-9_]+\$/sm "
ABresult
1X1
011
000
365 }
366
367 95460 ▶ if ( exists $params{coercion} and !ref $params{coercion} and $params{coercion} )
Branch: 1 branch
BranchTrueFalseTotal
if (exists $params{"coercion"} and not ref $params{"coercion"} and $params{"coercion"}) 2 95458 95460
Condition100%6/6
exists $params{"coercion"} and not ref $params{"coercion"} and $params{"coercion"}
!ll&&!rl&&r
9545442
exists $params{"coercion"} and not ref $params{"coercion"}
!ll&&!rl&&r
9544956
MC/DC100%3/3
exists $params{"coercion"} and not ref $params{"coercion"} and $params{"coercion"}
exists $params{"coercion"} not ref $params{"coercion"} $params{"coercion"}
Truth table100%4/4
A and not(B) and C
A= exists $params{"coercion"}B= not ref $params{"coercion"}C= $params{"coercion"}
ABCresult
0XX0
10X0
1100
1111
368 {
369 $params{parent}->has_coercion
370 2 ▶ or _croak
Branch: 1 branch
BranchTrueFalseTotal
$params{"parent"}->has_coercion or &_croak("coercion => 1 requires type to have a direct parent with a coercion") 2 0 2
371 "coercion => 1 requires type to have a direct parent with a coercion";
372
373 2 $params{coercion} = $params{parent}->coercion->type_coercion_map;
374 }
375
376 95460 ▶ if ( !exists $params{inlined}
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $params{"inlined"} and exists $params{"constraint"} and !exists $params{"parent"} || $params{"parent"}->can_be_inlined and $QFS ||= "Sub::Quote"->can("quoted_from_sub")) 6 95454 95460
Condition100%15/15
not exists $params{"inlined"} and exists $params{"constraint"} and !exists $params{"parent"} || $params{"parent"}->can_be_inlined and $QFS ||= "Sub::Quote"->can("quoted_from_sub")
!ll&&!rl&&r
55268401866
not exists $params{"inlined"} and exists $params{"constraint"} and !exists $params{"parent"} || $params{"parent"}->can_be_inlined
!ll&&!rl&&r
551937540192
not exists $params{"inlined"} and exists $params{"constraint"}
!ll&&!rl&&r
104644472940267
not exists $params{"parent"} or $params{"parent"}->can_be_inlined
l!l&&r!l&&!r
4005513775
$QFS ||= "Sub::Quote"->can("quoted_from_sub")
l!l&&r!l&&!r
5140186
MC/DC0%0/6
not exists $params{"inlined"} and exists $params{"constraint"} and !exists $params{"parent"} || $params{"parent"}->can_be_inlined and $QFS ||= "Sub::Quote"->can("quoted_from_sub")
not exists $params{"inlined"} exists $params{"constraint"} not exists $params{"parent"} $params{"parent"}->can_be_inlined $QFS "Sub::Quote"->can("quoted_from_sub")
Truth table0%0/9
not(A) and B and not(C) or D and E ||= F
A= not exists $params{"inlined"}B= exists $params{"constraint"}C= not exists $params{"parent"}D= $params{"parent"}->can_be_inlinedE= $QFSF= "Sub::Quote"->can("quoted_from_sub")
ABCDEFresult
0XXXXX0
10XXXX0
1100XX0
111X000
1101000
111X1X1
111X011
11011X1
1101011
377 and exists $params{constraint}
378 and ( !exists $params{parent} or $params{parent}->can_be_inlined )
379 and $QFS ||= "Sub::Quote"->can( "quoted_from_sub" ) )
380 {
381 6 ▶ my ( undef, $perlstring, $captures ) = @{ $QFS->( $params{constraint} ) || [] };
Condition100%2/2
&$QFS($params{'constraint'}) || []
l!l
51
MC/DC100%1/1
&$QFS($params{'constraint'}) || []
&$QFS($params{'constraint'})
Truth table100%2/2
A
A= &$QFS($params{'constraint'})
Aresult
11
00
382
383 28 ▶ $params{inlined} = sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
384 28 my ( $self, $var ) = @_;
385 28 ▶ my $code = Sub::Quote::inlinify(
Branch: 1 branch
BranchTrueFalseTotal
$var eq '$_' ? : 0 28 28
386 $perlstring,
387 $var,
388 $var eq q($_) ? '' : "local \$_ = $var;",
389 1,
390 );
391 28 ▶ $code = sprintf( '%s and %s', $self->parent->inline_check( $var ), $code )
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_parent 10 18 28
392 if $self->has_parent;
393 28 return $code;
394 }
395 6 ▶ if $perlstring && !$captures;
Branch: 1 branch
BranchTrueFalseTotal
if $perlstring and not $captures 4 2 6
Condition100%3/3
$perlstring and not $captures
!ll&&!rl&&r
114
MC/DC100%2/2
$perlstring and not $captures
$perlstring not $captures
Truth table100%3/3
A and not(B)
A= $perlstringB= not $captures
ABresult
0X0
100
111
396 } #/ if ( !exists $params{inlined...})
397
398 95460 my $self = bless \%params, $class;
399
400 95460 ▶ unless ( $params{tmp} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($params{"tmp"}) 95402 58 95460
401 95402 my $uniq = $self->{uniq};
402
403 95402 $ALL_TYPES{$uniq} = $self;
404 95402 Scalar::Util::weaken( $ALL_TYPES{$uniq} );
405
406 95402 my $tmp = $self;
407 95402 Scalar::Util::weaken( $tmp );
408 0 ▶ $Moo::HandleMoose::TYPE_MAP{ $self->_stringify_no_magic } = sub { $tmp };
Subroutine __ANON__: not called CC=1 SCAR=1.2
409 } #/ unless ( $params{tmp} )
410
411 95460 ▶ if ( ref( $params{coercion} ) eq q(CODE) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $params{'coercion'} eq 'CODE') { } 2 95458 95460
elsif (ref $params{'coercion'} eq 'ARRAY') { } 5 95453 95458
412 2 require Types::Standard;
413 2 my $code = delete( $params{coercion} );
414 2 $self->{coercion} = $self->_build_coercion;
415 2 $self->coercion->add_type_coercions( Types::Standard::Any(), $code );
416 }
417 elsif ( ref( $params{coercion} ) eq q(ARRAY) ) {
418 5 my $arr = delete( $params{coercion} );
419 5 $self->{coercion} = $self->_build_coercion;
420 5 $self->coercion->add_type_coercions( @$arr );
421 }
422
423 # Documenting this here because it's too weird to be in the pod.
424 # There's a secret attribute called "_build_coercion" which takes a
425 # coderef. If present, then when $type->coercion is lazy built,
426 # the blank Type::Coercion object gets passed to the coderef,
427 # allowing the coderef to manipulate it a little. This is used by
428 # Types::TypeTiny to allow it to build a coercion for the TypeTiny
429 # type constraint without needing to load Type::Coercion yet.
430
431 95460 ▶ if ( $params{my_methods} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($params{"my_methods"}) 1097 94363 95460
432 1097 require Eval::TypeTiny;
433 Scalar::Util::reftype( $params{my_methods}{$_} ) eq 'CODE'
434 and /\A[^0-9\W]\w+\z/
435 and Eval::TypeTiny::set_subname(
436 sprintf( "%s::my_%s", $self->qualified_name, $_ ),
437 $params{my_methods}{$_},
438 1097 ▶ ) for keys %{ $params{my_methods} };
Branch: 1 branch
BranchTrueFalseTotal
builtin::reftype($params{"my_methods"}{$_}) eq "CODE" and /\A[^0-9\W]\w+\z/ and &Eval::TypeTiny::set_subname(sprintf("%s::my_%s", $self->qualified_name, $_), $params{"my_methods"}{$_}) 549 1918 2467
Condition66%2/3
builtin::reftype($params{"my_methods"}{$_}) eq "CODE" and /\A[^0-9\W]\w+\z/
!ll&&!rl&&r
19180549
MC/DC50%1/2
builtin::reftype($params{"my_methods"}{$_}) eq "CODE" and /\A[^0-9\W]\w+\z/
builtin::reftype($params{"my_methods"}{$_}) eq "CODE" /\A[^0-9\W]\w+\z/
Truth table66%2/3
A and B
A= builtin::reftype($params{"my_methods"}{$_}) eq "CODE"B= /\A[^0-9\W]\w+\z/
ABresult
0X0
100
111
439 } #/ if ( $params{my_methods...})
440
441 # In general, mutating a type constraint after it's been created
442 # is a bad idea and will probably not work. However some places are
443 # especially harmful and can lead to confusing errors, so allow
444 # subclasses to lock down particular keys.
445 #
446 40517 ▶ $self->_lockdown( sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
447 40517 &Internals::SvREADONLY( $_, !!1 ) for @_;
448 95460 } );
449
450 95460 return $self;
451 } #/ sub new
452  
453 54943 ▶sub _lockdown {}
Subroutine _lockdown: called CC=1 SCAR=0.0
454  
455 81777 ▶sub DESTROY {
Subroutine DESTROY: called CC=1 SCAR=0.0
456 81777 my $self = shift;
457 81777 delete( $ALL_TYPES{ $self->{uniq} } );
458 81777 delete( $Moo::HandleMoose::TYPE_MAP{ $self->_stringify_no_magic } );
459 81777 return;
460 }
461  
462 97 ▶sub _clone {
Subroutine _clone: called CC=2 SCAR=6.9
463 97 my $self = shift;
464 97 my %opts;
465 97 $opts{$_} = $self->{$_} for qw< name display_name message >;
466 97 $self->create_child_type( %opts );
467 }
468  
469 177180 ▶sub _stringify_no_magic {
Subroutine _stringify_no_magic: called CC=1 SCAR=0.0
470 177180 sprintf(
471 '%s=%s(0x%08x)', blessed( $_[0] ), Scalar::Util::reftype( $_[0] ),
472 Scalar::Util::refaddr( $_[0] )
473 );
474 }
475  
476 303 our $DD;
477  
478 2568 ▶sub _dd {
Subroutine _dd: called CC=8 SCAR=20.9
479 2568 ▶ @_ = $_ unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 2568 2568
480 2568 my ( $value ) = @_;
481
482 2568 ▶ goto $DD if ref( $DD ) eq q(CODE);
Branch: 1 branch
BranchTrueFalseTotal
if ref $Type::Tiny::DD eq "CODE" 2 2566 2568
483
484 2566 require B;
485
486 !defined $value ? 'Undef'
487 : !ref $value ? sprintf( 'Value %s', B::perlstring( $value ) )
488 2566 ▶ : do {
Branch: 2 branches
BranchTrueFalseTotal
!defined($value) ? : 99 2467 2566
!ref($value) ? : 942 1525 2467
489 1525 ▶ my $N = 0+ ( defined( $DD ) ? $DD : 72 );
Branch: 1 branch
BranchTrueFalseTotal
defined $Type::Tiny::DD ? : 0 1525 1525
490 1525 require Data::Dumper;
491 1525 local $Data::Dumper::Indent = 0;
492 1525 local $Data::Dumper::Useqq = 1;
493 1525 local $Data::Dumper::Terse = 1;
494 1525 local $Data::Dumper::Sortkeys = 1;
495 1525 local $Data::Dumper::Maxdepth = 2;
496 1525 my $str;
497 eval {
498 1525 ▶ local $SIG{__WARN__} = sub {};
Subroutine __ANON__: not called CC=1 SCAR=0.0
499 1525 $str = Data::Dumper::Dumper( $value );
500 1525 ▶ $str = substr( $str, 0, $N - 12 ) . '...' . substr( $str, -1, 1 )
Branch: 1 branch
BranchTrueFalseTotal
if length $str >= $N 36 1489 1525
501 if length( $str ) >= $N;
502 1525 1;
503 0 ▶ } or do { $str = 'which cannot be dumped' };
Branch: 1 branch
BranchTrueFalseTotal
eval { do { local $SIG{"__WARN__"} = sub { } ; $str = Data::Dumper::Dumper($value); $str = substr($str, 0, ($N - 12)) . '...' . substr($str, -1, 1) if length $str >= $N; 1 } } or do { $str = "which cannot be dumped" } 1525 0 1525
504 1525 "Reference $str";
505 } #/ do
506 } #/ sub _dd
507  
508 31894 ▶sub _loose_to_TypeTiny {
Subroutine _loose_to_TypeTiny: called CC=2 SCAR=6.9
509 31894 my $caller = caller( 1 ); # assumption
510 map +(
511 ref( $_ )
512 ? Types::TypeTiny::to_TypeTiny( $_ )
513 31894 ▶ : do { require Type::Utils; Type::Utils::dwim_type( $_, for => $caller ) }
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 63786 2 63788
514 ), @_;
515 }
516  
517 106150 ▶sub name { $_[0]{name} }
Subroutine name: called CC=1 SCAR=0.0
Pod documented
518 51500 ▶sub display_name { $_[0]{display_name} ||= $_[0]->_build_display_name }
Subroutine display_name: called CC=2 SCAR=7.2
Pod documented
Condition66%2/3
$_[0]{"display_name"} ||= $_[0]->_build_display_name
l!l&&r!l&&!r
38632128680
MC/DC0%0/2
$_[0]{"display_name"} ||= $_[0]->_build_display_name
$_[0]{"display_name"} $_[0]->_build_display_name
Truth table66%2/3
A ||= B
A= $_[0]{"display_name"}B= $_[0]->_build_display_name
ABresult
1X1
011
000
519 158608 ▶sub parent { $_[0]{parent} }
Subroutine parent: called CC=1 SCAR=0.0
Pod documented
520 436757 ▶sub constraint { $_[0]{constraint} ||= $_[0]->_build_constraint }
Subroutine constraint: called CC=2 SCAR=7.2
Pod documented
Condition66%2/3
$_[0]{"constraint"} ||= $_[0]->_build_constraint
l!l&&r!l&&!r
43217645810
MC/DC0%0/2
$_[0]{"constraint"} ||= $_[0]->_build_constraint
$_[0]{"constraint"} $_[0]->_build_constraint
Truth table66%2/3
A ||= B
A= $_[0]{"constraint"}B= $_[0]->_build_constraint
ABresult
1X1
011
000
521  
522 133241 ▶sub compiled_check {
Subroutine compiled_check: called CC=2 SCAR=7.2
Pod documented
523 133241 ▶ $_[0]{compiled_type_constraint} ||= $_[0]->_build_compiled_check;
Condition66%2/3
$_[0]{"compiled_type_constraint"} ||= $_[0]->_build_compiled_check
l!l&&r!l&&!r
85777474640
MC/DC0%0/2
$_[0]{"compiled_type_constraint"} ||= $_[0]->_build_compiled_check
$_[0]{"compiled_type_constraint"} $_[0]->_build_compiled_check
Truth table66%2/3
A ||= B
A= $_[0]{"compiled_type_constraint"}B= $_[0]->_build_compiled_check
ABresult
1X1
011
000
524 }
525 19869 ▶sub coercion { $_[0]{coercion} ||= $_[0]->_build_coercion }
Subroutine coercion: called CC=2 SCAR=7.2
Pod documented
Condition66%2/3
$_[0]{"coercion"} ||= $_[0]->_build_coercion
l!l&&r!l&&!r
7233126360
MC/DC0%0/2
$_[0]{"coercion"} ||= $_[0]->_build_coercion
$_[0]{"coercion"} $_[0]->_build_coercion
Truth table66%2/3
A ||= B
A= $_[0]{"coercion"}B= $_[0]->_build_coercion
ABresult
1X1
011
000
526 28 ▶sub message { $_[0]{message} }
Subroutine message: called CC=1 SCAR=0.0
Pod documented
527 68 ▶sub library { $_[0]{library} }
Subroutine library: called CC=1 SCAR=0.0
Pod documented
528 50598 ▶sub inlined { $_[0]{inlined} }
Subroutine inlined: called CC=1 SCAR=0.0
Pod documented
529 32440 ▶sub deprecated { $_[0]{deprecated} }
Subroutine deprecated: called CC=1 SCAR=0.0
Pod documented
530 1330 ▶sub constraint_generator { $_[0]{constraint_generator} }
Subroutine constraint_generator: called CC=1 SCAR=0.0
Pod documented
531 1129 ▶sub inline_generator { $_[0]{inline_generator} }
Subroutine inline_generator: called CC=1 SCAR=0.0
Pod documented
532 1048 ▶sub name_generator { $_[0]{name_generator} ||= $_[0]->_build_name_generator }
Subroutine name_generator: called CC=2 SCAR=7.2
Pod documented
Condition66%2/3
$_[0]{"name_generator"} ||= $_[0]->_build_name_generator
l!l&&r!l&&!r
8082400
MC/DC0%0/2
$_[0]{"name_generator"} ||= $_[0]->_build_name_generator
$_[0]{"name_generator"} $_[0]->_build_name_generator
Truth table66%2/3
A ||= B
A= $_[0]{"name_generator"}B= $_[0]->_build_name_generator
ABresult
1X1
011
000
533 214 ▶sub coercion_generator { $_[0]{coercion_generator} }
Subroutine coercion_generator: called CC=1 SCAR=0.0
Pod documented
534 966 ▶sub parameters { $_[0]{parameters} }
Subroutine parameters: called CC=1 SCAR=0.0
Pod documented
535 0 ▶sub moose_type { $_[0]{moose_type} ||= $_[0]->_build_moose_type }
Subroutine moose_type: not called CC=2 SCAR=17.9
Pod documented
Condition0%0/3
$_[0]{"moose_type"} ||= $_[0]->_build_moose_type
l!l&&r!l&&!r
000
MC/DC0%0/2
$_[0]{"moose_type"} ||= $_[0]->_build_moose_type
$_[0]{"moose_type"} $_[0]->_build_moose_type
Truth table0%0/3
A ||= B
A= $_[0]{"moose_type"}B= $_[0]->_build_moose_type
ABresult
1X1
011
000
536 0 ▶sub mouse_type { $_[0]{mouse_type} ||= $_[0]->_build_mouse_type }
Subroutine mouse_type: not called CC=2 SCAR=17.9
Pod documented
Condition0%0/3
$_[0]{"mouse_type"} ||= $_[0]->_build_mouse_type
l!l&&r!l&&!r
000
MC/DC0%0/2
$_[0]{"mouse_type"} ||= $_[0]->_build_mouse_type
$_[0]{"mouse_type"} $_[0]->_build_mouse_type
Truth table0%0/3
A ||= B
A= $_[0]{"mouse_type"}B= $_[0]->_build_mouse_type
ABresult
1X1
011
000
537 102 ▶sub deep_explanation { $_[0]{deep_explanation} }
Subroutine deep_explanation: called CC=1 SCAR=0.0
Pod documented
538 1964 ▶sub my_methods { $_[0]{my_methods} ||= $_[0]->_build_my_methods }
Subroutine my_methods: called CC=2 SCAR=7.2
Pod documented
Condition66%2/3
$_[0]{"my_methods"} ||= $_[0]->_build_my_methods
l!l&&r!l&&!r
18081560
MC/DC0%0/2
$_[0]{"my_methods"} ||= $_[0]->_build_my_methods
$_[0]{"my_methods"} $_[0]->_build_my_methods
Truth table66%2/3
A ||= B
A= $_[0]{"my_methods"}B= $_[0]->_build_my_methods
ABresult
1X1
011
000
539 25 ▶sub sorter { $_[0]{sorter} }
Subroutine sorter: called CC=1 SCAR=0.0
Pod documented
540 23986 ▶sub exception_class { $_[0]{exception_class} ||= $_[0]->_build_exception_class }
Subroutine exception_class: called CC=2 SCAR=7.2
Pod documented
Condition66%2/3
$_[0]{"exception_class"} ||= $_[0]->_build_exception_class
l!l&&r!l&&!r
11604123820
MC/DC0%0/2
$_[0]{"exception_class"} ||= $_[0]->_build_exception_class
$_[0]{"exception_class"} $_[0]->_build_exception_class
Truth table66%2/3
A ||= B
A= $_[0]{"exception_class"}B= $_[0]->_build_exception_class
ABresult
1X1
011
000
541  
542 587960 ▶sub has_parent { exists $_[0]{parent} }
Subroutine has_parent: called CC=1 SCAR=0.0
Pod documented
543 0 ▶sub has_library { exists $_[0]{library} }
Subroutine has_library: not called CC=1 SCAR=6.9
Pod documented
544 143730 ▶sub has_inlined { exists $_[0]{inlined} }
Subroutine has_inlined: called CC=1 SCAR=0.0
Pod documented
545 15734 ▶sub has_constraint_generator { exists $_[0]{constraint_generator} }
Subroutine has_constraint_generator: called CC=1 SCAR=0.0
Pod documented
546 864 ▶sub has_inline_generator { exists $_[0]{inline_generator} }
Subroutine has_inline_generator: called CC=1 SCAR=0.0
Pod documented
547 2151 ▶sub has_coercion_generator { exists $_[0]{coercion_generator} }
Subroutine has_coercion_generator: called CC=1 SCAR=0.0
Pod documented
548 491 ▶sub has_parameters { exists $_[0]{parameters} }
Subroutine has_parameters: called CC=1 SCAR=0.0
Pod documented
549 899 ▶sub has_message { defined $_[0]{message} }
Subroutine has_message: called CC=1 SCAR=0.0
Pod documented
550 102 ▶sub has_deep_explanation { exists $_[0]{deep_explanation} }
Subroutine has_deep_explanation: called CC=1 SCAR=0.0
Pod documented
551 74 ▶sub has_sorter { exists $_[0]{sorter} }
Subroutine has_sorter: called CC=1 SCAR=0.0
Pod documented
552  
553 871 ▶sub _default_message {
Subroutine _default_message: called CC=2 SCAR=7.2
554 871 ▶ $_[0]{_default_message} ||= $_[0]->_build_default_message;
Condition66%2/3
$_[0]{"_default_message"} ||= $_[0]->_build_default_message
l!l&&r!l&&!r
6841870
MC/DC0%0/2
$_[0]{"_default_message"} ||= $_[0]->_build_default_message
$_[0]{"_default_message"} $_[0]->_build_default_message
Truth table66%2/3
A ||= B
A= $_[0]{"_default_message"}B= $_[0]->_build_default_message
ABresult
1X1
011
000
555 }
556  
557 30786 ▶sub has_coercion {
Subroutine has_coercion: called CC=3 SCAR=11.0
Pod documented
558 30786 ▶ $_[0]->coercion if $_[0]{_build_coercion}; # trigger auto build thing
Branch: 1 branch
BranchTrueFalseTotal
if $_[0]{"_build_coercion"} 703 30083 30786
559 30786 ▶ $_[0]{coercion} and !!@{ $_[0]{coercion}->type_coercion_map };
Branch: 1 branch
BranchTrueFalseTotal
$_[0]{"coercion"} and not !@{$_[0]{"coercion"}->type_coercion_map;} 19036 11750 30786
560 }
561  
562 649 ▶sub _assert_coercion {
Subroutine _assert_coercion: called CC=4 SCAR=13.9
563 649 my $self = shift;
564 649 ▶ return $self->coercion if $self->{_build_coercion}; # trigger auto build thing
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"_build_coercion"} 136 513 649
565 _croak "No coercion for this type constraint"
566 unless $self->has_coercion
567 513 ▶ && @{ $self->coercion->type_coercion_map };
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_coercion and @{$self->coercion->type_coercion_map;} 9 504 513
Condition66%2/3
$self->has_coercion and @{$self->coercion->type_coercion_map;}
!ll&&!rl&&r
90504
MC/DC50%1/2
$self->has_coercion and @{$self->coercion->type_coercion_map;}
$self->has_coercion @{$self->coercion->type_coercion_map;}
Truth table66%2/3
A and B
A= $self->has_coercionB= @{$self->coercion->type_coercion_map;}
ABresult
0X0
100
111
568 504 $self->coercion;
569 }
570  
571 0 ▶my $null_constraint = sub { !!1 };
Subroutine __ANON__: not called CC=1 SCAR=1.2
572  
573 12717 ▶sub _build_display_name {
Subroutine _build_display_name: called CC=1 SCAR=0.0
574 12717 shift->name;
575 }
576  
577 4529 ▶sub _build_constraint {
Subroutine _build_constraint: called CC=1 SCAR=0.0
578 4529 return $null_constraint;
579 }
580  
581 376478 ▶sub _is_null_constraint {
Subroutine _is_null_constraint: called CC=1 SCAR=0.0
582 376478 shift->constraint == $null_constraint;
583 }
584  
585 12578 ▶sub _build_coercion {
Subroutine _build_coercion: called CC=3 SCAR=11.0
586 12578 require Type::Coercion;
587 12578 my $self = shift;
588 12578 my %opts = ( type_constraint => $self );
589 12578 ▶ $opts{display_name} = "to_$self" unless $self->is_anon;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->is_anon 11476 1102 12578
590 12578 my $coercion = "Type::Coercion"->new( %opts );
591 12578 ▶ $self->{_build_coercion}->( $coercion ) if ref $self->{_build_coercion};
Branch: 1 branch
BranchTrueFalseTotal
if ref $self->{"_build_coercion"} 447 12131 12578
592 12578 $coercion;
593 }
594  
595 184 ▶sub _build_default_message {
Subroutine _build_default_message: called CC=2 SCAR=6.9
596 184 my $self = shift;
597 184 $self->{is_using_default_message} = 1;
598 67 ▶ return sub { sprintf '%s did not pass type constraint', _dd( $_[0] ) }
Subroutine __ANON__: called CC=1 SCAR=0.0
599 184 ▶ if "$self" eq "__ANON__";
Branch: 1 branch
BranchTrueFalseTotal
if "$self" eq "__ANON__" 26 158 184
600 158 my $name = "$self";
601 801 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
602 801 sprintf '%s did not pass type constraint "%s"', _dd( $_[0] ), $name;
603 158 };
604 } #/ sub _build_default_message
605  
606 240 ▶sub _build_name_generator {
Subroutine _build_name_generator: called CC=1 SCAR=0.0
607 240 my $self = shift;
608 885 ▶ return sub {
Subroutine __ANON__: called CC=6 SCAR=18.3
609 885 ▶ defined && s/[\x00-\x1F]//smg for ( my ( $s, @a ) = @_ );
Branch: 1 branch
BranchTrueFalseTotal
defined $_ and s/[\x00-\x1F]//gms 2063 0 2063
610 885 ▶ sprintf( '%s[%s]', $s, join q[,], map !defined() ? 'undef' : !ref() && /\W/ ? B::perlstring($_) : $_, @a );
Branch: 2 branches
BranchTrueFalseTotal
!defined($_) ? : 0 1178 1178
!ref($_) && /\W/ ? : 35 1143 1178
Condition100%3/3
not ref $_ and /\W/
!ll&&!rl&&r
57257135
MC/DC100%2/2
not ref $_ and /\W/
not ref $_ /\W/
Truth table100%3/3
not(A) and B
A= not ref $_B= /\W/
ABresult
0X0
100
111
611 240 };
612 }
613  
614 48014 ▶sub _build_compiled_check {
Subroutine _build_compiled_check: called CC=7 SCAR=19.5
615 48014 my $self = shift;
616
617 48014 local our $AvoidCallbacks = 0;
618
619 48014 ▶ if ( $self->_is_null_constraint and $self->has_parent ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_null_constraint and $self->has_parent) 3430 44584 48014
Condition100%3/3
$self->_is_null_constraint and $self->has_parent
!ll&&!rl&&r
4457773430
MC/DC100%2/2
$self->_is_null_constraint and $self->has_parent
$self->_is_null_constraint $self->has_parent
Truth table100%3/3
A and B
A= $self->_is_null_constraintB= $self->has_parent
ABresult
0X0
100
111
620 3430 return $self->parent->compiled_check;
621 }
622
623 44584 require Eval::TypeTiny;
624 44584 ▶ return Eval::TypeTiny::eval_closure(
Branch: 1 branch
BranchTrueFalseTotal
if $self->can_be_inlined 4322 40262 44584
625 source => sprintf( 'sub ($) { %s }', $self->inline_check( '$_[0]' ) ),
626 description => sprintf( "compiled check '%s'", $self ),
627 ) if $self->can_be_inlined;
628
629 40262 my @constraints;
630 40262 ▶ push @constraints, $self->parent->compiled_check if $self->has_parent;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_parent 210 40052 40262
631 40262 ▶ push @constraints, $self->constraint if !$self->_is_null_constraint;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_null_constraint 40262 0 40262
632 40262 ▶ return $null_constraint unless @constraints;
Branch: 1 branch
BranchTrueFalseTotal
unless @constraints 0 40262 40262
633
634 2935 ▶ return sub ($) {
Subroutine __ANON__: called CC=3 SCAR=11.0
635 2935 local $_ = $_[0];
636 2935 for my $c ( @constraints ) {
637 5171 ▶ return unless $c->( @_ );
Branch: 2 branches
BranchTrueFalseTotal
unless &$c(@_) 862 4309 5171
unless &$c(@_) 314 447 761
638 }
639 2073 return !!1;
640 40262 };
641 } #/ sub _build_compiled_check
642  
643 12382 ▶sub _build_exception_class {
Subroutine _build_exception_class: called CC=2 SCAR=6.9
644 12382 my $self = shift;
645 12382 ▶ return $self->parent->exception_class if $self->has_parent;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_parent 11254 1128 12382
646 1128 require Error::TypeTiny::Assertion;
647 1128 return 'Error::TypeTiny::Assertion';
648 }
649  
650 1 ▶sub definition_context {
Subroutine definition_context: called CC=2 SCAR=7.2
Pod documented
651 1 my $self = shift;
652 1 ▶ my $found = $self->find_parent(sub {
Subroutine __ANON__: called CC=2 SCAR=7.6
653 1 ▶ ref $_->{definition_context} and exists $_->{definition_context}{file};
Branch: 1 branch
BranchTrueFalseTotal
ref $_->{"definition_context"} and exists $_->{"definition_context"}{"file"} 1 0 1
654 1 });
655 1 ▶ $found ? $found->{definition_context} : {};
Branch: 1 branch
BranchTrueFalseTotal
$found ? : 1 0 1
656 }
657  
658 4055 ▶sub find_constraining_type {
Subroutine find_constraining_type: called CC=3 SCAR=11.0
Pod documented
659 4055 my $self = shift;
660 4055 ▶ if ( $self->_is_null_constraint and $self->has_parent ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_is_null_constraint and $self->has_parent) 810 3245 4055
Condition100%3/3
$self->_is_null_constraint and $self->has_parent
!ll&&!rl&&r
3040205810
MC/DC100%2/2
$self->_is_null_constraint and $self->has_parent
$self->_is_null_constraint $self->has_parent
Truth table100%3/3
A and B
A= $self->_is_null_constraintB= $self->has_parent
ABresult
0X0
100
111
661 810 return $self->parent->find_constraining_type;
662 }
663 3245 $self;
664 }
665  
666 739 ▶sub type_default {
Subroutine type_default: called CC=5 SCAR=16.1
Pod documented
667 739 my ( $self, @args ) = @_;
668 739 ▶ if ( exists $self->{type_default} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"type_default"}) 554 185 739
669 554 ▶ if ( @args ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 1 553 554
670 1 my $td = $self->{type_default};
671 1 ▶ return sub { local $_ = \@args; &$td; };
Subroutine __ANON__: called CC=1 SCAR=0.0
672 }
673 553 return $self->{type_default};
674 }
675 185 ▶ if ( my $parent = $self->parent ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $parent = $self->parent) 183 2 185
676 183 ▶ return $parent->type_default( @args ) if $self->_is_null_constraint;
Branch: 1 branch
BranchTrueFalseTotal
if $self->_is_null_constraint 104 79 183
677 }
678 81 return undef;
679 }
680  
681 303 our @CMP;
682  
683 sub CMP_SUPERTYPE () { -1 }
684 sub CMP_EQUAL () { 0 }
685 sub CMP_EQUIVALENT () { '0E0' }
686 sub CMP_SUBTYPE () { 1 }
687 sub CMP_UNKNOWN () { ''; }
688  
689 # avoid getting mixed up with cmp operator at compile time
690 1523 ▶*cmp = sub {
Subroutine __ANON__: called CC=9 SCAR=22.9
691 1523 my ( $A, $B ) = _loose_to_TypeTiny( $_[0], $_[1] );
692 1523 ▶ return unless blessed( $A ) && $A->isa( "Type::Tiny" );
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($A) and $A->isa("Type::Tiny") 0 1523 1523
Condition33%1/3
builtin::blessed($A) and $A->isa("Type::Tiny")
!ll&&!rl&&r
001523
MC/DC0%0/2
builtin::blessed($A) and $A->isa("Type::Tiny")
builtin::blessed($A) $A->isa("Type::Tiny")
Truth table33%1/3
A and B
A= builtin::blessed($A)B= $A->isa("Type::Tiny")
ABresult
0X0
100
111
693 1523 ▶ return unless blessed( $B ) && $B->isa( "Type::Tiny" );
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($B) and $B->isa("Type::Tiny") 0 1523 1523
Condition33%1/3
builtin::blessed($B) and $B->isa("Type::Tiny")
!ll&&!rl&&r
001523
MC/DC0%0/2
builtin::blessed($B) and $B->isa("Type::Tiny")
builtin::blessed($B) $B->isa("Type::Tiny")
Truth table33%1/3
A and B
A= builtin::blessed($B)B= $B->isa("Type::Tiny")
ABresult
0X0
100
111
694 1523 for my $comparator ( @CMP ) {
695 1998 my $result = $comparator->( $A, $B );
696 1998 ▶ next if $result eq CMP_UNKNOWN;
Branch: 1 branch
BranchTrueFalseTotal
if $result eq "" 818 1180 1998
697 1180 ▶ if ( $result eq CMP_EQUIVALENT ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($result eq "0E0") 51 1129 1180
698 51 ▶ my $prefer = @_ == 3 ? $_[2] : CMP_EQUAL;
Branch: 1 branch
BranchTrueFalseTotal
@_ == 3 ? : 12 39 51
699 51 return $prefer;
700 }
701 1129 return $result;
702 }
703 343 return CMP_UNKNOWN;
704 303 };
705  
706 1523 ▶push @CMP, sub {
Subroutine __ANON__: called CC=20 SCAR=30.0
707 1523 my ( $A, $B ) = @_;
708 1523 ▶ return CMP_EQUAL
Branch: 1 branch
BranchTrueFalseTotal
if builtin::refaddr($A) == builtin::refaddr($B) 345 1178 1523
709 if Scalar::Util::refaddr( $A ) == Scalar::Util::refaddr( $B );
710
711 1178 ▶ return CMP_EQUIVALENT
Branch: 1 branch
BranchTrueFalseTotal
if builtin::refaddr($A->compiled_check) == builtin::refaddr($B->compiled_check) 35 1143 1178
712 if Scalar::Util::refaddr( $A->compiled_check ) ==
713 Scalar::Util::refaddr( $B->compiled_check );
714
715 1143 my $A_stem = $A->find_constraining_type;
716 1143 my $B_stem = $B->find_constraining_type;
717 1143 ▶ return CMP_EQUIVALENT
Branch: 1 branch
BranchTrueFalseTotal
if builtin::refaddr($A_stem) == builtin::refaddr($B_stem) 2 1141 1143
718 if Scalar::Util::refaddr( $A_stem ) == Scalar::Util::refaddr( $B_stem );
719 1141 ▶ return CMP_EQUIVALENT
Branch: 1 branch
BranchTrueFalseTotal
if builtin::refaddr($A_stem->compiled_check) == builtin::refaddr($B_stem->compiled_check) 0 1141 1141
720 if Scalar::Util::refaddr( $A_stem->compiled_check ) ==
721 Scalar::Util::refaddr( $B_stem->compiled_check );
722
723 1141 ▶ if ( $A_stem->can_be_inlined and $B_stem->can_be_inlined ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($A_stem->can_be_inlined and $B_stem->can_be_inlined) 924 217 1141
Condition100%3/3
$A_stem->can_be_inlined and $B_stem->can_be_inlined
!ll&&!rl&&r
18334924
MC/DC100%2/2
$A_stem->can_be_inlined and $B_stem->can_be_inlined
$A_stem->can_be_inlined $B_stem->can_be_inlined
Truth table100%3/3
A and B
A= $A_stem->can_be_inlinedB= $B_stem->can_be_inlined
ABresult
0X0
100
111
724 924 ▶ return CMP_EQUIVALENT
Branch: 1 branch
BranchTrueFalseTotal
if $A_stem->inline_check("\$WOLFIE") eq $B_stem->inline_check("\$WOLFIE") 13 911 924
725 if $A_stem->inline_check( '$WOLFIE' ) eq $B_stem->inline_check( '$WOLFIE' );
726 }
727
728 A_IS_SUBTYPE: {
729 1128 my $A_prime = $A_stem;
730 1128 ▶ while ( $A_prime->has_parent ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($A_prime->has_parent) 3213 424 3637
731 3213 $A_prime = $A_prime->parent;
732 3213 ▶ return CMP_SUBTYPE
Branch: 1 branch
BranchTrueFalseTotal
if builtin::refaddr($A_prime) == builtin::refaddr($B_stem) 213 3000 3213
733 if Scalar::Util::refaddr( $A_prime ) == Scalar::Util::refaddr( $B_stem );
734 3000 ▶ return CMP_SUBTYPE
Branch: 1 branch
BranchTrueFalseTotal
if builtin::refaddr($A_prime->compiled_check) == builtin::refaddr($B_stem->compiled_check) 407 2593 3000
735 if Scalar::Util::refaddr( $A_prime->compiled_check ) ==
736 Scalar::Util::refaddr( $B_stem->compiled_check );
737 2593 ▶ if ( $A_prime->can_be_inlined and $B_stem->can_be_inlined ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($A_prime->can_be_inlined and $B_stem->can_be_inlined) 2209 384 2593
Condition100%3/3
$A_prime->can_be_inlined and $B_stem->can_be_inlined
!ll&&!rl&&r
1722122209
MC/DC100%2/2
$A_prime->can_be_inlined and $B_stem->can_be_inlined
$A_prime->can_be_inlined $B_stem->can_be_inlined
Truth table100%3/3
A and B
A= $A_prime->can_be_inlinedB= $B_stem->can_be_inlined
ABresult
0X0
100
111
738 2209 ▶ return CMP_SUBTYPE
Branch: 1 branch
BranchTrueFalseTotal
if $A_prime->inline_check("\$WOLFIE") eq $B_stem->inline_check("\$WOLFIE") 84 2125 2209
739 if $A_prime->inline_check( '$WOLFIE' ) eq $B_stem->inline_check( '$WOLFIE' );
740 }
741 } #/ while ( $A_prime->has_parent)
742 } #/ A_IS_SUBTYPE:
743
744 B_IS_SUBTYPE: {
745 424 my $B_prime = $B_stem;
746 424 ▶ while ( $B_prime->has_parent ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($B_prime->has_parent) 1566 365 1931
747 1566 $B_prime = $B_prime->parent;
748 1566 ▶ return CMP_SUPERTYPE
Branch: 1 branch
BranchTrueFalseTotal
if builtin::refaddr($B_prime) == builtin::refaddr($A_stem) 17 1549 1566
749 if Scalar::Util::refaddr( $B_prime ) == Scalar::Util::refaddr( $A_stem );
750 1549 ▶ return CMP_SUPERTYPE
Branch: 1 branch
BranchTrueFalseTotal
if builtin::refaddr($B_prime->compiled_check) == builtin::refaddr($A_stem->compiled_check) 34 1515 1549
751 if Scalar::Util::refaddr( $B_prime->compiled_check ) ==
752 Scalar::Util::refaddr( $A_stem->compiled_check );
753 1515 ▶ if ( $A_stem->can_be_inlined and $B_prime->can_be_inlined ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($A_stem->can_be_inlined and $B_prime->can_be_inlined) 1167 348 1515
Condition100%3/3
$A_stem->can_be_inlined and $B_prime->can_be_inlined
!ll&&!rl&&r
297511167
MC/DC100%2/2
$A_stem->can_be_inlined and $B_prime->can_be_inlined
$A_stem->can_be_inlined $B_prime->can_be_inlined
Truth table100%3/3
A and B
A= $A_stem->can_be_inlinedB= $B_prime->can_be_inlined
ABresult
0X0
100
111
754 1167 ▶ return CMP_SUPERTYPE
Branch: 1 branch
BranchTrueFalseTotal
if $B_prime->inline_check("\$WOLFIE") eq $A_stem->inline_check("\$WOLFIE") 8 1159 1167
755 if $B_prime->inline_check( '$WOLFIE' ) eq $A_stem->inline_check( '$WOLFIE' );
756 }
757 } #/ while ( $B_prime->has_parent)
758 } #/ B_IS_SUBTYPE:
759
760 365 return CMP_UNKNOWN;
761 303 };
762  
763 777 ▶sub equals {
Subroutine equals: called CC=2 SCAR=7.1
Pod documented
764 777 my $result = Type::Tiny::cmp( $_[0], $_[1] );
765 777 ▶ return unless defined $result;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $result 0 777 777
766 777 $result eq CMP_EQUAL;
767 }
768  
769 101 ▶sub is_subtype_of {
Subroutine is_subtype_of: called CC=2 SCAR=7.1
Pod documented
770 101 my $result = Type::Tiny::cmp( $_[0], $_[1], CMP_SUBTYPE );
771 101 ▶ return unless defined $result;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $result 0 101 101
772 101 $result eq CMP_SUBTYPE;
773 }
774  
775 21 ▶sub is_supertype_of {
Subroutine is_supertype_of: called CC=2 SCAR=7.1
Pod documented
776 21 my $result = Type::Tiny::cmp( $_[0], $_[1], CMP_SUBTYPE );
777 21 ▶ return unless defined $result;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $result 0 21 21
778 21 $result eq CMP_SUPERTYPE;
779 }
780  
781 580 ▶sub is_a_type_of {
Subroutine is_a_type_of: called CC=4 SCAR=13.9
Pod documented
782 580 my $result = Type::Tiny::cmp( $_[0], $_[1] );
783 580 ▶ return unless defined $result;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $result 0 580 580
784 580 ▶ $result eq CMP_SUBTYPE or $result eq CMP_EQUAL or $result eq CMP_EQUIVALENT;
Branch: 1 branch
BranchTrueFalseTotal
$result eq 1 or $result eq 0 or $result eq "0E0" 240 340 580
Condition100%3/3
$result eq 1 or $result eq 0
l!l&&r!l&&!r
18951340
MC/DC100%2/2
$result eq 1 or $result eq 0
$result eq 1 $result eq 0
Truth table100%3/3
A or B
A= $result eq 1B= $result eq 0
ABresult
1X1
011
000
785 }
786  
787 14193 ▶sub strictly_equals {
Subroutine strictly_equals: called CC=5 SCAR=19.4
Pod documented
788 14193 my ( $self, $other ) = _loose_to_TypeTiny( @_ );
789 14193 ▶ return unless blessed( $self ) && $self->isa( "Type::Tiny" );
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($self) and $self->isa("Type::Tiny") 0 14193 14193
Condition33%1/3
builtin::blessed($self) and $self->isa("Type::Tiny")
!ll&&!rl&&r
0014193
MC/DC0%0/2
builtin::blessed($self) and $self->isa("Type::Tiny")
builtin::blessed($self) $self->isa("Type::Tiny")
Truth table33%1/3
A and B
A= builtin::blessed($self)B= $self->isa("Type::Tiny")
ABresult
0X0
100
111
790 14193 ▶ return unless blessed( $other ) && $other->isa( "Type::Tiny" );
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($other) and $other->isa("Type::Tiny") 0 14193 14193
Condition33%1/3
builtin::blessed($other) and $other->isa("Type::Tiny")
!ll&&!rl&&r
0014193
MC/DC0%0/2
builtin::blessed($other) and $other->isa("Type::Tiny")
builtin::blessed($other) $other->isa("Type::Tiny")
Truth table33%1/3
A and B
A= builtin::blessed($other)B= $other->isa("Type::Tiny")
ABresult
0X0
100
111
791 14193 $self->{uniq} == $other->{uniq};
792 }
793  
794 13625 ▶sub is_strictly_subtype_of {
Subroutine is_strictly_subtype_of: called CC=7 SCAR=21.5
Pod documented
795 13625 my ( $self, $other ) = _loose_to_TypeTiny( @_ );
796 13625 ▶ return unless blessed( $self ) && $self->isa( "Type::Tiny" );
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($self) and $self->isa("Type::Tiny") 0 13625 13625
Condition33%1/3
builtin::blessed($self) and $self->isa("Type::Tiny")
!ll&&!rl&&r
0013625
MC/DC0%0/2
builtin::blessed($self) and $self->isa("Type::Tiny")
builtin::blessed($self) $self->isa("Type::Tiny")
Truth table33%1/3
A and B
A= builtin::blessed($self)B= $self->isa("Type::Tiny")
ABresult
0X0
100
111
797 13625 ▶ return unless blessed( $other ) && $other->isa( "Type::Tiny" );
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($other) and $other->isa("Type::Tiny") 0 13625 13625
Condition33%1/3
builtin::blessed($other) and $other->isa("Type::Tiny")
!ll&&!rl&&r
0013625
MC/DC0%0/2
builtin::blessed($other) and $other->isa("Type::Tiny")
builtin::blessed($other) $other->isa("Type::Tiny")
Truth table33%1/3
A and B
A= builtin::blessed($other)B= $other->isa("Type::Tiny")
ABresult
0X0
100
111
798
799 13625 ▶ return unless $self->has_parent;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_parent 2002 11623 13625
800 11623 ▶ $self->parent->strictly_equals( $other )
Branch: 1 branch
BranchTrueFalseTotal
$self->parent->strictly_equals($other) or $self->parent->is_strictly_subtype_of($other) 553 11070 11623
801 or $self->parent->is_strictly_subtype_of( $other );
802 }
803  
804 2 ▶sub is_strictly_supertype_of {
Subroutine is_strictly_supertype_of: called CC=5 SCAR=19.4
Pod documented
805 2 my ( $self, $other ) = _loose_to_TypeTiny( @_ );
806 2 ▶ return unless blessed( $self ) && $self->isa( "Type::Tiny" );
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($self) and $self->isa("Type::Tiny") 0 2 2
Condition33%1/3
builtin::blessed($self) and $self->isa("Type::Tiny")
!ll&&!rl&&r
002
MC/DC0%0/2
builtin::blessed($self) and $self->isa("Type::Tiny")
builtin::blessed($self) $self->isa("Type::Tiny")
Truth table33%1/3
A and B
A= builtin::blessed($self)B= $self->isa("Type::Tiny")
ABresult
0X0
100
111
807 2 ▶ return unless blessed( $other ) && $other->isa( "Type::Tiny" );
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($other) and $other->isa("Type::Tiny") 0 2 2
Condition33%1/3
builtin::blessed($other) and $other->isa("Type::Tiny")
!ll&&!rl&&r
002
MC/DC0%0/2
builtin::blessed($other) and $other->isa("Type::Tiny")
builtin::blessed($other) $other->isa("Type::Tiny")
Truth table33%1/3
A and B
A= builtin::blessed($other)B= $other->isa("Type::Tiny")
ABresult
0X0
100
111
808
809 2 $other->is_strictly_subtype_of( $self );
810 }
811  
812 2551 ▶sub is_strictly_a_type_of {
Subroutine is_strictly_a_type_of: called CC=6 SCAR=22.0
Pod documented
813 2551 my ( $self, $other ) = _loose_to_TypeTiny( @_ );
814 2551 ▶ return unless blessed( $self ) && $self->isa( "Type::Tiny" );
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($self) and $self->isa("Type::Tiny") 0 2551 2551
Condition33%1/3
builtin::blessed($self) and $self->isa("Type::Tiny")
!ll&&!rl&&r
002551
MC/DC0%0/2
builtin::blessed($self) and $self->isa("Type::Tiny")
builtin::blessed($self) $self->isa("Type::Tiny")
Truth table33%1/3
A and B
A= builtin::blessed($self)B= $self->isa("Type::Tiny")
ABresult
0X0
100
111
815 2551 ▶ return unless blessed( $other ) && $other->isa( "Type::Tiny" );
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::blessed($other) and $other->isa("Type::Tiny") 0 2551 2551
Condition33%1/3
builtin::blessed($other) and $other->isa("Type::Tiny")
!ll&&!rl&&r
002551
MC/DC0%0/2
builtin::blessed($other) and $other->isa("Type::Tiny")
builtin::blessed($other) $other->isa("Type::Tiny")
Truth table33%1/3
A and B
A= builtin::blessed($other)B= $other->isa("Type::Tiny")
ABresult
0X0
100
111
816
817 2551 ▶ $self->strictly_equals( $other ) or $self->is_strictly_subtype_of( $other );
Branch: 1 branch
BranchTrueFalseTotal
$self->strictly_equals($other) or $self->is_strictly_subtype_of($other) 0 2551 2551
818 }
819  
820 14535 ▶sub qualified_name {
Subroutine qualified_name: called CC=3 SCAR=11.1
Pod documented
821 14535 my $self = shift;
822 ( exists $self->{library} and $self->name ne "__ANON__" )
823 ? "$self->{library}::$self->{name}"
824 14535 ▶ : $self->{name};
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'library'} && $self->name ne '__ANON__' ? : 14492 43 14535
Condition66%2/3
exists $self->{"library"} and $self->name ne "__ANON__"
!ll&&!rl&&r
43014492
MC/DC50%1/2
exists $self->{"library"} and $self->name ne "__ANON__"
exists $self->{"library"} $self->name ne "__ANON__"
Truth table66%2/3
A and B
A= exists $self->{"library"}B= $self->name ne "__ANON__"
ABresult
0X0
100
111
825 }
826  
827 41338 ▶sub is_anon {
Subroutine is_anon: called CC=1 SCAR=0.0
Pod documented
828 41338 my $self = shift;
829 41338 $self->name eq "__ANON__";
830 }
831  
832 38052 ▶sub parents {
Subroutine parents: called CC=2 SCAR=6.9
Pod documented
833 38052 my $self = shift;
834 38052 ▶ return unless $self->has_parent;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_parent 6383 31669 38052
835 31669 return ( $self->parent, $self->parent->parents );
836 }
837  
838 481 ▶sub find_parent {
Subroutine find_parent: called CC=4 SCAR=13.9
Pod documented
839 481 my $self = shift;
840 481 my ( $test ) = @_;
841
842 481 local ( $_, $. );
843 481 my $type = $self;
844 481 my $count = 0;
845 481 ▶ while ( $type ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type) 589 3 592
846 589 ▶ if ( $test->( $_ = $type, $. = $count ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&$test($_ = $type, $. = $count)) { } 478 111 589
847 478 ▶ return wantarray ? ( $type, $count ) : $type;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 477 478
848 }
849 else {
850 111 $type = $type->parent;
851 111 $count++;
852 }
853 }
854
855 3 return;
856 } #/ sub find_parent
857  
858 142565 ▶sub check {
Subroutine check: called CC=2 SCAR=7.1
Pod documented
859 142565 my $self = shift;
860 142565 ▶ ( $self->{compiled_type_constraint} ||= $self->_build_compiled_check )->( @_ );
Condition66%2/3
$self->{"compiled_type_constraint"} ||= $self->_build_compiled_check
l!l&&r!l&&!r
1420255400
MC/DC0%0/2
$self->{"compiled_type_constraint"} ||= $self->_build_compiled_check
$self->{"compiled_type_constraint"} $self->_build_compiled_check
Truth table66%2/3
A ||= B
A= $self->{"compiled_type_constraint"}B= $self->_build_compiled_check
ABresult
1X1
011
000
861 }
862  
863 5625 ▶sub _strict_check {
Subroutine _strict_check: called CC=3 SCAR=11.0
864 5625 my $self = shift;
865 5625 local $_ = $_[0];
866
867 my @constraints =
868 reverse
869 20172 map { $_->constraint }
870 5625 grep { not $_->_is_null_constraint } ( $self, $self->parents );
871
872 5625 for my $c ( @constraints ) {
873 15443 ▶ return unless $c->( @_ );
Branch: 1 branch
BranchTrueFalseTotal
unless &$c(@_) 4062 11381 15443
874 }
875
876 1563 return !!1;
877 } #/ sub _strict_check
878  
879 899 ▶sub get_message {
Subroutine get_message: called CC=2 SCAR=6.9
Pod documented
880 899 my $self = shift;
881 899 local $_ = $_[0];
882 899 ▶ $self->has_message
Branch: 1 branch
BranchTrueFalseTotal
$self->has_message ? : 28 871 899
883 ? $self->message->( @_ )
884 : $self->_default_message->( @_ );
885 }
886  
887 2 ▶sub validate {
Subroutine validate: called CC=3 SCAR=12.0
Pod documented
888 2 my $self = shift;
889
890 return undef
891 2 ▶ if ( $self->{compiled_type_constraint} ||= $self->_build_compiled_check )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"compiled_type_constraint"} ||= $self->_build_compiled_check)->(@_) 0 2 2
Condition33%1/3
$self->{"compiled_type_constraint"} ||= $self->_build_compiled_check
l!l&&r!l&&!r
200
MC/DC0%0/2
$self->{"compiled_type_constraint"} ||= $self->_build_compiled_check
$self->{"compiled_type_constraint"} $self->_build_compiled_check
Truth table33%1/3
A ||= B
A= $self->{"compiled_type_constraint"}B= $self->_build_compiled_check
ABresult
1X1
011
000
892 ->( @_ );
893
894 2 local $_ = $_[0];
895 2 return $self->get_message( @_ );
896 } #/ sub validate
897  
898 2088 ▶sub validate_explain {
Subroutine validate_explain: called CC=9 SCAR=22.0
Pod documented
899 2088 my $self = shift;
900 2088 my ( $value, $varname ) = @_;
901 2088 ▶ $varname = '$_' unless defined $varname;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $varname 2 2086 2088
902
903 2088 ▶ return undef if $self->check( $value );
Branch: 1 branch
BranchTrueFalseTotal
if $self->check($value) 442 1646 2088
904
905 1646 ▶ if ( $self->has_parent ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_parent) 1638 8 1646
906 1638 my $parent = $self->parent->validate_explain( $value, $varname );
907 return [
908 1638 ▶ sprintf( '"%s" is a subtype of "%s"', $self, $self->parent ),
Branch: 1 branch
BranchTrueFalseTotal
if $parent 1196 442 1638
909 @$parent
910 ]
911 if $parent;
912 }
913
914 450 ▶ my $message = sprintf(
Branch: 1 branch
BranchTrueFalseTotal
$varname eq '$_' ? : 44 406 450
915 '%s%s',
916 $self->get_message( $value ),
917 $varname eq q{$_} ? '' : sprintf( ' (in %s)', $varname ),
918 );
919
920 450 ▶ if ( $self->is_parameterized and $self->parent->has_deep_explanation ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->is_parameterized and $self->parent->has_deep_explanation) 102 348 450
Condition66%2/3
$self->is_parameterized and $self->parent->has_deep_explanation
!ll&&!rl&&r
3480102
MC/DC50%1/2
$self->is_parameterized and $self->parent->has_deep_explanation
$self->is_parameterized $self->parent->has_deep_explanation
Truth table66%2/3
A and B
A= $self->is_parameterizedB= $self->parent->has_deep_explanation
ABresult
0X0
100
111
921 102 my $deep = $self->parent->deep_explanation->( $self, $value, $varname );
922 102 ▶ return [ $message, @$deep ] if $deep;
Branch: 1 branch
BranchTrueFalseTotal
if $deep 102 0 102
923 }
924  
925 348 ▶ local $SIG{__WARN__} = sub {};
Subroutine __ANON__: not called CC=1 SCAR=0.0
926 return [
927 348 $message,
928 sprintf( '"%s" is defined as: %s', $self, $self->_perlcode )
929 ];
930 } #/ sub validate_explain
931  
932 303 my $b;
933  
934 348 ▶sub _perlcode {
Subroutine _perlcode: called CC=4 SCAR=13.9
935 348 my $self = shift;
936
937 348 local our $AvoidCallbacks = 1;
938 348 ▶ return $self->inline_check( '$_' )
Branch: 1 branch
BranchTrueFalseTotal
if $self->can_be_inlined 336 12 348
939 if $self->can_be_inlined;
940
941 12 ▶ $b ||= do {
Condition66%2/3
$b ||= do { local $@; require B::Deparse; my $tmp = "B::Deparse"->new; $tmp->ambient_pragmas("strict", "all", "warnings", "all") if $tmp->can("ambient_pragmas"); $tmp }
l!l&&r!l&&!r
570
MC/DC0%0/2
$b ||= do { local $@; require B::Deparse; my $tmp = "B::Deparse"->new; $tmp->ambient_pragmas("strict", "all", "warnings", "all") if $tmp->can("ambient_pragmas"); $tmp }
$b do { local $@; require B::Deparse; my $tmp = "B::Deparse"->new; $tmp->ambient_pragmas("strict", "all", "warnings", "all") if $tmp->can("ambient_pragmas"); $tmp }
Truth table66%2/3
A ||= B
A= $bB= do { local $@; require B::Deparse; my $tmp = "B::Deparse"->new; $tmp->ambient_pragmas("strict", "all", "warnings", "all") if $tmp->can("ambient_pragmas"); $tmp }
ABresult
1X1
011
000
942 7 local $@;
943 7 require B::Deparse;
944 7 my $tmp = "B::Deparse"->new;
945 7 ▶ $tmp->ambient_pragmas( strict => "all", warnings => "all" )
Branch: 1 branch
BranchTrueFalseTotal
if $tmp->can("ambient_pragmas") 7 0 7
946 if $tmp->can( 'ambient_pragmas' );
947 7 $tmp;
948 };
949
950 12 my $code = $b->coderef2text( $self->constraint );
951 12 $code =~ s/\s+/ /g;
952 12 return "sub $code";
953 } #/ sub _perlcode
954  
955 87 ▶sub assert_valid {
Subroutine assert_valid: called CC=3 SCAR=11.0
Pod documented
956 87 my $self = shift;
957
958 return !!1
959 87 ▶ if ( $self->{compiled_type_constraint} ||= $self->_build_compiled_check )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"compiled_type_constraint"} ||= $self->_build_compiled_check)->(@_) 72 15 87
Condition66%2/3
$self->{"compiled_type_constraint"} ||= $self->_build_compiled_check
l!l&&r!l&&!r
7890
MC/DC0%0/2
$self->{"compiled_type_constraint"} ||= $self->_build_compiled_check
$self->{"compiled_type_constraint"} $self->_build_compiled_check
Truth table66%2/3
A ||= B
A= $self->{"compiled_type_constraint"}B= $self->_build_compiled_check
ABresult
1X1
011
000
960 ->( @_ );
961
962 15 local $_ = $_[0];
963 15 $self->_failed_check( "$self", $_ );
964 } #/ sub assert_valid
965  
966 115083 ▶sub assert_return {
Subroutine assert_return: called CC=3 SCAR=11.0
Pod documented
967 115083 my $self = shift;
968
969 return $_[0]
970 115083 ▶ if ( $self->{compiled_type_constraint} ||= $self->_build_compiled_check )
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"compiled_type_constraint"} ||= $self->_build_compiled_check)->(@_) 115082 1 115083
Condition66%2/3
$self->{"compiled_type_constraint"} ||= $self->_build_compiled_check
l!l&&r!l&&!r
11508210
MC/DC0%0/2
$self->{"compiled_type_constraint"} ||= $self->_build_compiled_check
$self->{"compiled_type_constraint"} $self->_build_compiled_check
Truth table66%2/3
A ||= B
A= $self->{"compiled_type_constraint"}B= $self->_build_compiled_check
ABresult
1X1
011
000
971 ->( @_ );
972
973 1 local $_ = $_[0];
974 1 $self->_failed_check( "$self", $_ );
975 } #/ sub assert_return
976  
977 186899 ▶sub can_be_inlined {
Subroutine can_be_inlined: called CC=5 SCAR=16.1
Pod documented
978 186899 my $self = shift;
979 186899 ▶ return $self->parent->can_be_inlined
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_parent and $self->_is_null_constraint 27574 159325 186899
Condition100%3/3
$self->has_parent and $self->_is_null_constraint
!ll&&!rl&&r
5890210042327574
MC/DC100%2/2
$self->has_parent and $self->_is_null_constraint
$self->has_parent $self->_is_null_constraint
Truth table100%3/3
A and B
A= $self->has_parentB= $self->_is_null_constraint
ABresult
0X0
100
111
980 if $self->has_parent && $self->_is_null_constraint;
981 159325 ▶ return !!1
Branch: 1 branch
BranchTrueFalseTotal
if not $self->has_parent and $self->_is_null_constraint 13220 146105 159325
Condition100%3/3
not $self->has_parent and $self->_is_null_constraint
!ll&&!rl&&r
1004234568213220
MC/DC100%2/2
not $self->has_parent and $self->_is_null_constraint
not $self->has_parent $self->_is_null_constraint
Truth table100%3/3
not(A) and B
A= not $self->has_parentB= $self->_is_null_constraint
ABresult
0X0
100
111
982 if !$self->has_parent && $self->_is_null_constraint;
983 146105 return $self->has_inlined;
984 }
985  
986 68465 ▶sub inline_check {
Subroutine inline_check: called CC=13 SCAR=25.7
Pod documented
987 68465 my $self = shift;
988 68465 ▶ _croak 'Cannot inline type constraint check for "%s"', $self
Branch: 1 branch
BranchTrueFalseTotal
unless $self->can_be_inlined 0 68465 68465
989 unless $self->can_be_inlined;
990
991 68465 ▶ return $self->parent->inline_check( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_parent and $self->_is_null_constraint 12279 56186 68465
Condition100%3/3
$self->has_parent and $self->_is_null_constraint
!ll&&!rl&&r
69414924512279
MC/DC100%2/2
$self->has_parent and $self->_is_null_constraint
$self->has_parent $self->_is_null_constraint
Truth table100%3/3
A and B
A= $self->has_parentB= $self->_is_null_constraint
ABresult
0X0
100
111
992 if $self->has_parent && $self->_is_null_constraint;
993 56186 ▶ return '(!!1)'
Branch: 1 branch
BranchTrueFalseTotal
if not $self->has_parent and $self->_is_null_constraint 4328 51858 56186
Condition100%3/3
not $self->has_parent and $self->_is_null_constraint
!ll&&!rl&&r
4924526134328
MC/DC100%2/2
not $self->has_parent and $self->_is_null_constraint
not $self->has_parent $self->_is_null_constraint
Truth table100%3/3
not(A) and B
A= not $self->has_parentB= $self->_is_null_constraint
ABresult
0X0
100
111
994 if !$self->has_parent && $self->_is_null_constraint;
995
996 51858 local $_ = $_[0];
997 51858 my @r = $self->inlined->( $self, @_ );
998 51858 ▶ if ( @r and not defined $r[0] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@r and not defined $r[0]) 7769 44089 51858
Condition66%2/3
@r and not defined $r[0]
!ll&&!rl&&r
0440897769
MC/DC50%1/2
@r and not defined $r[0]
@r not defined $r[0]
Truth table66%2/3
A and not(B)
A= @rB= not defined $r[0]
ABresult
0X0
100
111
999 7769 ▶ _croak 'Inlining type constraint check for "%s" returned undef!', $self
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_parent 0 7769 7769
1000 unless $self->has_parent;
1001 7769 $r[0] = $self->parent->inline_check( @_ );
1002 }
1003 my $r = join " && " => map {
1004 51858 ▶ /\A(?:[A-Z](?:\w)*::[A-Z](?:\w|::)*)\(\$\w+(?:\[\d+\]|\{[^}]+\})?\)\z/i ? $_ :
Branch: 2 branches
BranchTrueFalseTotal
/\A(?:[A-Z](?:\w)*::[A-Z](?:\w|::)*)\(\$\w+(?:\[\d+\]|\{[^}]+\})?\)\z/i ? : 22988 40181 63169
/[;{}]/ && !/\Ado \{.+\}\z/ ? : 10367 29814 40181
Condition100%3/3
/[;{}]/ and not /\Ado \{.+\}\z/
!ll&&!rl&&r
24871494310367
MC/DC100%2/2
/[;{}]/ and not /\Ado \{.+\}\z/
/[;{}]/ not /\Ado \{.+\}\z/
Truth table100%3/3
A and not(B)
A= /[;{}]/B= not /\Ado \{.+\}\z/
ABresult
0X0
100
111
1005 /[;{}]/ && !/\Ado \{.+\}\z/ ? "do { $SafePackage $_ }" :
1006 "($_)"
1007 } @r;
1008 51858 ▶ return @r == 1 ? $r : "($r)";
Branch: 1 branch
BranchTrueFalseTotal
@r == 1 ? : 43434 8424 51858
1009 } #/ sub inline_check
1010  
1011 12368 ▶sub inline_assert {
Subroutine inline_assert: called CC=6 SCAR=17.9
Pod documented
1012 12368 require B;
1013 12368 my $self = shift;
1014 12368 my ( $varname, $typevarname, %extras ) = @_;
1015
1016 12368 ▶ $extras{exception_class} ||= $self->exception_class;
Condition33%1/3
$extras{"exception_class"} ||= $self->exception_class
l!l&&r!l&&!r
0123680
MC/DC0%0/2
$extras{"exception_class"} ||= $self->exception_class
$extras{"exception_class"} $self->exception_class
Truth table33%1/3
A ||= B
A= $extras{"exception_class"}B= $self->exception_class
ABresult
1X1
011
000
1017
1018 12368 my $inline_check;
1019 12368 ▶ if ( $self->can_be_inlined ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->can_be_inlined) { } 12270 98 12368
elsif ($typevarname) { } 97 1 98
1020 12270 $inline_check = sprintf( '(%s)', $self->inline_check( $varname ) );
1021 }
1022 elsif ( $typevarname ) {
1023 97 $inline_check = sprintf( '%s->check(%s)', $typevarname, $varname );
1024 }
1025 else {
1026 1 _croak 'Cannot inline type constraint check for "%s"', $self;
1027 }
1028
1029 12367 my $do_wrapper = !delete $extras{no_wrapper};
1030
1031 12367 my $inline_throw;
1032 12367 ▶ if ( $typevarname ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($typevarname) { } 98 12269 12367
1033 $inline_throw = sprintf(
1034 'Type::Tiny::_failed_check(%s, %s, %s, %s)',
1035 $typevarname,
1036 B::perlstring( "$self" ),
1037 $varname,
1038 join(
1039 98 ',', map +( B::perlstring( $_ ) => B::perlstring( $extras{$_} ) ),
1040 sort keys %extras
1041 ),
1042 );
1043 } #/ if ( $typevarname )
1044 else {
1045 $inline_throw = sprintf(
1046 'Type::Tiny::_failed_check(%s, %s, %s, %s)',
1047 $self->{uniq},
1048 B::perlstring( "$self" ),
1049 $varname,
1050 join(
1051 12269 ',', map +( B::perlstring( $_ ) => B::perlstring( $extras{$_} ) ),
1052 sort keys %extras
1053 ),
1054 );
1055 } #/ else [ if ( $typevarname ) ]
1056
1057 12367 ▶ $do_wrapper
Branch: 1 branch
BranchTrueFalseTotal
$do_wrapper ? : 291 12076 12367
1058 ? qq[do { no warnings "void"; $SafePackage $inline_check or $inline_throw; $varname };]
1059 : qq[ no warnings "void"; $SafePackage $inline_check or $inline_throw; $varname ];
1060 } #/ sub inline_assert
1061  
1062 426 ▶sub _failed_check {
Subroutine _failed_check: called CC=6 SCAR=18.0
1063 426 my ( $self, $name, $value, %attrs ) = @_;
1064 426 ▶ $self = $ALL_TYPES{$self} if defined $self && !ref $self;
Branch: 1 branch
BranchTrueFalseTotal
if defined $self and not ref $self 370 56 426
Condition100%3/3
defined $self and not ref $self
!ll&&!rl&&r
155370
MC/DC100%2/2
defined $self and not ref $self
defined $self not ref $self
Truth table100%3/3
A and not(B)
A= defined $selfB= not ref $self
ABresult
0X0
100
111
1065
1066 my $exception_class = delete( $attrs{exception_class} )
1067 426 ▶ || ( ref $self ? $self->exception_class : 'Error::TypeTiny::Assertion' );
Branch: 1 branch
BranchTrueFalseTotal
ref $self ? : 364 0 364
Condition66%2/3
delete $attrs{'exception_class'} || (ref $self ? $self->exception_class : 'Error::TypeTiny::Assertion')
l!l&&r!l&&!r
623640
MC/DC0%0/2
delete $attrs{'exception_class'} || (ref $self ? $self->exception_class : 'Error::TypeTiny::Assertion')
delete $attrs{'exception_class'} (ref $self ? $self->exception_class : 'Error::TypeTiny::Assertion')
Truth table66%2/3
A || B
A= delete $attrs{'exception_class'}B= (ref $self ? $self->exception_class : 'Error::TypeTiny::Assertion')
ABresult
1X1
011
000
1068 426 my $callback = delete( $attrs{on_die} );
1069  
1070 426 ▶ if ( $self ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self) { } 425 1 426
1071 425 return $exception_class->throw_cb(
1072 $callback,
1073 message => $self->get_message( $value ),
1074 type => $self,
1075 value => $value,
1076 %attrs,
1077 );
1078 }
1079 else {
1080 1 return $exception_class->throw_cb(
1081 $callback,
1082 message => sprintf( '%s did not pass type constraint "%s"', _dd( $value ), $name ),
1083 value => $value,
1084 %attrs,
1085 );
1086 }
1087 } #/ sub _failed_check
1088  
1089 573 ▶sub coerce {
Subroutine coerce: called CC=1 SCAR=0.0
Pod documented
1090 573 my $self = shift;
1091 573 $self->_assert_coercion->coerce( @_ );
1092 }
1093  
1094 4 ▶sub check_coerce {
Subroutine check_coerce: called CC=3 SCAR=14.2
Pod documented
1095 4 my $self = shift;
1096 4 ▶ if ( $self->has_coercion ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_coercion) { } 4 0 4
1097 4 $self->_assert_coercion->check_coerce( @_ ) ;
1098 }
1099 else {
1100 0 ▶ $self->check( @_ ) ? $_[0] : undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->check(@_) ? : 0 0 0
1101 }
1102 }
1103  
1104 64 ▶sub assert_coerce {
Subroutine assert_coerce: called CC=1 SCAR=0.0
Pod documented
1105 64 my $self = shift;
1106 64 $self->_assert_coercion->assert_coerce( @_ );
1107 }
1108  
1109 15734 ▶sub is_parameterizable {
Subroutine is_parameterizable: called CC=1 SCAR=0.0
Pod documented
1110 15734 shift->has_constraint_generator;
1111 }
1112  
1113 489 ▶sub is_parameterized {
Subroutine is_parameterized: called CC=1 SCAR=0.0
Pod documented
1114 489 shift->has_parameters;
1115 }
1116  
1117 {
1118 303 my %seen;
1119
1120 1774 ▶ sub ____make_key {
Subroutine ____make_key: called CC=12 SCAR=25.3
1121 #<<<
1122 join ',', map {
1123 1774 Types::TypeTiny::is_TypeTiny( $_ ) ? sprintf( '$Type::Tiny::ALL_TYPES{%s}', defined( $_->{uniq} ) ? $_->{uniq} : '____CANNOT_KEY____' ) :
1124 7 ▶ ref() eq 'ARRAY' ? do { $seen{$_}++ ? '____CANNOT_KEY____' : sprintf( '[%s]', ____make_key( @$_ ) ) } :
Branch: 2 branches
BranchTrueFalseTotal
$seen{$_}++ ? : 0 7 7
ref $_ eq 'HASH' ? : 18 4476 4494
1125 18 ▶ ref() eq 'HASH' ? do { $seen{$_}++ ? '____CANNOT_KEY____' : sprintf( '{%s}', ____make_key( do { my %h = %$_; map +( $_, $h{$_} ), sort keys %h; } ) ) } :
Branch: 2 branches
BranchTrueFalseTotal
$seen{$_}++ ? : 0 18 18
ref $_ eq 'SCALAR' || ref $_ eq 'REF' ? : 3 4473 4476
Condition66%2/3
ref $_ eq "SCALAR" or ref $_ eq "REF"
l!l&&r!l&&!r
304473
MC/DC50%1/2
ref $_ eq "SCALAR" or ref $_ eq "REF"
ref $_ eq "SCALAR" ref $_ eq "REF"
Truth table66%2/3
A or B
A= ref $_ eq "SCALAR"B= ref $_ eq "REF"
ABresult
1X1
011
000
1126 3 ▶ ref() eq 'SCALAR' || ref() eq 'REF' ? do { $seen{$_}++ ? '____CANNOT_KEY____' : sprintf( '\\(%s)', ____make_key( $$_ ) ) } :
Branch: 3 branches
BranchTrueFalseTotal
$seen{$_}++ ? : 0 3 3
!defined($_) ? : 3 4470 4473
!ref($_) ? : 4428 42 4470
1127 !defined() ? 'undef' :
1128 7512 ▶ !ref() ? do { require B; B::perlstring( $_ ) } :
Branch: 3 branches
BranchTrueFalseTotal
Types::TypeTiny::is_TypeTiny($_) ? : 3011 4501 7512
defined $_->{'uniq'} ? : 3011 0 3011
ref $_ eq 'ARRAY' ? : 7 4494 4501
1129 '____CANNOT_KEY____';
1130 } @_;
1131 #>>>
1132 } #/ sub ____make_key
1133 303 my %param_cache;
1134
1135 1744 ▶ sub parameterize {
Subroutine parameterize: called CC=16 SCAR=27.8
Pod documented
1136 1744 my $self = shift;
1137
1138 1744 ▶ $self->is_parameterizable
Branch: 2 branches
BranchTrueFalseTotal
$self->is_parameterizable or @_ ? &_croak("Type '%s' does not accept parameters", "$self") : (return $self) 1744 0 1744
@_ ? : 0 0 0
1139 or @_
1140 ? _croak( "Type '%s' does not accept parameters", "$self" )
1141 : return ( $self );
1142
1143 1744 @_ = map Types::TypeTiny::to_TypeTiny( $_ ), @_;
1144
1145 # Generate a key for caching parameterized type constraints,
1146 # but only if all the parameters are strings or type constraints.
1147 1744 %seen = ();
1148 1744 my $key = $self->____make_key( @_ );
1149 1744 ▶ undef( $key ) if $key =~ /____CANNOT_KEY____/;
Branch: 1 branch
BranchTrueFalseTotal
if $key =~ /____CANNOT_KEY____/ 37 1707 1744
1150 1744 ▶ return $param_cache{$key} if defined $key && defined $param_cache{$key};
Branch: 1 branch
BranchTrueFalseTotal
if defined $key and defined $param_cache{$key} 414 1330 1744
Condition100%3/3
defined $key and defined $param_cache{$key}
!ll&&!rl&&r
371293414
MC/DC100%2/2
defined $key and defined $param_cache{$key}
defined $key defined $param_cache{$key}
Truth table100%3/3
A and B
A= defined $keyB= defined $param_cache{$key}
ABresult
0X0
100
111
1151
1152 1330 local $Type::Tiny::parameterize_type = $self;
1153 1330 local $_ = $_[0];
1154 1330 my $P;
1155
1156 1330 my ( $constraint, $compiled ) = $self->constraint_generator->( @_ );
1157
1158 1287 ▶ if ( Types::TypeTiny::is_TypeTiny( $constraint ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (Types::TypeTiny::is_TypeTiny($constraint)) { } 423 864 1287
1159 423 $P = $constraint;
1160 }
1161 else {
1162 864 my %options = (
1163 constraint => $constraint,
1164 display_name => $self->name_generator->( $self, @_ ),
1165 parameters => [@_],
1166 );
1167 864 ▶ $options{compiled_type_constraint} = $compiled
Branch: 1 branch
BranchTrueFalseTotal
if $compiled 215 649 864
1168 if $compiled;
1169 864 ▶ $options{inlined} = $self->inline_generator->( @_ )
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_inline_generator 854 10 864
1170 if $self->has_inline_generator;
1171 $options{type_default} = $self->{type_default_generator}->( @_ )
1172 864 ▶ if exists $self->{type_default_generator}; # undocumented
Branch: 1 branch
BranchTrueFalseTotal
if exists $self->{"type_default_generator"} 308 556 864
1173 exists $options{$_} && !defined $options{$_} && delete $options{$_}
1174 864 ▶ for keys %options;
Branch: 1 branch
BranchTrueFalseTotal
exists $options{$_} and not defined $options{$_} and delete $options{$_} 40 3929 3969
Condition66%2/3
exists $options{$_} and not defined $options{$_}
!ll&&!rl&&r
0392940
MC/DC50%1/2
exists $options{$_} and not defined $options{$_}
exists $options{$_} not defined $options{$_}
Truth table66%2/3
A and not(B)
A= exists $options{$_}B= not defined $options{$_}
ABresult
0X0
100
111
1175
1176 864 $P = $self->create_child_type( %options );
1177
1178 864 ▶ if ( $self->has_coercion_generator ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_coercion_generator) 454 410 864
1179 454 my @args = @_;
1180 214 ▶ $P->{_build_coercion} = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
1181 214 my $coercion = shift;
1182 214 my $built = $self->coercion_generator->( $self, $P, @args );
1183 214 ▶ $coercion->add_type_coercions( @{ $built->type_coercion_map } ) if $built;
Branch: 1 branch
BranchTrueFalseTotal
if $built 111 103 214
1184 214 $coercion->freeze;
1185 454 };
1186 }
1187 } #/ else [ if ( Types::TypeTiny::is_TypeTiny...)]
1188
1189 1287 ▶ if ( defined $key ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $key) 1251 36 1287
1190 1251 $param_cache{$key} = $P;
1191 1251 Scalar::Util::weaken( $param_cache{$key} );
1192 }
1193
1194 1287 ▶ $P->coercion->freeze unless $self->has_coercion_generator;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->has_coercion_generator 830 457 1287
1195
1196 1287 return $P;
1197 } #/ sub parameterize
1198 }
1199  
1200 303 ▶sub check_parameter_count_for_parameterized_type {
Subroutine check_parameter_count_for_parameterized_type: called CC=8 SCAR=21.2
Pod undocumented
1201 914 my ( $library, $type_name, $args, $max_args, $min_args ) = @_;
1202 914 ▶ $args = @$args if ref $args;
Branch: 1 branch
BranchTrueFalseTotal
if ref $args 914 0 914
1203
1204 914 ▶ if ( ( defined $max_args and $args > $max_args ) or ( defined $min_args and $args < $min_args ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $max_args and $args > $max_args or defined $min_args and $args < $min_args) 2 912 914
Condition88%8/9
defined $max_args and $args > $max_args or defined $min_args and $args < $min_args
l!l&&r!l&&!r
11912
defined $max_args and $args > $max_args
!ll&&!rl&&r
09131
defined $min_args and $args < $min_args
!ll&&!rl&&r
845671
MC/DC75%3/4
defined $max_args and $args > $max_args or defined $min_args and $args < $min_args
defined $max_args $args > $max_args defined $min_args $args < $min_args
Truth table57%4/7
A and B or C and D
A= defined $max_argsB= $args > $max_argsC= defined $min_argsD= $args < $min_args
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
1205 2 require Error::TypeTiny::WrongNumberOfParameters;
1206 2 ▶ Error::TypeTiny::WrongNumberOfParameters->throw(
Branch: 2 branches
BranchTrueFalseTotal
defined $min_args ? : 2 0 2
defined $max_args ? : 2 0 2
1207 target => "$library\::$type_name\[]",
1208 ( defined $min_args ) ? ( minimum => $min_args ) : (),
1209 ( defined $max_args ) ? ( maximum => $max_args ) : (),
1210 got => $args,
1211 );
1212 }
1213
1214 912 return;
1215 }
1216  
1217 1507 ▶sub child_type_class {
Subroutine child_type_class: called CC=1 SCAR=0.0
Pod documented
1218 1507 __PACKAGE__;
1219 }
1220  
1221 1507 ▶sub create_child_type {
Subroutine create_child_type: called CC=2 SCAR=6.9
Pod documented
1222 1507 my $self = shift;
1223 1507 my %moreopts;
1224 1507 ▶ $moreopts{is_object} = 1 if $self->{is_object};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"is_object"} 27 1480 1507
1225 1507 return $self->child_type_class->new( parent => $self, %moreopts, @_ );
1226 }
1227  
1228 81 ▶sub complementary_type {
Subroutine complementary_type: called CC=3 SCAR=11.0
Pod documented
1229 81 my $self = shift;
1230 81 ▶ my $r = ( $self->{complementary_type} ||= $self->_build_complementary_type );
Condition66%2/3
$self->{"complementary_type"} ||= $self->_build_complementary_type
l!l&&r!l&&!r
12690
MC/DC0%0/2
$self->{"complementary_type"} ||= $self->_build_complementary_type
$self->{"complementary_type"} $self->_build_complementary_type
Truth table66%2/3
A ||= B
A= $self->{"complementary_type"}B= $self->_build_complementary_type
ABresult
1X1
011
000
1231 Scalar::Util::weaken( $self->{complementary_type} )
1232 81 ▶ unless Scalar::Util::isweak( $self->{complementary_type} );
Branch: 1 branch
BranchTrueFalseTotal
unless builtin::is_weak($self->{"complementary_type"}) 71 10 81
1233 81 return $r;
1234 }
1235  
1236 69 ▶sub _build_complementary_type {
Subroutine _build_complementary_type: called CC=3 SCAR=11.0
1237 69 my $self = shift;
1238 my %opts = (
1239 112 ▶ constraint => sub { not $self->check( $_ ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
1240 69 display_name => sprintf( "~%s", $self ),
1241 );
1242 69 $opts{display_name} =~ s/^\~{2}//;
1243 309 ▶ $opts{inlined} = sub { shift; "not(" . $self->inline_check( @_ ) . ")" }
Subroutine __ANON__: called CC=1 SCAR=0.0
1244 69 ▶ if $self->can_be_inlined;
Branch: 1 branch
BranchTrueFalseTotal
if $self->can_be_inlined 63 6 69
1245 $opts{display_name} = $opts{name} = $self->{complement_name}
1246 69 ▶ if $self->{complement_name};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"complement_name"} 2 67 69
1247 69 return "Type::Tiny"->new( %opts );
1248 } #/ sub _build_complementary_type
1249  
1250 0 ▶sub _instantiate_moose_type {
Subroutine _instantiate_moose_type: not called CC=1 SCAR=6.9
1251 0 my $self = shift;
1252 0 my %opts = @_;
1253 0 require Moose::Meta::TypeConstraint;
1254 0 return "Moose::Meta::TypeConstraint"->new( %opts );
1255 }
1256  
1257 0 ▶sub _build_moose_type {
Subroutine _build_moose_type: not called CC=9 SCAR=45.0
1258 0 my $self = shift;
1259
1260 0 my $r;
1261 0 ▶ if ( $self->{_is_core} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'_is_core'}) { } 0 0 0
1262 0 require Moose::Util::TypeConstraints;
1263 0 $r = Moose::Util::TypeConstraints::find_type_constraint( $self->name );
1264 0 $r->{"Types::TypeTiny::to_TypeTiny"} = $self;
1265 0 Scalar::Util::weaken( $r->{"Types::TypeTiny::to_TypeTiny"} );
1266 }
1267 else {
1268 # Type::Tiny is more flexible than Moose, allowing
1269 # inlined to return a list. So we need to wrap the
1270 # inlined coderef to make sure Moose gets a single
1271 # string.
1272 #
1273 0 ▶ my $wrapped_inlined = sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
1274 0 shift;
1275 0 $self->inline_check( @_ );
1276 0 };
1277
1278 0 my %opts;
1279 0 ▶ $opts{name} = $self->qualified_name if $self->has_library && !$self->is_anon;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_library and not $self->is_anon 0 0 0
Condition0%0/3
$self->has_library and not $self->is_anon
!ll&&!rl&&r
000
MC/DC0%0/2
$self->has_library and not $self->is_anon
$self->has_library not $self->is_anon
Truth table0%0/3
A and not(B)
A= $self->has_libraryB= not $self->is_anon
ABresult
0X0
100
111
1280 0 ▶ $opts{parent} = $self->parent->moose_type if $self->has_parent;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_parent 0 0 0
1281 0 ▶ $opts{constraint} = $self->constraint unless $self->_is_null_constraint;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_null_constraint 0 0 0
1282 0 ▶ $opts{message} = $self->message if $self->has_message;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_message 0 0 0
1283 0 ▶ $opts{inlined} = $wrapped_inlined if $self->has_inlined;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_inlined 0 0 0
1284
1285 0 $r = $self->_instantiate_moose_type( %opts );
1286 0 $r->{"Types::TypeTiny::to_TypeTiny"} = $self;
1287 0 $self->{moose_type} = $r; # prevent recursion
1288 0 ▶ $r->coercion( $self->coercion->moose_coercion ) if $self->has_coercion;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_coercion 0 0 0
1289 } #/ else [ if ( $self->{_is_core})]
1290
1291 0 return $r;
1292 } #/ sub _build_moose_type
1293  
1294 0 ▶sub _build_mouse_type {
Subroutine _build_mouse_type: not called CC=7 SCAR=40.3
1295 0 my $self = shift;
1296
1297 0 my %options;
1298 0 ▶ $options{name} = $self->qualified_name if $self->has_library && !$self->is_anon;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_library and not $self->is_anon 0 0 0
Condition0%0/3
$self->has_library and not $self->is_anon
!ll&&!rl&&r
000
MC/DC0%0/2
$self->has_library and not $self->is_anon
$self->has_library not $self->is_anon
Truth table0%0/3
A and not(B)
A= $self->has_libraryB= not $self->is_anon
ABresult
0X0
100
111
1299 0 ▶ $options{parent} = $self->parent->mouse_type if $self->has_parent;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_parent 0 0 0
1300 0 ▶ $options{constraint} = $self->constraint unless $self->_is_null_constraint;
Branch: 1 branch
BranchTrueFalseTotal
unless $self->_is_null_constraint 0 0 0
1301 0 ▶ $options{message} = $self->message if $self->has_message;
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_message 0 0 0
1302
1303 0 require Mouse::Meta::TypeConstraint;
1304 0 my $r = "Mouse::Meta::TypeConstraint"->new( %options );
1305
1306 0 $self->{mouse_type} = $r; # prevent recursion
1307 0 ▶ $r->_add_type_coercions(
Branch: 1 branch
BranchTrueFalseTotal
if $self->has_coercion 0 0 0
1308 $self->coercion->freeze->_codelike_type_coercion_map( 'mouse_type' ) )
1309 if $self->has_coercion;
1310
1311 0 return $r;
1312 } #/ sub _build_mouse_type
1313  
1314 14591 ▶sub exportables {
Subroutine exportables: called CC=15 SCAR=27.2
Pod documented
1315 14591 my ( $self, $base_name, $tag ) = ( shift, @_ ); # $tag is undocumented
1316 14591 ▶ if ( not $self->is_anon ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->is_anon) 14590 1 14591
1317 14590 ▶ $base_name ||= $self->name;
Condition66%2/3
$base_name ||= $self->name
l!l&&r!l&&!r
13145770
MC/DC0%0/2
$base_name ||= $self->name
$base_name $self->name
Truth table66%2/3
A ||= B
A= $base_nameB= $self->name
ABresult
1X1
011
000
1318 }
1319 14591 ▶ $tag ||= 0;
Condition100%2/2
$tag ||= 0
l!l
73613855
MC/DC100%1/1
$tag ||= 0
$tag
Truth table100%2/2
A
A= $tag
Aresult
11
00
1320  
1321 14591 my @exportables;
1322 14591 ▶ return \@exportables if ! $base_name;
Branch: 1 branch
BranchTrueFalseTotal
unless $base_name 0 14591 14591
1323  
1324 14591 require Eval::TypeTiny;
1325  
1326 14591 ▶ push @exportables, {
Branch: 1 branch
BranchTrueFalseTotal
if $tag eq "types" or not $tag 13855 736 14591
Condition66%2/3
$tag eq "types" or not $tag
l!l&&r!l&&!r
013855736
MC/DC50%1/2
$tag eq "types" or not $tag
$tag eq "types" not $tag
Truth table66%2/3
A or not(B)
A= $tag eq "types"B= not $tag
ABresult
1X1
011
000
1327 name => $base_name,
1328 code => Eval::TypeTiny::type_to_coderef( $self ),
1329 tags => [ 'types' ],
1330 } if $tag eq 'types' || !$tag;
1331  
1332 14591 ▶ push @exportables, {
Branch: 1 branch
BranchTrueFalseTotal
if $tag eq "is" or not $tag 13856 735 14591
Condition100%3/3
$tag eq "is" or not $tag
l!l&&r!l&&!r
113855735
MC/DC100%2/2
$tag eq "is" or not $tag
$tag eq "is" not $tag
Truth table100%3/3
A or not(B)
A= $tag eq "is"B= not $tag
ABresult
1X1
011
000
1333 name => sprintf( 'is_%s', $base_name ),
1334 code => $self->compiled_check,
1335 tags => [ 'is' ],
1336 } if $tag eq 'is' || !$tag;
1337  
1338 14591 ▶ push @exportables, {
Branch: 1 branch
BranchTrueFalseTotal
if $tag eq "assert" or not $tag 13855 736 14591
Condition66%2/3
$tag eq "assert" or not $tag
l!l&&r!l&&!r
013855736
MC/DC50%1/2
$tag eq "assert" or not $tag
$tag eq "assert" not $tag
Truth table66%2/3
A or not(B)
A= $tag eq "assert"B= not $tag
ABresult
1X1
011
000
1339 name => sprintf( 'assert_%s', $base_name ),
1340 code => $self->_overload_coderef,
1341 tags => [ 'assert' ],
1342 } if $tag eq 'assert' || !$tag;
1343  
1344 push @exportables, {
1345 name => sprintf( 'to_%s', $base_name ),
1346 code => $self->has_coercion && $self->coercion->frozen
1347 ? $self->coercion->compiled_coercion
1348 4 ▶ : sub ($) { $self->coerce( $_[0] ) },
Subroutine to_Map: called CC=1 SCAR=0.0
Subroutine to_Value: called CC=1 SCAR=0.0
1349 14591 ▶ tags => [ 'to' ],
Branch: 2 branches
BranchTrueFalseTotal
if $tag eq "to" or not $tag 14590 1 14591
$self->has_coercion && $self->coercion->frozen ? : 960 13630 14590
Condition100%6/6
$tag eq "to" or not $tag
l!l&&r!l&&!r
735138551
$self->has_coercion and $self->coercion->frozen
!ll&&!rl&&r
136237960
MC/DC100%2/2
$tag eq "to" or not $tag
$tag eq "to" not $tag
MC/DC100%2/2
$self->has_coercion and $self->coercion->frozen
$self->has_coercion $self->coercion->frozen
Truth table100%3/3
A or not(B)
A= $tag eq "to"B= not $tag
ABresult
1X1
011
000
Truth table100%3/3
A and B
A= $self->has_coercionB= $self->coercion->frozen
ABresult
0X0
100
111
1350 } if $tag eq 'to' || !$tag;
1351  
1352 14591 return \@exportables;
1353 }
1354  
1355 736 ▶sub exportables_by_tag {
Subroutine exportables_by_tag: called CC=4 SCAR=14.0
Pod documented
1356 736 my ( $self, $tag, $base_name ) = ( shift, @_ );
1357 my @matched = grep {
1358 736 my $e = $_;
1359 736 ▶ grep $_ eq $tag, @{ $e->{tags} || [] };
Condition50%1/2
$e->{'tags'} || []
l!l
7360
MC/DC0%0/1
$e->{'tags'} || []
$e->{'tags'}
Truth table50%1/2
A
A= $e->{'tags'}
Aresult
11
00
1360 736 } @{ $self->exportables( $base_name, $tag ) };
1361 736 ▶ return @matched if wantarray;
Branch: 1 branch
BranchTrueFalseTotal
if wantarray 735 1 736
1362 1 ▶ _croak( 'Expected to find one exportable tagged "%s", found %d', $tag, scalar @matched )
Branch: 1 branch
BranchTrueFalseTotal
unless @matched == 1 0 1 1
1363 unless @matched == 1;
1364 1 return $matched[0];
1365 }
1366  
1367 93 ▶sub _process_coercion_list {
Subroutine _process_coercion_list: called CC=8 SCAR=21.0
1368 93 my $self = shift;
1369
1370 93 my @pairs;
1371 93 ▶ while ( @_ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 97 93 190
1372 97 my $next = shift;
1373 97 ▶ if ( blessed( $next )
Branch: 3 branches
BranchTrueFalseTotal
if (builtin::blessed($next) and $next->isa('Type::Coercion') and $next->is_parameterized) { } 7 90 97
elsif (builtin::blessed($next) and $next->can('type_coercion_map')) { } 9 81 90
elsif (ref $next eq 'ARRAY') { } 0 81 81
Condition83%5/6
builtin::blessed($next) and $next->isa("Type::Coercion") and $next->is_parameterized
!ll&&!rl&&r
8197
builtin::blessed($next) and $next->isa("Type::Coercion")
!ll&&!rl&&r
08116
MC/DC66%2/3
builtin::blessed($next) and $next->isa("Type::Coercion") and $next->is_parameterized
builtin::blessed($next) $next->isa("Type::Coercion") $next->is_parameterized
Truth table75%3/4
A and B and C
A= builtin::blessed($next)B= $next->isa("Type::Coercion")C= $next->is_parameterized
ABCresult
0XX0
10X0
1100
1111
1374 and $next->isa( 'Type::Coercion' )
1375 and $next->is_parameterized )
1376 {
1377 7 push @pairs => ( @{ $next->_reparameterize( $self )->type_coercion_map } );
1378 }
1379 ▶ elsif ( blessed( $next ) and $next->can( 'type_coercion_map' ) ) {
Condition66%2/3
builtin::blessed($next) and $next->can("type_coercion_map")
!ll&&!rl&&r
0819
MC/DC50%1/2
builtin::blessed($next) and $next->can("type_coercion_map")
builtin::blessed($next) $next->can("type_coercion_map")
Truth table66%2/3
A and B
A= builtin::blessed($next)B= $next->can("type_coercion_map")
ABresult
0X0
100
111
1380 push @pairs => (
1381 9 @{ $next->type_coercion_map },
1382 );
1383 }
1384 elsif ( ref( $next ) eq q(ARRAY) ) {
1385 0 unshift @_, @$next;
1386 }
1387 else {
1388 81 push @pairs => (
1389 Types::TypeTiny::to_TypeTiny( $next ),
1390 shift,
1391 );
1392 }
1393 } #/ while ( @_ )
1394
1395 93 return @pairs;
1396 } #/ sub _process_coercion_list
1397  
1398 90 ▶sub plus_coercions {
Subroutine plus_coercions: called CC=1 SCAR=0.0
Pod documented
1399 90 my $self = shift;
1400 90 my $new = $self->_clone;
1401 $new->coercion->add_type_coercions(
1402 $self->_process_coercion_list( @_ ),
1403 90 @{ $self->coercion->type_coercion_map },
1404 );
1405 90 $new->coercion->freeze;
1406 90 return $new;
1407 } #/ sub plus_coercions
1408  
1409 2 ▶sub plus_fallback_coercions {
Subroutine plus_fallback_coercions: called CC=1 SCAR=0.0
Pod documented
1410 2 my $self = shift;
1411
1412 2 my $new = $self->_clone;
1413 $new->coercion->add_type_coercions(
1414 2 @{ $self->coercion->type_coercion_map },
1415 $self->_process_coercion_list( @_ ),
1416 );
1417 2 $new->coercion->freeze;
1418 2 return $new;
1419 } #/ sub plus_fallback_coercions
1420  
1421 1 ▶sub minus_coercions {
Subroutine minus_coercions: called CC=5 SCAR=16.1
Pod documented
1422 1 my $self = shift;
1423
1424 1 my $new = $self->_clone;
1425 1 my @not = grep Types::TypeTiny::is_TypeTiny( $_ ),
1426 $self->_process_coercion_list( $new, @_ );
1427
1428 1 my @keep;
1429 1 my $c = $self->coercion->type_coercion_map;
1430 1 ▶ for ( my $i = 0 ; $i <= $#$c ; $i += 2 ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($i <= $c->$#*) 4 1 5
1431 4 my $keep_this = 1;
1432 4 NOT: for my $n ( @not ) {
1433 11 ▶ if ( $c->[$i] == $n ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->[$i] == $n) 2 9 11
1434 2 $keep_this = 0;
1435 2 last NOT;
1436 }
1437 }
1438
1439 4 ▶ push @keep, $c->[$i], $c->[ $i + 1 ] if $keep_this;
Branch: 1 branch
BranchTrueFalseTotal
if $keep_this 2 2 4
1440 } #/ for ( my $i = 0 ; $i <=...)
1441
1442 1 $new->coercion->add_type_coercions( @keep );
1443 1 $new->coercion->freeze;
1444 1 return $new;
1445 } #/ sub minus_coercions
1446  
1447 4 ▶sub no_coercions {
Subroutine no_coercions: called CC=1 SCAR=0.0
Pod documented
1448 4 my $new = shift->_clone;
1449 4 $new->coercion->freeze;
1450 4 $new;
1451 }
1452  
1453 16 ▶sub coercibles {
Subroutine coercibles: called CC=2 SCAR=6.9
Pod documented
1454 16 my $self = shift;
1455 16 ▶ $self->has_coercion ? $self->coercion->_source_type_union : $self;
Branch: 1 branch
BranchTrueFalseTotal
$self->has_coercion ? : 4 12 16
1456 }
1457  
1458 281305 ▶sub isa {
Subroutine isa: called CC=11 SCAR=40.4
Pod documented
1459 281305 my $self = shift;
1460
1461 281305 ▶ if ( $INC{"Moose/Meta/TypeConstraint.pm"}
Branch: 1 branch
BranchTrueFalseTotal
if ($INC{"Moose/Meta/TypeConstraint.pm"} and ref $self and $_[0] =~ /^(?:Class::MOP|MooseX?::Meta)::(.+)$/) 0 281305 281305
Condition33%2/6
$INC{"Moose/Meta/TypeConstraint.pm"} and ref $self and $_[0] =~ /^(?:Class::MOP|MooseX?::Meta)::(.+)$/
!ll&&!rl&&r
28130500
$INC{"Moose/Meta/TypeConstraint.pm"} and ref $self
!ll&&!rl&&r
28130500
MC/DC0%0/3
$INC{"Moose/Meta/TypeConstraint.pm"} and ref $self and $_[0] =~ /^(?:Class::MOP|MooseX?::Meta)::(.+)$/
$INC{"Moose/Meta/TypeConstraint.pm"} ref $self $_[0] =~ /^(?:Class::MOP|MooseX?::Meta)::(.+)$/
Truth table25%1/4
A and B and C
A= $INC{"Moose/Meta/TypeConstraint.pm"}B= ref $selfC= $_[0] =~ /^(?:Class::MOP|MooseX?::Meta)::(.+)$/
ABCresult
0XX0
10X0
1100
1111
1462 and ref( $self )
1463 and $_[0] =~ /^(?:Class::MOP|MooseX?::Meta)::(.+)$/ )
1464 {
1465 0 my $meta = $1;
1466
1467 0 ▶ return !!1 if $meta eq 'TypeConstraint';
Branch: 1 branch
BranchTrueFalseTotal
if $meta eq "TypeConstraint" 0 0 0
1468 0 ▶ return $self->is_parameterized if $meta eq 'TypeConstraint::Parameterized';
Branch: 1 branch
BranchTrueFalseTotal
if $meta eq "TypeConstraint::Parameterized" 0 0 0
1469 0 ▶ return $self->is_parameterizable if $meta eq 'TypeConstraint::Parameterizable';
Branch: 1 branch
BranchTrueFalseTotal
if $meta eq "TypeConstraint::Parameterizable" 0 0 0
1470 0 ▶ return $self->isa( 'Type::Tiny::Union' ) if $meta eq 'TypeConstraint::Union';
Branch: 1 branch
BranchTrueFalseTotal
if $meta eq "TypeConstraint::Union" 0 0 0
1471
1472 0 my $inflate = $self->moose_type;
1473 0 return $inflate->isa( @_ );
1474 } #/ if ( $INC{"Moose/Meta/TypeConstraint.pm"} ...)
1475
1476 281305 ▶ if ( $INC{"Mouse.pm"}
Branch: 1 branch
BranchTrueFalseTotal
if ($INC{"Mouse.pm"} and ref $self and $_[0] eq "Mouse::Meta::TypeConstraint") 0 281305 281305
Condition33%2/6
$INC{"Mouse.pm"} and ref $self and $_[0] eq "Mouse::Meta::TypeConstraint"
!ll&&!rl&&r
28130500
$INC{"Mouse.pm"} and ref $self
!ll&&!rl&&r
28130500
MC/DC0%0/3
$INC{"Mouse.pm"} and ref $self and $_[0] eq "Mouse::Meta::TypeConstraint"
$INC{"Mouse.pm"} ref $self $_[0] eq "Mouse::Meta::TypeConstraint"
Truth table25%1/4
A and B and C
A= $INC{"Mouse.pm"}B= ref $selfC= $_[0] eq "Mouse::Meta::TypeConstraint"
ABCresult
0XX0
10X0
1100
1111
1477 and ref( $self )
1478 and $_[0] eq 'Mouse::Meta::TypeConstraint' )
1479 {
1480 0 return !!1;
1481 }
1482
1483 281305 $self->SUPER::isa( @_ );
1484 } #/ sub isa
1485  
1486 156 ▶sub _build_my_methods {
Subroutine _build_my_methods: called CC=1 SCAR=0.0
1487 156 return {};
1488 }
1489  
1490 1326 ▶sub _lookup_my_method {
Subroutine _lookup_my_method: called CC=3 SCAR=11.0
1491 1326 my $self = shift;
1492 1326 my ( $name ) = @_;
1493
1494 1326 ▶ if ( $self->my_methods->{$name} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->my_methods->{$name}) 638 688 1326
1495 638 return $self->my_methods->{$name};
1496 }
1497
1498 688 ▶ if ( $self->has_parent ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->has_parent) 686 2 688
1499 686 return $self->parent->_lookup_my_method( @_ );
1500 }
1501
1502 2 return;
1503 } #/ sub _lookup_my_method
1504  
1505 303 my %object_methods = (
1506 with_attribute_values => 1, stringifies_to => 1,
1507 numifies_to => 1
1508 );
1509  
1510 303 my $re_list_methods = qr/\A(?:(?:a(?:ll|ny|ssert_a(?:ll|ny))|first|grep|map|rsort|sort))\z/;
1511  
1512 82739 ▶sub can {
Subroutine can: called CC=15 SCAR=28.8
Pod documented
1513 82739 my $self = shift;
1514
1515 82739 ▶ return !!0
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] eq "type_parameter" and builtin::blessed($_[0]) and $_[0]->has_parameters 0 82739 82739
Condition50%3/6
$_[0] eq "type_parameter" and builtin::blessed($_[0]) and $_[0]->has_parameters
!ll&&!rl&&r
8273900
$_[0] eq "type_parameter" and builtin::blessed($_[0])
!ll&&!rl&&r
8273810
MC/DC0%0/3
$_[0] eq "type_parameter" and builtin::blessed($_[0]) and $_[0]->has_parameters
$_[0] eq "type_parameter" builtin::blessed($_[0]) $_[0]->has_parameters
Truth table50%2/4
A and B and C
A= $_[0] eq "type_parameter"B= builtin::blessed($_[0])C= $_[0]->has_parameters
ABCresult
0XX0
10X0
1100
1111
1516 if $_[0] eq 'type_parameter'
1517 && blessed( $_[0] )
1518 && $_[0]->has_parameters;
1519
1520 82739 my $can = $self->SUPER::can( @_ );
1521 82739 ▶ return $can if $can;
Branch: 1 branch
BranchTrueFalseTotal
if $can 40437 42302 82739
1522
1523 42302 ▶ if ( ref( $self ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) 42301 1 42302
1524 42301 ▶ if ( $_[0] =~ /\Amy_(.+)\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /\Amy_(.+)\z/) 4 42297 42301
1525 4 my $method = $self->_lookup_my_method( $1 );
1526 4 ▶ return $method if $method;
Branch: 1 branch
BranchTrueFalseTotal
if $method 2 2 4
1527 }
1528 42299 ▶ if ( $self->{is_object} && $object_methods{ $_[0] } ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"is_object"} and $object_methods{$_[0]}) 1 42298 42299
Condition100%3/3
$self->{"is_object"} and $object_methods{$_[0]}
!ll&&!rl&&r
4229621
MC/DC100%2/2
$self->{"is_object"} and $object_methods{$_[0]}
$self->{"is_object"} $object_methods{$_[0]}
Truth table100%3/3
A and B
A= $self->{"is_object"}B= $object_methods{$_[0]}
ABresult
0X0
100
111
1529 1 require Type::Tiny::ConstrainedObject;
1530 1 return Type::Tiny::ConstrainedObject->can( $_[0] );
1531 }
1532 42298 ▶ if ( $_[0] =~ $re_list_methods ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_[0] =~ /$re_list_methods/) 36 42262 42298
1533 36 my $util = $_[0];
1534 36 ▶ $self->{'_util'}{$util} ||= eval { $self->_build_util( $util ) };
Condition66%2/3
$self->{"_util"}{$util} ||= eval { do { $self->_build_util($util) } }
l!l&&r!l&&!r
0342
MC/DC50%1/2
$self->{"_util"}{$util} ||= eval { do { $self->_build_util($util) } }
$self->{"_util"}{$util} eval { do { $self->_build_util($util) } }
Truth table66%2/3
A ||= B
A= $self->{"_util"}{$util}B= eval { do { $self->_build_util($util) } }
ABresult
1X1
011
000
1535 36 ▶ return unless $self->{'_util'}{$util};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"_util"}{$util} 2 34 36
1536 0 ▶ return sub { my $s = shift; $s->{'_util'}{$util}( @_ ) };
Subroutine __ANON__: not called CC=1 SCAR=2.6
1537 }
1538 42262 ▶ if ( $INC{"Moose/Meta/TypeConstraint.pm"} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($INC{"Moose/Meta/TypeConstraint.pm"}) 0 42262 42262
1539 0 my $method = $self->moose_type->can( @_ );
1540 0 ▶ return sub { shift->moose_type->$method( @_ ) }
Subroutine __ANON__: not called CC=1 SCAR=6.9
1541 0 ▶ if $method;
Branch: 1 branch
BranchTrueFalseTotal
if $method 0 0 0
1542 }
1543 } #/ if ( ref( $self ) )
1544
1545 42263 return;
1546 } #/ sub can
1547  
1548 1803 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=12 SCAR=26.8
1549 1803 my $self = shift;
1550 1803 my ( $m ) = ( our $AUTOLOAD =~ /::(\w+)$/ );
1551 1803 ▶ return if $m eq 'DESTROY';
Branch: 1 branch
BranchTrueFalseTotal
if $m eq "DESTROY" 0 1803 1803
1552
1553 1803 ▶ if ( ref( $self ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self) 1803 0 1803
1554 1803 ▶ if ( $m =~ /\Amy_(.+)\z/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($m =~ /\Amy_(.+)\z/) 636 1167 1803
1555 636 my $method = $self->_lookup_my_method( $1 );
1556 636 ▶ return &$method( $self, @_ ) if $method;
Branch: 1 branch
BranchTrueFalseTotal
if $method 636 0 636
1557 }
1558 1167 ▶ if ( $self->{is_object} && $object_methods{$m} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"is_object"} and $object_methods{$m}) 3 1164 1167
Condition66%2/3
$self->{"is_object"} and $object_methods{$m}
!ll&&!rl&&r
116403
MC/DC50%1/2
$self->{"is_object"} and $object_methods{$m}
$self->{"is_object"} $object_methods{$m}
Truth table66%2/3
A and B
A= $self->{"is_object"}B= $object_methods{$m}
ABresult
0X0
100
111
1559 3 require Type::Tiny::ConstrainedObject;
1560 3 unshift @_, $self;
1561 303 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
1562 3 goto \&{"Type::Tiny::ConstrainedObject::$m"};
1563 }
1564 1164 ▶ if ( $m =~ $re_list_methods ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($m =~ /$re_list_methods/) 1163 1 1164
1565 1163 ▶ return ( $self->{'_util'}{$m} ||= $self->_build_util( $m ) )->( @_ );
Condition66%2/3
$self->{"_util"}{$m} ||= $self->_build_util($m)
l!l&&r!l&&!r
9951680
MC/DC0%0/2
$self->{"_util"}{$m} ||= $self->_build_util($m)
$self->{"_util"}{$m} $self->_build_util($m)
Truth table66%2/3
A ||= B
A= $self->{"_util"}{$m}B= $self->_build_util($m)
ABresult
1X1
011
000
1566 }
1567 1 ▶ if ( $INC{"Moose/Meta/TypeConstraint.pm"} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($INC{"Moose/Meta/TypeConstraint.pm"}) 0 1 1
1568 0 my $method = $self->moose_type->can( $m );
1569 0 ▶ return $self->moose_type->$method( @_ ) if $method;
Branch: 1 branch
BranchTrueFalseTotal
if $method 0 0 0
1570 }
1571 } #/ if ( ref( $self ) )
1572
1573 1 ▶ _croak q[Can't locate object method "%s" via package "%s"], $m,
Condition33%1/3
ref $self || $self
l!l&&r!l&&!r
100
MC/DC0%0/2
ref $self || $self
ref $self $self
Truth table33%1/3
A || B
A= ref $selfB= $self
ABresult
1X1
011
000
1574 ref( $self ) || $self;
1575 } #/ sub AUTOLOAD
1576  
1577 45 ▶sub DOES {
Subroutine DOES: called CC=6 SCAR=22.0
Pod documented
1578 45 my $self = shift;
1579
1580 45 ▶ return !!1
Branch: 1 branch
BranchTrueFalseTotal
if ref $self and $_[0] =~ /^ Type::API::Constraint (?: ::Coercible | ::Inlinable )? $/x 0 45 45
Condition33%1/3
ref $self and $_[0] =~ /^ Type::API::Constraint (?: ::Coercible | ::Inlinable )? $/x
!ll&&!rl&&r
0450
MC/DC0%0/2
ref $self and $_[0] =~ /^ Type::API::Constraint (?: ::Coercible | ::Inlinable )? $/x
ref $self $_[0] =~ /^ Type::API::Constraint (?: ::Coercible | ::Inlinable )? $/x
Truth table33%1/3
A and B
A= ref $selfB= $_[0] =~ /^ Type::API::Constraint (?: ::Coercible | ::Inlinable )? $/x
ABresult
0X0
100
111
1581 if ref( $self )
1582 && $_[0] =~ m{^ Type::API::Constraint (?: ::Coercible | ::Inlinable )? $}x;
1583 45 ▶ return !!1 if !ref( $self ) && $_[0] eq 'Type::API::Constraint::Constructor';
Branch: 1 branch
BranchTrueFalseTotal
if not ref $self and $_[0] eq "Type::API::Constraint::Constructor" 0 45 45
Condition33%1/3
not ref $self and $_[0] eq "Type::API::Constraint::Constructor"
!ll&&!rl&&r
4500
MC/DC0%0/2
not ref $self and $_[0] eq "Type::API::Constraint::Constructor"
not ref $self $_[0] eq "Type::API::Constraint::Constructor"
Truth table33%1/3
not(A) and B
A= not ref $selfB= $_[0] eq "Type::API::Constraint::Constructor"
ABresult
0X0
100
111
1584
1585 45 ▶ "UNIVERSAL"->can( "DOES" ) ? $self->SUPER::DOES( @_ ) : $self->isa( @_ );
Branch: 1 branch
BranchTrueFalseTotal
'UNIVERSAL'->can('DOES') ? : 45 0 45
1586 } #/ sub DOES
1587  
1588 1 ▶sub _has_xsub {
Subroutine _has_xsub: called CC=1 SCAR=0.0
1589 1 require B;
1590 1 !!B::svref_2object( shift->compiled_check )->XSUB;
1591 }
1592  
1593 206 ▶sub _build_util {
Subroutine _build_util: called CC=24 SCAR=31.8
1594 206 my ( $self, $func ) = @_;
1595 206 Scalar::Util::weaken( my $type = $self );
1596
1597 206 ▶ if ( $func eq 'grep'
Branch: 1 branch
BranchTrueFalseTotal
if ($func eq "grep" or $func eq "first" or $func eq "any" or $func eq "all" or $func eq "assert_any" or $func eq "assert_all") 167 39 206
Condition100%15/15
$func eq "grep" or $func eq "first" or $func eq "any" or $func eq "all" or $func eq "assert_any" or $func eq "assert_all"
l!l&&r!l&&!r
159839
$func eq "grep" or $func eq "first" or $func eq "any" or $func eq "all" or $func eq "assert_any"
l!l&&r!l&&!r
151847
$func eq "grep" or $func eq "first" or $func eq "any" or $func eq "all"
l!l&&r!l&&!r
2312855
$func eq "grep" or $func eq "first" or $func eq "any"
l!l&&r!l&&!r
158183
$func eq "grep" or $func eq "first"
l!l&&r!l&&!r
105191
MC/DC100%6/6
$func eq "grep" or $func eq "first" or $func eq "any" or $func eq "all" or $func eq "assert_any" or $func eq "assert_all"
$func eq "grep" $func eq "first" $func eq "any" $func eq "all" $func eq "assert_any" $func eq "assert_all"
Truth table100%7/7
A or B or C or D or E or F
A= $func eq "grep"B= $func eq "first"C= $func eq "any"D= $func eq "all"E= $func eq "assert_any"F= $func eq "assert_all"
ABCDEFresult
1XXXXX1
01XXXX1
001XXX1
0001XX1
00001X1
0000011
0000000
1598 || $func eq 'first'
1599 || $func eq 'any'
1600 || $func eq 'all'
1601 || $func eq 'assert_any'
1602 || $func eq 'assert_all' )
1603 {
1604 167 my ( $inline, $compiled );
1605
1606 167 ▶ if ( $self->can_be_inlined ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->can_be_inlined) { } 137 30 167
1607 137 $inline = $self->inline_check( '$_' );
1608 }
1609 else {
1610 30 $compiled = $self->compiled_check;
1611 30 $inline = '$compiled->($_)';
1612 }
1613
1614 167 ▶ if ( $func eq 'grep' ) {
Branch: 6 branches
BranchTrueFalseTotal
if ($func eq 'grep') { } 10 157 167
elsif ($func eq 'first') { } 5 152 157
elsif ($func eq 'any') { } 8 144 152
elsif ($func eq 'assert_any') { } 8 136 144
elsif ($func eq 'all') { } 128 8 136
elsif ($func eq 'assert_all') { } 8 0 8
1615 10 return eval "sub { grep { $inline } \@_ }";
1616 }
1617 elsif ( $func eq 'first' ) {
1618 5 return eval "sub { for (\@_) { return \$_ if ($inline) }; undef; }";
1619 }
1620 elsif ( $func eq 'any' ) {
1621 8 return eval "sub { for (\@_) { return !!1 if ($inline) }; !!0; }";
1622 }
1623 elsif ( $func eq 'assert_any' ) {
1624 8 my $qname = B::perlstring( $self->name );
1625 return
1626 eval
1627 8 "sub { for (\@_) { return \@_ if ($inline) }; Type::Tiny::_failed_check(\$type, $qname, \@_ ? \$_[-1] : undef); }";
1628 }
1629 elsif ( $func eq 'all' ) {
1630 128 return eval "sub { for (\@_) { return !!0 unless ($inline) }; !!1; }";
1631 }
1632 elsif ( $func eq 'assert_all' ) {
1633 8 my $qname = B::perlstring( $self->name );
1634 return
1635 eval
1636 8 "sub { my \$idx = 0; for (\@_) { Type::Tiny::_failed_check(\$type, $qname, \$_, varname => sprintf('\$_[%d]', \$idx)) unless ($inline); ++\$idx }; \@_; }";
1637 }
1638 } #/ if ( $func eq 'grep' ||...)
1639
1640 39 ▶ if ( $func eq 'map' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($func eq "map") 8 31 39
1641 8 my ( $inline, $compiled );
1642 8 my $c = $self->_assert_coercion;
1643
1644 4 ▶ if ( $c->can_be_inlined ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($c->can_be_inlined) { } 1 3 4
1645 1 $inline = $c->inline_coercion( '$_' );
1646 }
1647 else {
1648 3 $compiled = $c->compiled_coercion;
1649 3 $inline = '$compiled->($_)';
1650 }
1651
1652 4 return eval "sub { map { $inline } \@_ }";
1653 } #/ if ( $func eq 'map' )
1654
1655 31 ▶ if ( $func eq 'sort' || $func eq 'rsort' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($func eq "sort" or $func eq "rsort") 29 2 31
Condition100%3/3
$func eq "sort" or $func eq "rsort"
l!l&&r!l&&!r
18112
MC/DC100%2/2
$func eq "sort" or $func eq "rsort"
$func eq "sort" $func eq "rsort"
Truth table100%3/3
A or B
A= $func eq "sort"B= $func eq "rsort"
ABresult
1X1
011
000
1656 29 my ( $inline, $compiled );
1657
1658 29 ▶ my $ptype = $self->find_parent( sub { $_->has_sorter } );
Subroutine __ANON__: called CC=1 SCAR=0.0
1659 29 ▶ _croak "No sorter for this type constraint" unless $ptype;
Branch: 1 branch
BranchTrueFalseTotal
unless $ptype 2 27 29
1660
1661 27 my $sorter = $ptype->sorter;
1662
1663 # Schwarzian transformation
1664 27 ▶ if ( ref( $sorter ) eq 'ARRAY' ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $sorter eq 'ARRAY') { } 6 21 27
1665 6 my $sort_key;
1666 6 ( $sorter, $sort_key ) = @$sorter;
1667
1668 6 ▶ if ( $func eq 'sort' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($func eq 'sort') { } 4 2 6
elsif ($func eq 'rsort') { } 2 0 2
1669 return
1670 eval
1671 4 "our (\$a, \$b); sub { map \$_->[0], sort { \$sorter->(\$a->[1],\$b->[1]) } map [\$_,\$sort_key->(\$_)], \@_ }";
1672 }
1673 elsif ( $func eq 'rsort' ) {
1674 return
1675 eval
1676 2 "our (\$a, \$b); sub { map \$_->[0], sort { \$sorter->(\$b->[1],\$a->[1]) } map [\$_,\$sort_key->(\$_)], \@_ }";
1677 }
1678 } #/ if ( ref( $sorter ) eq...)
1679
1680 # Simple sort
1681 else {
1682 21 ▶ if ( $func eq 'sort' ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($func eq 'sort') { } 12 9 21
elsif ($func eq 'rsort') { } 9 0 9
1683 12 return eval "our (\$a, \$b); sub { sort { \$sorter->(\$a,\$b) } \@_ }";
1684 }
1685 elsif ( $func eq 'rsort' ) {
1686 9 return eval "our (\$a, \$b); sub { sort { \$sorter->(\$b,\$a) } \@_ }";
1687 }
1688 }
1689 } #/ if ( $func eq 'sort' ||...)
1690
1691 2 die "Unknown function: $func";
1692 } #/ sub _build_util
1693  
1694 334 ▶sub of { shift->parameterize( @_ ) }
Subroutine of: called CC=1 SCAR=0.0
Pod documented
1695 142 ▶sub where { shift->create_child_type( constraint => @_ ) }
Subroutine where: called CC=1 SCAR=0.0
Pod documented
1696  
1697 # fill out Moose-compatible API
1698 1 ▶sub inline_environment { +{} }
Subroutine inline_environment: called CC=1 SCAR=0.0
Pod documented
1699 1 ▶sub _inline_check { shift->inline_check( @_ ) }
Subroutine _inline_check: called CC=1 SCAR=0.0
1700 2 ▶sub _compiled_type_constraint { shift->compiled_check( @_ ) }
Subroutine _compiled_type_constraint: called CC=1 SCAR=0.0
1701 1 ▶sub meta { _croak( "Not really a Moose::Meta::TypeConstraint. Sorry!" ) }
Subroutine meta: called CC=1 SCAR=0.0
Pod documented
1702 2 ▶sub compile_type_constraint { shift->compiled_check }
Subroutine compile_type_constraint: called CC=1 SCAR=0.0
Pod documented
1703 2 ▶sub _actually_compile_type_constraint { shift->_build_compiled_check }
Subroutine _actually_compile_type_constraint: called CC=1 SCAR=0.0
1704 1 ▶sub hand_optimized_type_constraint { shift->{hand_optimized_type_constraint} }
Subroutine hand_optimized_type_constraint: called CC=1 SCAR=0.0
Pod documented
1705  
1706 1 ▶sub has_hand_optimized_type_constraint {
Subroutine has_hand_optimized_type_constraint: called CC=1 SCAR=0.0
Pod documented
1707 1 exists( shift->{hand_optimized_type_constraint} );
1708 }
1709 216 ▶sub type_parameter { ( shift->parameters || [] )->[0] }
Subroutine type_parameter: called CC=2 SCAR=7.6
Pod documented
Condition50%1/2
(shift())->parameters || []
l!l
2160
MC/DC0%0/1
(shift())->parameters || []
(shift())->parameters
Truth table50%1/2
A
A= (shift())->parameters
Aresult
11
00
1710  
1711 5 ▶sub parameterized_from {
Subroutine parameterized_from: called CC=2 SCAR=7.6
Pod documented
1712 5 ▶ $_[0]->is_parameterized ? shift->parent : _croak( "Not a parameterized type" );
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->is_parameterized ? : 5 0 5
1713 }
1714 2 ▶sub has_parameterized_from { $_[0]->is_parameterized }
Subroutine has_parameterized_from: called CC=1 SCAR=0.0
Pod documented
1715  
1716 # some stuff for Mouse-compatible API
1717 2 ▶sub __is_parameterized { shift->is_parameterized( @_ ) }
Subroutine __is_parameterized: called CC=1 SCAR=0.0
1718 1 ▶sub _add_type_coercions { shift->coercion->add_type_coercions( @_ ) }
Subroutine _add_type_coercions: called CC=1 SCAR=0.0
1719 1 ▶sub _as_string { shift->qualified_name( @_ ) }
Subroutine _as_string: called CC=1 SCAR=0.0
1720 1 ▶sub _compiled_type_coercion { shift->coercion->compiled_coercion( @_ ) }
Subroutine _compiled_type_coercion: called CC=1 SCAR=0.0
1721 2 ▶sub _identity { Scalar::Util::refaddr( shift ) }
Subroutine _identity: called CC=1 SCAR=0.0
1722  
1723 1 ▶sub _unite {
Subroutine _unite: called CC=1 SCAR=0.0
1724 1 require Type::Tiny::Union;
1725 1 "Type::Tiny::Union"->new( type_constraints => \@_ );
1726 }
1727  
1728 # Hooks for Type::Tie
1729 3 ▶sub TIESCALAR {
Subroutine TIESCALAR: called CC=1 SCAR=0.0
1730 3 require Type::Tie;
1731 3 unshift @_, 'Type::Tie::SCALAR';
1732 3 goto \&Type::Tie::SCALAR::TIESCALAR;
1733 }
1734  
1735 2 ▶sub TIEARRAY {
Subroutine TIEARRAY: called CC=1 SCAR=0.0
1736 2 require Type::Tie;
1737 2 unshift @_, 'Type::Tie::ARRAY';
1738 2 goto \&Type::Tie::ARRAY::TIEARRAY;
1739 }
1740  
1741 2 ▶sub TIEHASH {
Subroutine TIEHASH: called CC=1 SCAR=0.0
1742 2 require Type::Tie;
1743 2 unshift @_, 'Type::Tie::HASH';
1744 2 goto \&Type::Tie::HASH::TIEHASH;
1745 }
1746  
1747 303 1;
1748  
1749 __END__
« lib/Types/Standard/Tuple.pm ↑ Summary lib/Types/Standard/Dict.pm »