blib/lib/Types/Standard.pm

filter: Statementstmt 98.5% 396 / 402 Branchbran 79.4% 135 / 170 Conditioncond 69.6% 78 / 112 MC/DCmcdc 41.8% 23 / 55 Subroutinesub 98.4% 130 / 132 Podpod 100% 3 / 3 totaltotal 87.5% 765 / 874 CC 134 SCAR 17.9
CC
134
Cov
89%
__ANON__
34.9
__ANON__
11.0
__ANON__
9.0
CRAP 6.0
« blib/lib/Type/Tiny/Class.pm ↑ Summary blib/lib/Reply/Plugin/TypeTiny.pm »
1 package Types::Standard;
2  
3 274 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 274 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 274 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 274 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=7.6
8 274 eval { require re };
9 0 ▶ if ( $] < 5.010 ) { require Devel::TypeTiny::Perl58Compat }
Branch: 1 branch
BranchTrueFalseTotal
if ($] < "5.01") 0 274 274
10 }
11  
12 274 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
13 274 $Types::Standard::AUTHORITY = 'cpan:TOBYINK';
14 274 $Types::Standard::VERSION = '2.010001';
15 }
16  
17 274 $Types::Standard::VERSION =~ tr/_//d;
18  
19 274 ▶use Type::Library -base;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 274 our @EXPORT_OK = qw( slurpy );
22  
23 274 ▶use Eval::TypeTiny qw( set_subname );
Subroutine BEGIN: called CC=1 SCAR=0.0
24 274 ▶use Scalar::Util qw( blessed looks_like_number );
Subroutine BEGIN: called CC=1 SCAR=0.0
25 274 ▶use Type::Tiny ();
Subroutine BEGIN: called CC=1 SCAR=0.0
26 274 ▶use Types::TypeTiny ();
Subroutine BEGIN: called CC=1 SCAR=0.0
27  
28 274 my $is_class_loaded;
29  
30 274 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=6.9
31 274 $is_class_loaded = q{sub {
32 no strict 'refs';
33 return !!0 if ref $_[0];
34 return !!0 if not $_[0];
35 return !!0 if ref(do { my $tmpstr = $_[0]; \$tmpstr }) ne 'SCALAR';
36 my $stash = \%{"$_[0]\::"};
37 return !!1 if exists($stash->{'ISA'}) && *{$stash->{'ISA'}}{ARRAY} && @{$_[0].'::ISA'};
38 return !!1 if exists($stash->{'VERSION'});
39 foreach my $globref (values %$stash) {
40 return !!1
41 if ref \$globref eq 'GLOB'
42 ? *{$globref}{CODE}
43 : ref $globref; # const or sub ref
44 }
45 return !!0;
46 }};
47
48 274 ▶ *_is_class_loaded =
Subroutine BEGIN: called CC=1 SCAR=0.0
49 Type::Tiny::_USE_XS
50 ? \&Type::Tiny::XS::Util::is_class_loaded
51 : eval $is_class_loaded;
52
53 *_HAS_REFUTILXS = eval {
54 274 require Ref::Util::XS;
55 274 Ref::Util::XS::->VERSION( 0.100 );
56 274 1;
57 }
58 ? sub () { !!1 }
59 274 ▶ : sub () { !!0 };
Branch: 1 branch
BranchTrueFalseTotal
eval { do { require Ref::Util::XS; 'Ref::Util::XS'->VERSION(0.1); 1 } } ? : 274 0 274
60 } #/ BEGIN
61  
62 5480 ▶my $add_core_type = sub {
Subroutine __ANON__: called CC=24 SCAR=35.5
63 5480 my $meta = shift;
64 5480 my ( $typedef ) = @_;
65
66 5480 my $name = $typedef->{name};
67 5480 my ( $xsub, $xsubname );
68
69 # We want Map and Tuple to be XSified, even if they're not
70 # really core.
71 5480 ▶ $typedef->{_is_core} = 1
Branch: 1 branch
BranchTrueFalseTotal
unless $name eq "Map" or $name eq "Tuple" 4932 548 5480
Condition100%3/3
$name eq "Map" or $name eq "Tuple"
l!l&&r!l&&!r
2742744932
MC/DC100%2/2
$name eq "Map" or $name eq "Tuple"
$name eq "Map" $name eq "Tuple"
Truth table100%3/3
A or B
A= $name eq "Map"B= $name eq "Tuple"
ABresult
1X1
011
000
72 unless $name eq 'Map' || $name eq 'Tuple';
73
74 5480 ▶ if ( Type::Tiny::_USE_XS
Branch: 2 branches
BranchTrueFalseTotal
if (not $name eq 'RegexpRef') { } 5168 312 5480
elsif (&Type::Tiny::_USE_MOUSE() and not $name eq 'RegexpRef' || $name eq 'Int' || $name eq 'Object') { } 0 584 584
75 and not( $name eq 'RegexpRef' ) )
76 {
77 5168 $xsub = Type::Tiny::XS::get_coderef_for( $name );
78 5208 $xsubname = Type::Tiny::XS::get_subname_for( $name );
79 }
80
81 ▶ elsif ( Type::Tiny::_USE_MOUSE
Condition11%1/9
&Type::Tiny::_USE_MOUSE() and not $name eq "RegexpRef" || $name eq "Int" || $name eq "Object"
!ll&&!rl&&r
31200
$name eq 'RegexpRef' || $name eq 'Int' || $name eq 'Object'
l!l&&r!l&&!r
000
$name eq "RegexpRef" or $name eq "Int"
l!l&&r!l&&!r
000
MC/DC0%0/4
&Type::Tiny::_USE_MOUSE() and not $name eq "RegexpRef" || $name eq "Int" || $name eq "Object"
&Type::Tiny::_USE_MOUSE() $name eq "RegexpRef" $name eq "Int" $name eq 'Object'
Truth table20%1/5
A and not(B or C || D)
A= &Type::Tiny::_USE_MOUSE()B= $name eq "RegexpRef"C= $name eq "Int"D= $name eq 'Object'
ABCDresult
0XXX0
11XX0
101X0
10010
10001
82 and not( $name eq 'RegexpRef' or $name eq 'Int' or $name eq 'Object' ) )
83 {
84 40 require Mouse::Util::TypeConstraints;
85 40 $xsub = "Mouse::Util::TypeConstraints"->can( $name );
86 40 ▶ $xsubname = "Mouse::Util::TypeConstraints::$name" if $xsub;
Branch: 1 branch
BranchTrueFalseTotal
if $xsub 0 0 0
87 }
88
89 5480 ▶ if ( Type::Tiny::_USE_XS
Branch: 1 branch
BranchTrueFalseTotal
if ("Type::Tiny::XS"->VERSION < "0.014" and $name eq "Bool") 0 5440 5440
Condition33%1/3
"Type::Tiny::XS"->VERSION < "0.014" and $name eq "Bool"
!ll&&!rl&&r
544000
MC/DC0%0/2
"Type::Tiny::XS"->VERSION < "0.014" and $name eq "Bool"
"Type::Tiny::XS"->VERSION < "0.014" $name eq "Bool"
Truth table33%1/3
A and B
A= "Type::Tiny::XS"->VERSION < "0.014"B= $name eq "Bool"
ABresult
0X0
100
111
90 and Type::Tiny::XS->VERSION < 0.014
91 and $name eq 'Bool' )
92 {
93 # Broken implementation of Bool
94 40 $xsub = $xsubname = undef;
95 }
96
97 5440 ▶ if ( Type::Tiny::_USE_XS
Branch: 1 branch
BranchTrueFalseTotal
if ("Type::Tiny::XS"->VERSION < "0.016" || $] < "5.018" and $name eq "Int") 0 5440 5440
Condition33%2/6
"Type::Tiny::XS"->VERSION < "0.016" || $] < "5.018" and $name eq "Int"
!ll&&!rl&&r
544000
"Type::Tiny::XS"->VERSION < "0.016" or $] < "5.018"
l!l&&r!l&&!r
005440
MC/DC0%0/3
"Type::Tiny::XS"->VERSION < "0.016" || $] < "5.018" and $name eq "Int"
"Type::Tiny::XS"->VERSION < "0.016" $] < "5.018" $name eq "Int"
Truth table20%1/5
A or B and C
A= "Type::Tiny::XS"->VERSION < "0.016"B= $] < "5.018"C= $name eq "Int"
ABCresult
00X0
1X00
0100
1X11
0111
98 and ( Type::Tiny::XS->VERSION < 0.016 or $] < 5.018 )
99 and $name eq 'Int' )
100 {
101 # Broken implementation of Int
102 40 $xsub = $xsubname = undef;
103 }
104  
105 5480 ▶ if ( Type::Tiny::_USE_XS
Branch: 1 branch
BranchTrueFalseTotal
if ($name eq "Int" and do { $Config::Config{"usequadmath"} }) 0 5440 5440
Condition66%2/3
$name eq "Int" and do { $Config::Config{"usequadmath"} }
!ll&&!rl&&r
51682720
MC/DC0%0/2
$name eq "Int" and do { $Config::Config{"usequadmath"} }
$name eq "Int" do { $Config::Config{"usequadmath"} }
Truth table66%2/3
A and B
A= $name eq "Int"B= do { $Config::Config{"usequadmath"} }
ABresult
0X0
100
111
106 and $name eq 'Int'
107 274 ▶ and do { use Config (); $Config::Config{usequadmath} } )
Subroutine BEGIN: called CC=1 SCAR=0.0
108 {
109 # Broken implementation of Int
110 0 $xsub = $xsubname = undef;
111 }
112
113 5440 ▶ $typedef->{compiled_type_constraint} = $xsub if $xsub;
Branch: 1 branch
BranchTrueFalseTotal
if $xsub 4896 544 5440
114
115 5440 my $orig_inlined = $typedef->{inlined};
116 5440 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (defined $xsubname and $name eq "Str" || $name eq "Bool" || $name eq "Int" || $name eq "ClassName" || $name eq "RegexpRef" || $name eq "FileHandle") 1088 4352 5440
Condition88%16/18
defined $xsubname and $name eq "Str" || $name eq "Bool" || $name eq "Int" || $name eq "ClassName" || $name eq "RegexpRef" || $name eq "FileHandle"
!ll&&!rl&&r
54438081088
$name eq "Str" or $name eq "Bool" or $name eq "Int" or $name eq "ClassName" or $name eq "RegexpRef" or $name eq "FileHandle"
l!l&&r!l&&!r
8162723808
$name eq "Str" or $name eq "Bool" or $name eq "Int" or $name eq "ClassName" or $name eq "RegexpRef"
l!l&&r!l&&!r
81604080
$name eq "Str" or $name eq "Bool" or $name eq "Int" or $name eq "ClassName"
l!l&&r!l&&!r
81604080
$name eq "Str" or $name eq "Bool" or $name eq "Int"
l!l&&r!l&&!r
5442724080
$name eq "Str" or $name eq "Bool"
l!l&&r!l&&!r
2722724352
MC/DC71%5/7
defined $xsubname and $name eq "Str" || $name eq "Bool" || $name eq "Int" || $name eq "ClassName" || $name eq "RegexpRef" || $name eq "FileHandle"
defined $xsubname $name eq "Str" $name eq "Bool" $name eq "Int" $name eq "ClassName" $name eq "RegexpRef" $name eq "FileHandle"
Truth table75%6/8
A and B or C or D or E or F or G
A= defined $xsubnameB= $name eq "Str"C= $name eq "Bool"D= $name eq "Int"E= $name eq "ClassName"F= $name eq "RegexpRef"G= $name eq "FileHandle"
ABCDEFGresult
0XXXXXX0
10000000
11XXXXX1
101XXXX1
1001XXX1
10001XX1
100001X1
10000011
117 defined( $xsubname ) and (
118
119 # These should be faster than their normal inlined
120 # equivalents
121 $name eq 'Str'
122 or $name eq 'Bool'
123 or $name eq 'Int'
124 or $name eq 'ClassName'
125 or $name eq 'RegexpRef'
126 or $name eq 'FileHandle'
127 )
128 )
129 {
130 10114 ▶ $typedef->{inlined} = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
131 10114 ▶ $Type::Tiny::AvoidCallbacks ? goto( $orig_inlined ) : "$xsubname\($_[1])";
Branch: 1 branch
BranchTrueFalseTotal
$Type::Tiny::AvoidCallbacks ? : 2560 7554 10114
132 1088 };
133 } #/ if ( defined( $xsubname...))
134
135 5440 @_ = ( $meta, $typedef );
136 5440 goto \&Type::Library::add_type;
137 274 };
138  
139 6323 ▶my $maybe_load_modules = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
140 6323 my $code = pop;
141 6323 ▶ if ( $Type::Tiny::AvoidCallbacks ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Type::Tiny::AvoidCallbacks) 1364 4959 6323
142 1364 $code = sprintf(
143 'do { %s %s; %s }',
144 $Type::Tiny::SafePackage,
145 join( '; ', map "use $_ ()", @_ ),
146 $code,
147 );
148 }
149 6323 $code;
150 274 };
151  
152 3 ▶sub _croak ($;@) { require Error::TypeTiny; goto \&Error::TypeTiny::croak }
Subroutine _croak: called CC=1 SCAR=0.0
153  
154 274 my $meta = __PACKAGE__->meta;
155  
156 # Stringable and LazyLoad are optimizations that complicate
157 # this module somewhat, but they have led to performance
158 # improvements. If Types::Standard wasn't such a key type
159 # library, I wouldn't use them. I strongly discourage anybody
160 # from using them in their own code. If you're looking for
161 # examples of how to write a type library sanely, you're
162 # better off looking at the code for Types::Common::Numeric
163 # and Types::Common::String.
164  
165 {
166  
167 274 ▶ sub Stringable (&) {
Subroutine Stringable: called CC=1 SCAR=0.0
Pod documented
168 42 bless +{ code => $_[0] }, 'Types::Standard::_Stringable';
169 }
170 Types::Standard::_Stringable->Type::Tiny::_install_overloads(
171 71 ▶ q[""] => sub { $_[0]{text} ||= $_[0]{code}->() } );
Subroutine __ANON__: called CC=2 SCAR=7.1
Condition66%2/3
$_[0]{"text"} ||= $_[0]{"code"}->()
l!l&&r!l&&!r
32390
MC/DC0%0/2
$_[0]{"text"} ||= $_[0]{"code"}->()
$_[0]{"text"} $_[0]{"code"}->()
Truth table66%2/3
A ||= B
A= $_[0]{"text"}B= $_[0]{"code"}->()
ABresult
1X1
011
000
172
173 10686 ▶ sub LazyLoad ($$) {
Subroutine LazyLoad: called CC=1 SCAR=0.0
Pod documented
174 10686 bless \@_, 'Types::Standard::LazyLoad';
175 }
176 'Types::Standard::LazyLoad'->Type::Tiny::_install_overloads(
177 190 ▶ q[&{}] => sub {
Subroutine __ANON__: called CC=7 SCAR=19.5
178 190 my ( $typename, $function ) = @{ $_[0] };
179 190 my $type = $meta->get_type( $typename );
180 190 my $class = "Types::Standard::$typename";
181 190 ▶ eval "require $class; 1" or die( $@ );
Branch: 1 branch
BranchTrueFalseTotal
eval "require $class; 1" or die $@ 190 0 190
182
183 # Majorly break encapsulation for Type::Tiny :-O
184 190 for my $key ( keys %$type ) {
185 3802 ▶ next unless ref( $type->{$key} ) eq 'Types::Standard::LazyLoad';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $type->{$key} eq "Types::Standard::LazyLoad" 3072 730 3802
186 730 my $f = $type->{$key}[1];
187 730 $type->{$key} = $class->can( "__$f" );
188 }
189 190 ▶ my $mm = $type->{my_methods} || {};
Condition100%2/2
$type->{'my_methods'} || {}
l!l
52138
MC/DC100%1/1
$type->{'my_methods'} || {}
$type->{'my_methods'}
Truth table100%2/2
A
A= $type->{'my_methods'}
Aresult
11
00
190 190 for my $key ( keys %$mm ) {
191 126 ▶ next unless ref( $mm->{$key} ) eq 'Types::Standard::LazyLoad';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $mm->{$key} eq "Types::Standard::LazyLoad" 0 126 126
192 126 my $f = $mm->{$key}[1];
193 126 $mm->{$key} = $class->can( "__$f" );
194 set_subname(
195 sprintf( "%s::my_%s", $type->qualified_name, $key ),
196 126 $mm->{$key},
197 );
198 } #/ for my $key ( keys %$mm)
199 190 return $class->can( "__$function" );
200 },
201 274 );
202 }
203  
204 274 ▶no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
205  
206 274 ▶BEGIN {
Subroutine BEGIN: called CC=2 SCAR=7.6
207 *STRICTNUM =
208 $ENV{PERL_TYPES_STANDARD_STRICTNUM}
209 ? sub() { !!1 }
210 : sub() { !!0 }
211 274 ▶}
Branch: 1 branch
BranchTrueFalseTotal
$ENV{'PERL_TYPES_STANDARD_STRICTNUM'} ? : 0 274 274
212  
213 my $_any = $meta->$add_core_type(
214 {
215 name => "Any",
216 0 ▶ inlined => sub { "!!1" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
217 complement_name => 'None',
218 6 ▶ type_default => sub { return undef; },
Subroutine __ANON__: called CC=1 SCAR=0.0
219 }
220 274 );
221  
222 my $_item = $meta->$add_core_type(
223 {
224 name => "Item",
225 0 ▶ inlined => sub { "!!1" },
Subroutine __ANON__: not called CC=1 SCAR=6.9
226 274 parent => $_any,
227 }
228 );
229  
230 my $_bool = $meta->$add_core_type(
231 {
232 name => "Bool",
233 parent => $_item,
234 73 ▶ constraint => sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
235 73 ▶ !ref $_ and ( !defined $_ or $_ eq q() or $_ eq '0' or $_ eq '1' );
Branch: 1 branch
BranchTrueFalseTotal
not ref $_ and !defined($_) || $_ eq "" || $_ eq 0 || $_ eq 1 25 48 73
Condition100%12/12
!ref($_) && (!defined($_) || $_ eq '' || $_ eq '0' || $_ eq '1')
!ll&&!rl&&r
48916
not defined $_ or $_ eq "" or $_ eq 0 or $_ eq 1
l!l&&r!l&&!r
1159
not defined $_ or $_ eq "" or $_ eq 0
l!l&&r!l&&!r
8314
not defined $_ or $_ eq ""
l!l&&r!l&&!r
3517
MC/DC100%5/5
!ref($_) && (!defined($_) || $_ eq '' || $_ eq '0' || $_ eq '1')
!ref($_) not defined $_ $_ eq "" $_ eq 0 $_ eq 1
Truth table100%6/6
not(A) && not(B) or C or D or E
A= !ref($_)B= not defined $_C= $_ eq ""D= $_ eq 0E= $_ eq 1
ABCDEresult
0XXXX0
100000
11XXX1
101XX1
1001X1
100011
236 },
237 104 ▶ inlined => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
238 104 "!ref $_[1] and (!defined $_[1] or $_[1] eq q() or $_[1] eq '0' or $_[1] eq '1')";
239 },
240 2 ▶ type_default => sub { return !!0; },
Subroutine __ANON__: called CC=1 SCAR=0.0
241 }
242 274 );
243  
244 274 $_bool->coercion->add_type_coercions( $_any, q{!!$_} );
245  
246 my $_undef = $meta->$add_core_type(
247 {
248 name => "Undef",
249 parent => $_item,
250 59 ▶ constraint => sub { !defined $_ },
Subroutine __ANON__: called CC=1 SCAR=0.0
251 479 ▶ inlined => sub { "!defined($_[1])" },
Subroutine __ANON__: called CC=1 SCAR=0.0
252 2 ▶ type_default => sub { return undef; },
Subroutine __ANON__: called CC=1 SCAR=0.0
253 }
254 274 );
255  
256 my $_def = $meta->$add_core_type(
257 {
258 name => "Defined",
259 parent => $_item,
260 4516 ▶ constraint => sub { defined $_ },
Subroutine __ANON__: called CC=1 SCAR=0.0
261 1289 ▶ inlined => sub { "defined($_[1])" },
Subroutine __ANON__: called CC=1 SCAR=0.0
262 274 complementary_type => $_undef,
263 }
264 );
265  
266 # hackish, but eh
267 274 ▶Scalar::Util::weaken( $_undef->{complementary_type} ||= $_def );
Condition33%1/3
$_undef->{"complementary_type"} ||= $_def
l!l&&r!l&&!r
02740
MC/DC0%0/2
$_undef->{"complementary_type"} ||= $_def
$_undef->{"complementary_type"} $_def
Truth table33%1/3
A ||= B
A= $_undef->{"complementary_type"}B= $_def
ABresult
1X1
011
000
268  
269 my $_val = $meta->$add_core_type(
270 {
271 name => "Value",
272 parent => $_def,
273 2626 ▶ constraint => sub { not ref $_ },
Subroutine __ANON__: called CC=1 SCAR=0.0
274 1448 ▶ inlined => sub { "defined($_[1]) and not ref($_[1])" },
Subroutine __ANON__: called CC=1 SCAR=0.0
275 }
276 274 );
277  
278 my $_str = $meta->$add_core_type(
279 {
280 name => "Str",
281 parent => $_val,
282 1246 ▶ constraint => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
283 1246 ▶ ref( \$_ ) eq 'SCALAR' or ref( \( my $val = $_ ) ) eq 'SCALAR';
Branch: 1 branch
BranchTrueFalseTotal
ref \$_ eq "SCALAR" or ref \(my $val = $_) eq "SCALAR" 1214 32 1246
284 },
285 1106 ▶ inlined => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
286 1106 "defined($_[1]) and do { ref(\\$_[1]) eq 'SCALAR' or ref(\\(my \$val = $_[1])) eq 'SCALAR' }";
287 },
288 12 ▶ sorter => sub { $_[0] cmp $_[1] },
Subroutine __ANON__: called CC=1 SCAR=0.0
289 5 ▶ type_default => sub { return ''; },
Subroutine __ANON__: called CC=1 SCAR=0.0
290 }
291 274 );
292  
293 my $_laxnum = $meta->add_type(
294 {
295 name => "LaxNum",
296 parent => $_str,
297 717 ▶ constraint => sub { looks_like_number( $_ ) and ref( \$_ ) ne 'GLOB' },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
&looks_like_number($_) and ref \$_ ne "GLOB" 607 110 717
298 3449 ▶ inlined => sub {
Subroutine __ANON__: called CC=2 SCAR=7.6
299 3449 ▶ $maybe_load_modules->(
Branch: 1 branch
BranchTrueFalseTotal
'Scalar::Util'->VERSION ge '1.18' ? : 3449 0 3449
300 qw/ Scalar::Util /,
301 'Scalar::Util'->VERSION ge '1.18' # RT 132426
302 ? "defined($_[1]) && !ref($_[1]) && Scalar::Util::looks_like_number($_[1])"
303 : "defined($_[1]) && !ref($_[1]) && Scalar::Util::looks_like_number($_[1]) && ref(\\($_[1])) ne 'GLOB'"
304 );
305 },
306 22 ▶ sorter => sub { $_[0] <=> $_[1] },
Subroutine __ANON__: called CC=1 SCAR=0.0
307 5 ▶ type_default => sub { return 0; },
Subroutine __ANON__: called CC=1 SCAR=0.0
308 }
309 274 );
310  
311 my $_strictnum = $meta->add_type(
312 {
313 name => "StrictNum",
314 parent => $_str,
315 12 ▶ constraint => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
316 12 my $val = $_;
317 12 ▶ ( $val =~ /\A[+-]?[0-9]+\z/ )
Branch: 1 branch
BranchTrueFalseTotal
$val =~ /\A[+-]?[0-9]+\z/ or $val =~ /\A(?:[+-]?) #matches optional +- in the beginning (?=[0-9]|\.[0-9]) #matches previous +- only if there is something like 3 or .3 [0-9]* #matches 0-9 zero or more times (?:\.[0-9]+)? #matches optional .89 or nothing (?:[Ee](?:[+-]?[0-9]+))? #matches E1 or e1 or e-1 or e+1 etc \z/x 4 8 12
318 || (
319 $val =~ /\A(?:[+-]?) #matches optional +- in the beginning
320 (?=[0-9]|\.[0-9]) #matches previous +- only if there is something like 3 or .3
321 [0-9]* #matches 0-9 zero or more times
322 (?:\.[0-9]+)? #matches optional .89 or nothing
323 (?:[Ee](?:[+-]?[0-9]+))? #matches E1 or e1 or e-1 or e+1 etc
324 \z/x
325 );
326 },
327 657 ▶ inlined => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
328 657 'my $val = '
329 . $_[1] . ';'
330 . Value()->inline_check( '$val' )
331 . ' && ( $val =~ /\A[+-]?[0-9]+\z/ || '
332 . '$val =~ /\A(?:[+-]?) # matches optional +- in the beginning
333 (?=[0-9]|\.[0-9]) # matches previous +- only if there is something like 3 or .3
334 [0-9]* # matches 0-9 zero or more times
335 (?:\.[0-9]+)? # matches optional .89 or nothing
336 (?:[Ee](?:[+-]?[0-9]+))? # matches E1 or e1 or e-1 or e+1 etc
337 \z/x ); '
338 },
339 2 ▶ sorter => sub { $_[0] <=> $_[1] },
Subroutine __ANON__: called CC=1 SCAR=0.0
340 2 ▶ type_default => sub { return 0; },
Subroutine __ANON__: called CC=1 SCAR=0.0
341 }
342 274 );
343  
344 274 my $_num = $meta->add_type(
345 {
346 name => "Num",
347 parent => ( STRICTNUM ? $_strictnum : $_laxnum ),
348 }
349 );
350  
351 $meta->$add_core_type(
352 {
353 name => "Int",
354 parent => $_num,
355 362 ▶ constraint => sub { /\A-?[0-9]+\z/ },
Subroutine __ANON__: called CC=1 SCAR=0.0
356 1318 ▶ inlined => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
357 1318 "do { my \$tmp = $_[1]; defined(\$tmp) and !ref(\$tmp) and \$tmp =~ /\\A-?[0-9]+\\z/ }";
358 },
359 9 ▶ type_default => sub { return 0; },
Subroutine __ANON__: called CC=1 SCAR=0.0
360 }
361 274 );
362  
363 my $_classn = $meta->add_type(
364 {
365 name => "ClassName",
366 parent => $_str,
367 constraint => \&_is_class_loaded,
368 725 ▶ inlined => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
369 725 ▶ $Type::Tiny::AvoidCallbacks
Branch: 1 branch
BranchTrueFalseTotal
$Type::Tiny::AvoidCallbacks ? : 77 648 725
370 ? "($is_class_loaded)->(do { my \$tmp = $_[1] })"
371 : "Types::Standard::_is_class_loaded(do { my \$tmp = $_[1] })";
372 },
373 }
374 274 );
375  
376 $meta->add_type(
377 {
378 name => "RoleName",
379 parent => $_classn,
380 6 ▶ constraint => sub { not $_->can( "new" ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
381 677 ▶ inlined => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
382 677 ▶ $Type::Tiny::AvoidCallbacks
Branch: 1 branch
BranchTrueFalseTotal
$Type::Tiny::AvoidCallbacks ? : 63 614 677
383 ? "($is_class_loaded)->(do { my \$tmp = $_[1] }) and not $_[1]\->can('new')"
384 : "Types::Standard::_is_class_loaded(do { my \$tmp = $_[1] }) and not $_[1]\->can('new')";
385 },
386 }
387 274 );
388  
389 my $_ref = $meta->$add_core_type(
390 {
391 name => "Ref",
392 parent => $_def,
393 1746 ▶ constraint => sub { ref $_ },
Subroutine __ANON__: called CC=1 SCAR=0.0
394 1931 ▶ inlined => sub { "!!ref($_[1])" },
Subroutine __ANON__: called CC=1 SCAR=0.0
395 24 ▶ constraint_generator => sub {
Subroutine __ANON__: called CC=3 SCAR=11.1
396 24 ▶ return $meta->get_type( 'Ref' ) unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 24 24
397
398 24 Type::Tiny::check_parameter_count_for_parameterized_type( 'Types::Standard', 'Ref', \@_, 1 );
399 24 my $reftype = shift;
400 24 ▶ $reftype =~
Branch: 1 branch
BranchTrueFalseTotal
$reftype =~ /^(SCALAR|ARRAY|HASH|CODE|REF|GLOB|LVALUE|FORMAT|IO|VSTRING|REGEXP|Regexp)$/i or &_croak("Parameter to Ref[`a] expected to be a Perl ref type; got $reftype") 23 1 24
401 /^(SCALAR|ARRAY|HASH|CODE|REF|GLOB|LVALUE|FORMAT|IO|VSTRING|REGEXP|Regexp)$/i
402 or _croak(
403 "Parameter to Ref[`a] expected to be a Perl ref type; got $reftype" );
404
405 23 $reftype = "$reftype";
406 62 ▶ return sub {
Subroutine __ANON__: called CC=2 SCAR=7.6
407 62 ▶ ref( $_[0] ) and Scalar::Util::reftype( $_[0] ) eq $reftype;
Branch: 1 branch
BranchTrueFalseTotal
ref $_[0] and builtin::reftype($_[0]) eq $reftype 62 0 62
408 }
409 23 },
410 23 ▶ inline_generator => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
411 23 my $reftype = shift;
412 181 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
413 181 my $v = $_[1];
414 181 $maybe_load_modules->(
415 qw/ Scalar::Util /,
416 "ref($v) and Scalar::Util::reftype($v) eq q($reftype)"
417 );
418 23 };
419 },
420 1 ▶ deep_explanation => sub {
Subroutine __ANON__: called CC=3 SCAR=11.2
421 1 require B;
422 1 my ( $type, $value, $varname ) = @_;
423 1 my $param = $type->parameters->[0];
424 1 ▶ return if $type->check( $value );
Branch: 1 branch
BranchTrueFalseTotal
if $type->check($value) 0 1 1
425 1 my $reftype = Scalar::Util::reftype( $value );
426 return [
427 1 ▶ sprintf(
Branch: 1 branch
BranchTrueFalseTotal
defined $reftype ? : 1 0 1
428 '"%s" constrains reftype(%s) to be equal to %s', $type, $varname,
429 B::perlstring( $param )
430 ),
431 sprintf(
432 'reftype(%s) is %s', $varname,
433 defined( $reftype ) ? B::perlstring( $reftype ) : "undef"
434 ),
435 ];
436 },
437 }
438 274 );
439  
440 $meta->$add_core_type(
441 {
442 name => "CodeRef",
443 parent => $_ref,
444 41 ▶ constraint => sub { ref $_ eq "CODE" },
Subroutine __ANON__: called CC=1 SCAR=0.0
445 509 ▶ inlined => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
446 509 ▶ _HAS_REFUTILXS && !$Type::Tiny::AvoidCallbacks
Branch: 1 branch
BranchTrueFalseTotal
!$Type::Tiny::AvoidCallbacks ? : 408 101 509
447 ? "Ref::Util::XS::is_plain_coderef($_[1])"
448 : "ref($_[1]) eq 'CODE'";
449 },
450 1 ▶ type_default => sub { return sub {}; },
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=1 SCAR=0.0
451 }
452 274 );
453  
454 my $_regexp = $meta->$add_core_type(
455 {
456 name => "RegexpRef",
457 parent => $_ref,
458 41 ▶ constraint => sub {
Subroutine __ANON__: called CC=4 SCAR=14.5
459 41 ▶ ref( $_ ) && !!re::is_regexp( $_ ) or blessed( $_ ) && $_->isa( 'Regexp' );
Branch: 1 branch
BranchTrueFalseTotal
ref $_ and not !&re::is_regexp($_) or builtin::blessed($_) and $_->isa("Regexp") 3 38 41
Condition66%6/9
ref $_ && !!&re::is_regexp($_) || builtin::blessed($_) && $_->isa('Regexp')
l!l&&r!l&&!r
3038
ref $_ and not !&re::is_regexp($_)
!ll&&!rl&&r
0383
builtin::blessed($_) and $_->isa("Regexp")
!ll&&!rl&&r
21170
MC/DC25%1/4
ref $_ && !!&re::is_regexp($_) || builtin::blessed($_) && $_->isa('Regexp')
ref $_ not !&re::is_regexp($_) builtin::blessed($_) $_->isa("Regexp")
Truth table42%3/7
A and B || C and D
A= ref $_B= not !&re::is_regexp($_)C= builtin::blessed($_)D= $_->isa("Regexp")
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
460 },
461 901 ▶ inlined => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
462 901 my $v = $_[1];
463 901 $maybe_load_modules->(
464 qw/ Scalar::Util re /,
465 "ref($v) && !!re::is_regexp($v) or Scalar::Util::blessed($v) && $v\->isa('Regexp')"
466 );
467 },
468 1 ▶ type_default => sub { return qr//; },
Subroutine __ANON__: called CC=1 SCAR=0.0
469 }
470 274 );
471  
472 $meta->$add_core_type(
473 {
474 name => "GlobRef",
475 parent => $_ref,
476 41 ▶ constraint => sub { ref $_ eq "GLOB" },
Subroutine __ANON__: called CC=1 SCAR=0.0
477 394 ▶ inlined => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
478 394 ▶ _HAS_REFUTILXS && !$Type::Tiny::AvoidCallbacks
Branch: 1 branch
BranchTrueFalseTotal
!$Type::Tiny::AvoidCallbacks ? : 336 58 394
479 ? "Ref::Util::XS::is_plain_globref($_[1])"
480 : "ref($_[1]) eq 'GLOB'";
481 },
482 }
483 274 );
484  
485 $meta->$add_core_type(
486 {
487 name => "FileHandle",
488 parent => $_ref,
489 41 ▶ constraint => sub {
Subroutine __ANON__: called CC=4 SCAR=14.5
490 41 ▶ ( ref( $_ ) && Scalar::Util::openhandle( $_ ) )
Branch: 1 branch
BranchTrueFalseTotal
ref $_ and &Scalar::Util::openhandle($_) or builtin::blessed($_) and $_->isa("IO::Handle") 3 38 41
Condition66%6/9
ref $_ && &Scalar::Util::openhandle($_) || builtin::blessed($_) && $_->isa('IO::Handle')
l!l&&r!l&&!r
3038
ref $_ and &Scalar::Util::openhandle($_)
!ll&&!rl&&r
0383
builtin::blessed($_) and $_->isa("IO::Handle")
!ll&&!rl&&r
20180
MC/DC25%1/4
ref $_ && &Scalar::Util::openhandle($_) || builtin::blessed($_) && $_->isa('IO::Handle')
ref $_ &Scalar::Util::openhandle($_) builtin::blessed($_) $_->isa("IO::Handle")
Truth table42%3/7
A and B || C and D
A= ref $_B= &Scalar::Util::openhandle($_)C= builtin::blessed($_)D= $_->isa("IO::Handle")
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
491 or ( blessed( $_ ) && $_->isa( "IO::Handle" ) );
492 },
493 62 ▶ inlined => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
494 62 $maybe_load_modules->(
495 qw/ Scalar::Util /,
496 "(ref($_[1]) && Scalar::Util::openhandle($_[1])) "
497 . "or (Scalar::Util::blessed($_[1]) && $_[1]\->isa(\"IO::Handle\"))"
498 );
499 },
500 }
501 274 );
502  
503 my $_arr = $meta->$add_core_type(
504 {
505 name => "ArrayRef",
506 parent => $_ref,
507 416 ▶ constraint => sub { ref $_ eq "ARRAY" },
Subroutine __ANON__: called CC=1 SCAR=0.0
508 3439 ▶ inlined => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
509 3439 ▶ _HAS_REFUTILXS && !$Type::Tiny::AvoidCallbacks
Branch: 1 branch
BranchTrueFalseTotal
!$Type::Tiny::AvoidCallbacks ? : 2715 724 3439
510 ? "Ref::Util::XS::is_plain_arrayref($_[1])"
511 : "ref($_[1]) eq 'ARRAY'";
512 },
513 constraint_generator => LazyLoad( ArrayRef => 'constraint_generator' ),
514 inline_generator => LazyLoad( ArrayRef => 'inline_generator' ),
515 deep_explanation => LazyLoad( ArrayRef => 'deep_explanation' ),
516 coercion_generator => LazyLoad( ArrayRef => 'coercion_generator' ),
517 6 ▶ type_default => sub { return []; },
Subroutine __ANON__: called CC=1 SCAR=0.0
518 173 ▶ type_default_generator => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
519 173 ▶ return $Type::Tiny::parameterize_type->type_default if @_ < 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 2 164 9 173
520 9 return undef;
521 },
522 }
523 274 );
524  
525 my $_hash = $meta->$add_core_type(
526 {
527 name => "HashRef",
528 parent => $_ref,
529 288 ▶ constraint => sub { ref $_ eq "HASH" },
Subroutine __ANON__: called CC=1 SCAR=0.0
530 4241 ▶ inlined => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
531 4241 ▶ _HAS_REFUTILXS && !$Type::Tiny::AvoidCallbacks
Branch: 1 branch
BranchTrueFalseTotal
!$Type::Tiny::AvoidCallbacks ? : 3759 482 4241
532 ? "Ref::Util::XS::is_plain_hashref($_[1])"
533 : "ref($_[1]) eq 'HASH'";
534 },
535 constraint_generator => LazyLoad( HashRef => 'constraint_generator' ),
536 inline_generator => LazyLoad( HashRef => 'inline_generator' ),
537 deep_explanation => LazyLoad( HashRef => 'deep_explanation' ),
538 coercion_generator => LazyLoad( HashRef => 'coercion_generator' ),
539 10 ▶ type_default => sub { return {}; },
Subroutine __ANON__: called CC=1 SCAR=0.0
540 40 ▶ type_default_generator => sub {
Subroutine __ANON__: called CC=2 SCAR=9.2
541 40 ▶ return $Type::Tiny::parameterize_type->type_default if @_ < 2;
Branch: 1 branch
BranchTrueFalseTotal
if @_ < 2 40 0 40
542 0 return undef;
543 },
544 274 my_methods => {
545 hashref_allows_key => LazyLoad( HashRef => 'hashref_allows_key' ),
546 hashref_allows_value => LazyLoad( HashRef => 'hashref_allows_value' ),
547 },
548 }
549 );
550  
551 $meta->$add_core_type(
552 {
553 name => "ScalarRef",
554 parent => $_ref,
555 65 ▶ constraint => sub { ref $_ eq "SCALAR" or ref $_ eq "REF" },
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
ref $_ eq "SCALAR" or ref $_ eq "REF" 23 42 65
556 454 ▶ inlined => sub { "ref($_[1]) eq 'SCALAR' or ref($_[1]) eq 'REF'" },
Subroutine __ANON__: called CC=1 SCAR=0.0
557 constraint_generator => LazyLoad( ScalarRef => 'constraint_generator' ),
558 inline_generator => LazyLoad( ScalarRef => 'inline_generator' ),
559 deep_explanation => LazyLoad( ScalarRef => 'deep_explanation' ),
560 coercion_generator => LazyLoad( ScalarRef => 'coercion_generator' ),
561 1 ▶ type_default => sub { my $x; return \$x; },
Subroutine __ANON__: called CC=1 SCAR=0.0
562 }
563 274 );
564  
565 my $_obj = $meta->$add_core_type(
566 {
567 name => "Object",
568 parent => $_ref,
569 317 ▶ constraint => sub { blessed $_ },
Subroutine __ANON__: called CC=1 SCAR=0.0
570 1687 ▶ inlined => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
571 1687 ▶ _HAS_REFUTILXS && !$Type::Tiny::AvoidCallbacks
Branch: 1 branch
BranchTrueFalseTotal
!$Type::Tiny::AvoidCallbacks ? : 1462 225 1687
572 ? "Ref::Util::XS::is_blessed_ref($_[1])"
573 : $maybe_load_modules->(
574 'Scalar::Util',
575 "Scalar::Util::blessed($_[1])"
576 );
577 },
578 274 is_object => 1,
579 }
580 );
581  
582 $meta->$add_core_type(
583 {
584 name => "Maybe",
585 parent => $_item,
586 11 ▶ constraint_generator => sub {
Subroutine __ANON__: called CC=4 SCAR=14.0
587 11 ▶ return $meta->get_type( 'Maybe' ) unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 11 11
588
589 11 Type::Tiny::check_parameter_count_for_parameterized_type( 'Types::Standard', 'Maybe', \@_, 1 );
590 11 my $param = Types::TypeTiny::to_TypeTiny( shift );
591 11 ▶ Types::TypeTiny::is_TypeTiny( $param )
Branch: 1 branch
BranchTrueFalseTotal
Types::TypeTiny::is_TypeTiny($param) or &_croak("Parameter to Maybe[`a] expected to be a type constraint; got $param") 11 0 11
592 or _croak(
593 "Parameter to Maybe[`a] expected to be a type constraint; got $param" );
594
595 11 my $param_compiled_check = $param->compiled_check;
596 11 my @xsub;
597 11 if ( Type::Tiny::_USE_XS ) {
598 11 my $paramname = Type::Tiny::XS::is_known( $param_compiled_check );
599 11 ▶ push @xsub, Type::Tiny::XS::get_coderef_for( "Maybe[$paramname]" )
Branch: 1 branch
BranchTrueFalseTotal
if $paramname 11 0 11
600 if $paramname;
601 }
602 elsif ( Type::Tiny::_USE_MOUSE and $param->_has_xsub ) {
603 require Mouse::Util::TypeConstraints;
604 my $maker = "Mouse::Util::TypeConstraints"->can( "_parameterize_Maybe_for" );
605 push @xsub, $maker->( $param ) if $maker;
606 }
607
608 return (
609 7 ▶ sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
610 7 my $value = shift;
611 7 ▶ return !!1 unless defined $value;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $value 2 5 7
612 5 return $param->check( $value );
613 },
614 11 @xsub,
615 );
616 },
617 11 ▶ inline_generator => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
618 11 my $param = shift;
619
620 11 my $param_compiled_check = $param->compiled_check;
621 11 my $xsubname;
622 11 if ( Type::Tiny::_USE_XS ) {
623 11 my $paramname = Type::Tiny::XS::is_known( $param_compiled_check );
624 11 $xsubname = Type::Tiny::XS::get_subname_for( "Maybe[$paramname]" );
625 }
626
627 11 ▶ return unless $param->can_be_inlined;
Branch: 1 branch
BranchTrueFalseTotal
unless $param->can_be_inlined 0 11 11
628 55 ▶ return sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
629 55 my $v = $_[1];
630 55 ▶ return "$xsubname\($v\)" if $xsubname && !$Type::Tiny::AvoidCallbacks;
Branch: 1 branch
BranchTrueFalseTotal
if $xsubname and not $Type::Tiny::AvoidCallbacks 30 25 55
Condition66%2/3
$xsubname and not $Type::Tiny::AvoidCallbacks
!ll&&!rl&&r
02530
MC/DC50%1/2
$xsubname and not $Type::Tiny::AvoidCallbacks
$xsubname not $Type::Tiny::AvoidCallbacks
Truth table66%2/3
A and not(B)
A= $xsubnameB= not $Type::Tiny::AvoidCallbacks
ABresult
0X0
100
111
631 25 my $param_check = $param->inline_check( $v );
632 25 "!defined($v) or $param_check";
633 11 };
634 },
635 1 ▶ deep_explanation => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
636 1 my ( $type, $value, $varname ) = @_;
637 1 my $param = $type->parameters->[0];
638
639 return [
640 sprintf( '%s is defined', Type::Tiny::_dd( $value ) ),
641 sprintf(
642 '"%s" constrains the value with "%s" if it is defined', $type, $param
643 ),
644 1 @{ $param->validate_explain( $value, $varname ) },
645 ];
646 },
647 2 ▶ coercion_generator => sub {
Subroutine __ANON__: called CC=2 SCAR=7.1
648 2 my ( $parent, $child, $param ) = @_;
649 2 ▶ return unless $param->has_coercion;
Branch: 1 branch
BranchTrueFalseTotal
unless $param->has_coercion 0 2 2
650 2 return $param->coercion;
651 },
652 3 ▶ type_default => sub { return undef; },
Subroutine __ANON__: called CC=1 SCAR=0.0
653 11 ▶ type_default_generator => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
654 11 ▶ $_[0]->type_default || $Type::Tiny::parameterize_type->type_default ;
Branch: 1 branch
BranchTrueFalseTotal
$_[0]->type_default or $Type::Tiny::parameterize_type->type_default 10 1 11
655 },
656 }
657 274 );
658  
659 my $_map = $meta->$add_core_type(
660 {
661 name => "Map",
662 parent => $_hash,
663 constraint_generator => LazyLoad( Map => 'constraint_generator' ),
664 inline_generator => LazyLoad( Map => 'inline_generator' ),
665 deep_explanation => LazyLoad( Map => 'deep_explanation' ),
666 coercion_generator => LazyLoad( Map => 'coercion_generator' ),
667 my_methods => {
668 hashref_allows_key => LazyLoad( Map => 'hashref_allows_key' ),
669 hashref_allows_value => LazyLoad( Map => 'hashref_allows_value' ),
670 },
671 25 ▶ type_default_generator => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
672 25 return $Type::Tiny::parameterize_type->type_default;
673 },
674 }
675 274 );
676  
677 my $_Optional = $meta->add_type(
678 {
679 name => "Optional",
680 parent => $_item,
681 59 ▶ constraint_generator => sub {
Subroutine __ANON__: called CC=3 SCAR=11.2
682 59 ▶ return $meta->get_type( 'Optional' ) unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 59 59
683
684 59 Type::Tiny::check_parameter_count_for_parameterized_type( 'Types::Standard', 'Optional', \@_, 1 );
685 59 my $param = Types::TypeTiny::to_TypeTiny( shift );
686 59 ▶ Types::TypeTiny::is_TypeTiny( $param )
Branch: 1 branch
BranchTrueFalseTotal
Types::TypeTiny::is_TypeTiny($param) or &_croak("Parameter to Optional[`a] expected to be a type constraint; got $param") 59 0 59
687 or _croak(
688 "Parameter to Optional[`a] expected to be a type constraint; got $param" );
689
690 101 ▶ sub { $param->check( $_[0] ) }
Subroutine __ANON__: called CC=1 SCAR=0.0
691 59 },
692 59 ▶ inline_generator => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
693 59 my $param = shift;
694 59 ▶ return unless $param->can_be_inlined;
Branch: 1 branch
BranchTrueFalseTotal
unless $param->can_be_inlined 7 52 59
695 463 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
696 463 my $v = $_[1];
697 463 $param->inline_check( $v );
698 52 };
699 },
700 69 ▶ deep_explanation => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
701 69 my ( $type, $value, $varname ) = @_;
702 69 my $param = $type->parameters->[0];
703
704 return [
705 sprintf( '%s exists', $varname ),
706 sprintf( '"%s" constrains %s with "%s" if it exists', $type, $varname, $param ),
707 69 @{ $param->validate_explain( $value, $varname ) },
708 ];
709 },
710 46 ▶ coercion_generator => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
711 46 my ( $parent, $child, $param ) = @_;
712 46 ▶ return unless $param->has_coercion;
Branch: 1 branch
BranchTrueFalseTotal
unless $param->has_coercion 21 25 46
713 25 return $param->coercion;
714 },
715 59 ▶ type_default_generator => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
716 59 return $_[0]->type_default;
717 },
718 }
719 274 );
720  
721 274 my $_slurpy;
722 $_slurpy = $meta->add_type(
723 {
724 name => "Slurpy",
725 slurpy => 1,
726 parent => $_item,
727 186 ▶ constraint_generator => sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
728 186 my $self = $_slurpy;
729
730 186 Type::Tiny::check_parameter_count_for_parameterized_type( 'Types::Standard', 'Slurpy', \@_, 1 );
731 186 ▶ my $param = @_ ? Types::TypeTiny::to_TypeTiny(shift) : $_any;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 186 0 186
732 186 ▶ Types::TypeTiny::is_TypeTiny( $param )
Branch: 1 branch
BranchTrueFalseTotal
Types::TypeTiny::is_TypeTiny($param) or &_croak("Parameter to Slurpy[`a] expected to be a type constraint; got $param") 184 2 186
733 or _croak(
734 "Parameter to Slurpy[`a] expected to be a type constraint; got $param" );
735
736 return $self->create_child_type(
737 slurpy => 1,
738 display_name => $self->name_generator->( $self, $param ),
739 parameters => [ $param ],
740 137 ▶ constraint => sub { $param->check( $_[0] ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
741 type_default => $param->type_default,
742 184 ▶ _build_coercion => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
743 184 my $coercion = shift;
744 184 ▶ $coercion->add_type_coercions( @{ $param->coercion->type_coercion_map } )
Branch: 1 branch
BranchTrueFalseTotal
if $param->has_coercion 20 164 184
745 if $param->has_coercion;
746 184 $coercion->freeze;
747 },
748 $param->can_be_inlined
749 480 ▶ ? ( inlined => sub { $param->inline_check( $_[1] ) } )
Subroutine __ANON__: called CC=1 SCAR=0.0
750 184 ▶ : (),
Branch: 1 branch
BranchTrueFalseTotal
$param->can_be_inlined ? : 180 4 184
751 );
752 },
753 5 ▶ deep_explanation => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
754 5 my ( $type, $value, $varname ) = @_;
755 5 my $param = $type->parameters->[0];
756 return [
757 sprintf( '%s is slurpy', $varname ),
758 5 @{ $param->validate_explain( $value, $varname ) },
759 ];
760 },
761 my_methods => {
762 216 ▶ 'unslurpy' => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
763 216 my $self = shift;
764 $self->{_my_unslurpy} ||= $self->find_parent(
765 74 ▶ sub { $_->parent->{uniq} == $_slurpy->{uniq} }
Subroutine __ANON__: called CC=1 SCAR=0.0
766 216 ▶ )->type_parameter;
Condition66%2/3
$self->{"_my_unslurpy"} ||= $self->find_parent(sub { $_->parent->{"uniq"} == $_slurpy->{"uniq"}; } )->type_parameter
l!l&&r!l&&!r
147690
MC/DC0%0/2
$self->{"_my_unslurpy"} ||= $self->find_parent(sub { $_->parent->{"uniq"} == $_slurpy->{"uniq"}; } )->type_parameter
$self->{"_my_unslurpy"} $self->find_parent(sub { $_->parent->{"uniq"} == $_slurpy->{"uniq"}; } )->type_parameter
Truth table66%2/3
A ||= B
A= $self->{"_my_unslurpy"}B= $self->find_parent(sub { $_->parent->{"uniq"} == $_slurpy->{"uniq"}; } )->type_parameter
ABresult
1X1
011
000
767 },
768 148 ▶ 'slurp_into' => sub {
Subroutine __ANON__: called CC=5 SCAR=16.6
769 148 my $self = shift;
770 my $parameters = $self->find_parent(
771 153 ▶ sub { $_->parent->{uniq} == $_slurpy->{uniq} }
Subroutine __ANON__: called CC=1 SCAR=0.0
772 148 )->parameters;
773 148 ▶ if ( $parameters->[1] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parameters->[1]) 0 148 148
774 0 return $parameters->[1];
775 }
776 148 my $constraint = $parameters->[0];
777 148 ▶ return 'HASH'
Branch: 1 branch
BranchTrueFalseTotal
if $constraint->is_a_type_of(&HashRef()) or $constraint->is_a_type_of(&Map()) or $constraint->is_a_type_of(&Dict()) 97 51 148
Condition66%4/6
$constraint->is_a_type_of(&HashRef()) or $constraint->is_a_type_of(&Map()) or $constraint->is_a_type_of(&Dict())
l!l&&r!l&&!r
97051
$constraint->is_a_type_of(&HashRef()) or $constraint->is_a_type_of(&Map())
l!l&&r!l&&!r
97051
MC/DC33%1/3
$constraint->is_a_type_of(&HashRef()) or $constraint->is_a_type_of(&Map()) or $constraint->is_a_type_of(&Dict())
$constraint->is_a_type_of(&HashRef()) $constraint->is_a_type_of(&Map()) $constraint->is_a_type_of(&Dict())
Truth table50%2/4
A or B or C
A= $constraint->is_a_type_of(&HashRef())B= $constraint->is_a_type_of(&Map())C= $constraint->is_a_type_of(&Dict())
ABCresult
1XX1
01X1
0011
0000
778 if $constraint->is_a_type_of( HashRef() )
779 or $constraint->is_a_type_of( Map() )
780 or $constraint->is_a_type_of( Dict() );
781 51 return 'ARRAY';
782 },
783 },
784 }
785 274 );
786  
787 97 ▶sub slurpy {
Subroutine slurpy: called CC=3 SCAR=11.0
Pod documented
788 97 my $t = shift;
789 97 my $s = $_slurpy->of( $t );
790 95 ▶ $s->{slurpy} ||= 1;
Condition50%1/2
$s->{"slurpy"} ||= 1
l!l
950
MC/DC0%0/1
$s->{"slurpy"} ||= 1
$s->{"slurpy"}
Truth table50%1/2
A
A= $s->{"slurpy"}
Aresult
11
00
791 95 ▶ wantarray ? ( $s, @_ ) : $s;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 94 1 95
792 }
793  
794 $meta->$add_core_type(
795 {
796 name => "Tuple",
797 parent => $_arr,
798 55 ▶ name_generator => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
799 55 my ( $s, @a ) = @_;
800 55 sprintf( '%s[%s]', $s, join q[,], @a );
801 },
802 274 constraint_generator => LazyLoad( Tuple => 'constraint_generator' ),
803 inline_generator => LazyLoad( Tuple => 'inline_generator' ),
804 deep_explanation => LazyLoad( Tuple => 'deep_explanation' ),
805 coercion_generator => LazyLoad( Tuple => 'coercion_generator' ),
806 }
807 );
808  
809 $meta->add_type(
810 {
811 name => "CycleTuple",
812 parent => $_arr,
813 8 ▶ name_generator => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
814 8 my ( $s, @a ) = @_;
815 8 sprintf( '%s[%s]', $s, join q[,], @a );
816 },
817 274 constraint_generator => LazyLoad( CycleTuple => 'constraint_generator' ),
818 inline_generator => LazyLoad( CycleTuple => 'inline_generator' ),
819 deep_explanation => LazyLoad( CycleTuple => 'deep_explanation' ),
820 coercion_generator => LazyLoad( CycleTuple => 'coercion_generator' ),
821 }
822 );
823  
824 $meta->add_type(
825 {
826 name => "Dict",
827 parent => $_hash,
828 64 ▶ name_generator => sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
829 64 my ( $s, @p ) = @_;
830 64 ▶ my $l = @p
Branch: 1 branch
BranchTrueFalseTotal
@p && Types::TypeTiny::is_TypeTiny($p[-1]) && $p[-1]->is_strictly_a_type_of(&Slurpy()) ? : 21 43 64
Condition83%5/6
@p and Types::TypeTiny::is_TypeTiny($p[-1]) and $p[-1]->is_strictly_a_type_of(&Slurpy())
!ll&&!rl&&r
24121
@p and Types::TypeTiny::is_TypeTiny($p[-1])
!ll&&!rl&&r
2062
MC/DC66%2/3
@p and Types::TypeTiny::is_TypeTiny($p[-1]) and $p[-1]->is_strictly_a_type_of(&Slurpy())
@p Types::TypeTiny::is_TypeTiny($p[-1]) $p[-1]->is_strictly_a_type_of(&Slurpy())
Truth table75%3/4
A and B and C
A= @pB= Types::TypeTiny::is_TypeTiny($p[-1])C= $p[-1]->is_strictly_a_type_of(&Slurpy())
ABCresult
0XX0
10X0
1100
1111
831 && Types::TypeTiny::is_TypeTiny( $p[-1] )
832 && $p[-1]->is_strictly_a_type_of( Types::Standard::Slurpy() )
833 ? pop(@p)
834 : undef;
835 64 my %a = @p;
836 sprintf(
837 '%s[%s%s]', $s,
838 64 ▶ join( q[,], map sprintf( "%s=>%s", $_, $a{$_} ), sort keys %a ),
Branch: 1 branch
BranchTrueFalseTotal
$l ? : 21 43 64
839 $l ? ",$l" : ''
840 );
841 },
842 274 constraint_generator => LazyLoad( Dict => 'constraint_generator' ),
843 inline_generator => LazyLoad( Dict => 'inline_generator' ),
844 deep_explanation => LazyLoad( Dict => 'deep_explanation' ),
845 coercion_generator => LazyLoad( Dict => 'coercion_generator' ),
846 my_methods => {
847 dict_is_slurpy => LazyLoad( Dict => 'dict_is_slurpy' ),
848 hashref_allows_key => LazyLoad( Dict => 'hashref_allows_key' ),
849 hashref_allows_value => LazyLoad( Dict => 'hashref_allows_value' ),
850 },
851 }
852 );
853  
854 $meta->add_type(
855 {
856 name => "Overload",
857 parent => $_obj,
858 34 ▶ constraint => sub { require overload; overload::Overloaded( $_ ) },
Subroutine __ANON__: called CC=1 SCAR=0.0
859 682 ▶ inlined => sub {
Subroutine __ANON__: called CC=2 SCAR=7.6
860 $maybe_load_modules->(
861 qw/ Scalar::Util overload /,
862 682 ▶ $INC{'overload.pm'}
Branch: 1 branch
BranchTrueFalseTotal
$INC{'overload.pm'} ? : 682 0 682
863 ? "Scalar::Util::blessed($_[1]) and overload::Overloaded($_[1])"
864 : "Scalar::Util::blessed($_[1]) and do { use overload (); overload::Overloaded($_[1]) }"
865 );
866 },
867 24 ▶ constraint_generator => sub {
Subroutine __ANON__: called CC=3 SCAR=11.1
868 24 ▶ return $meta->get_type( 'Overload' ) unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 24 24
869
870 my @operations = map {
871 24 ▶ Types::TypeTiny::is_StringLike( $_ )
Branch: 1 branch
BranchTrueFalseTotal
Types::TypeTiny::is_StringLike($_) ? : 27 0 27
872 ? "$_"
873 : _croak( "Parameters to Overload[`a] expected to be a strings; got $_" );
874 } @_;
875
876 24 require overload;
877 14 ▶ return sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
878 14 my $value = shift;
879 14 for my $op ( @operations ) {
880 17 ▶ return unless overload::Method( $value, $op );
Branch: 1 branch
BranchTrueFalseTotal
unless overload::Method($value, $op) 6 11 17
881 }
882 8 return !!1;
883 }
884 24 },
885 24 ▶ inline_generator => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
886 24 my @operations = @_;
887 137 ▶ return sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
888 137 require overload;
889 137 my $v = $_[1];
890 137 $maybe_load_modules->(
891 qw/ Scalar::Util overload /,
892 join " and ",
893 "Scalar::Util::blessed($v)",
894 map "overload::Method($v, q[$_])", @operations
895 );
896 24 };
897 },
898 274 is_object => 1,
899 }
900 );
901  
902 274 $meta->add_type(
903 {
904 name => "StrMatch",
905 parent => $_str,
906 constraint_generator => LazyLoad( StrMatch => 'constraint_generator' ),
907 inline_generator => LazyLoad( StrMatch => 'inline_generator' ),
908 }
909 );
910  
911 $meta->add_type(
912 {
913 name => "OptList",
914 parent => $_arr,
915 18 ▶ constraint => sub {
Subroutine __ANON__: called CC=5 SCAR=16.1
916 18 for my $inner ( @$_ ) {
917 15 ▶ return unless ref( $inner ) eq q(ARRAY);
Branch: 1 branch
BranchTrueFalseTotal
unless ref $inner eq "ARRAY" 3 12 15
918 12 ▶ return unless @$inner == 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @$inner == 2 6 6 12
919 6 ▶ return unless is_Str( $inner->[0] );
Branch: 1 branch
BranchTrueFalseTotal
unless is_Str($inner->[0]) 0 6 6
920 }
921 9 return !!1;
922 },
923 690 ▶ inlined => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
924 690 my ( $self, $var ) = @_;
925 690 my $Str_check = Str()->inline_check( '$inner->[0]' );
926 690 my @code = 'do { my $ok = 1; ';
927 690 push @code, sprintf( 'for my $inner (@{%s}) { no warnings; ', $var );
928 690 push @code,
929 sprintf(
930 '($ok=0) && last unless ref($inner) eq q(ARRAY) && @$inner == 2 && (%s); ',
931 $Str_check
932 );
933 690 push @code, '} ';
934 690 push @code, '$ok }';
935 690 return ( undef, join( q( ), @code ) );
936 },
937 1 ▶ type_default => sub { return [] },
Subroutine __ANON__: called CC=1 SCAR=0.0
938 }
939 274 );
940  
941 $meta->add_type(
942 {
943 name => "Tied",
944 parent => $_ref,
945 83 ▶ constraint => sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
946 !!tied(
947 19 ▶ Scalar::Util::reftype( $_ ) eq 'HASH' ? %{$_}
Branch: 1 branch
BranchTrueFalseTotal
builtin::reftype($_) eq 'ARRAY' ? : 27 37 64
948 27 ▶ : Scalar::Util::reftype( $_ ) eq 'ARRAY' ? @{$_}
Branch: 1 branch
BranchTrueFalseTotal
builtin::reftype($_) =~ /^(SCALAR|REF)$/ ? : 29 8 37
949 83 ▶ : Scalar::Util::reftype( $_ ) =~ /^(SCALAR|REF)$/ ? ${$_}
Branch: 1 branch
BranchTrueFalseTotal
builtin::reftype($_) eq 'HASH' ? : 19 64 83
950 : undef
951 );
952 },
953 686 ▶ inlined => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
954 686 my ( $self, $var ) = @_;
955 686 $maybe_load_modules->(
956 qw/ Scalar::Util /,
957 $self->parent->inline_check( $var )
958 . " and !!tied(Scalar::Util::reftype($var) eq 'HASH' ? \%{$var} : Scalar::Util::reftype($var) eq 'ARRAY' ? \@{$var} : Scalar::Util::reftype($var) =~ /^(SCALAR|REF)\$/ ? \${$var} : undef)"
959 );
960 },
961 36 ▶ name_generator => sub {
Subroutine __ANON__: called CC=3 SCAR=11.0
962 36 my $self = shift;
963 36 my $param = Types::TypeTiny::to_TypeTiny( shift );
964 36 ▶ unless ( Types::TypeTiny::is_TypeTiny( $param ) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (Types::TypeTiny::is_TypeTiny($param)) 26 10 36
965 26 ▶ Types::TypeTiny::is_StringLike( $param )
Branch: 1 branch
BranchTrueFalseTotal
Types::TypeTiny::is_StringLike($param) or &_croak("Parameter to Tied[`a] expected to be a class name; got $param") 26 0 26
966 or _croak( "Parameter to Tied[`a] expected to be a class name; got $param" );
967 26 require B;
968 26 return sprintf( "%s[%s]", $self, B::perlstring( $param ) );
969 }
970 10 return sprintf( "%s[%s]", $self, $param );
971 },
972 274 constraint_generator => LazyLoad( Tied => 'constraint_generator' ),
973 inline_generator => LazyLoad( Tied => 'inline_generator' ),
974 }
975 );
976  
977 $meta->add_type(
978 {
979 name => "InstanceOf",
980 parent => $_obj,
981 31 ▶ constraint_generator => sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
982 31 ▶ return $meta->get_type( 'InstanceOf' ) unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 1 30 31
983 30 require Type::Tiny::Class;
984 my @classes = map {
985 30 ▶ Types::TypeTiny::is_TypeTiny( $_ )
Branch: 1 branch
BranchTrueFalseTotal
Types::TypeTiny::is_TypeTiny($_) ? : 0 32 32
986 ? $_
987 : "Type::Tiny::Class"->new(
988 class => $_,
989 display_name => sprintf( 'InstanceOf[%s]', B::perlstring( $_ ) )
990 )
991 } @_;
992 30 ▶ return $classes[0] if @classes == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @classes == 1 28 2 30
993
994 2 require B;
995 2 require Type::Tiny::Union;
996 2 return "Type::Tiny::Union"->new(
997 type_constraints => \@classes,
998 display_name => sprintf(
999 'InstanceOf[%s]', join q[,], map B::perlstring( $_->class ), @classes
1000 ),
1001 );
1002 },
1003 }
1004 274 );
1005  
1006 $meta->add_type(
1007 {
1008 name => "ConsumerOf",
1009 parent => $_obj,
1010 21 ▶ constraint_generator => sub {
Subroutine __ANON__: called CC=4 SCAR=13.9
1011 21 ▶ return $meta->get_type( 'ConsumerOf' ) unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 1 20 21
1012 20 require B;
1013 20 require Type::Tiny::Role;
1014 my @roles = map {
1015 20 ▶ Types::TypeTiny::is_TypeTiny( $_ )
Branch: 1 branch
BranchTrueFalseTotal
Types::TypeTiny::is_TypeTiny($_) ? : 0 22 22
1016 ? $_
1017 : "Type::Tiny::Role"->new(
1018 role => $_,
1019 display_name => sprintf( 'ConsumerOf[%s]', B::perlstring( $_ ) )
1020 )
1021 } @_;
1022 20 ▶ return $roles[0] if @roles == 1;
Branch: 1 branch
BranchTrueFalseTotal
if @roles == 1 18 2 20
1023
1024 2 require Type::Tiny::Intersection;
1025 2 return "Type::Tiny::Intersection"->new(
1026 type_constraints => \@roles,
1027 display_name => sprintf(
1028 'ConsumerOf[%s]', join q[,], map B::perlstring( $_->role ), @roles
1029 ),
1030 );
1031 },
1032 }
1033 274 );
1034  
1035 $meta->add_type(
1036 {
1037 name => "HasMethods",
1038 parent => $_obj,
1039 11 ▶ constraint_generator => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
1040 11 ▶ return $meta->get_type( 'HasMethods' ) unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 2 9 11
1041 9 require B;
1042 9 require Type::Tiny::Duck;
1043 9 return "Type::Tiny::Duck"->new(
1044 methods => \@_,
1045 display_name =>
1046 sprintf( 'HasMethods[%s]', join q[,], map B::perlstring( $_ ), @_ ),
1047 );
1048 },
1049 }
1050 274 );
1051  
1052 $meta->add_type(
1053 {
1054 name => "Enum",
1055 parent => $_str,
1056 173 ▶ constraint_generator => sub {
Subroutine __ANON__: called CC=9 SCAR=22.0
1057 173 ▶ return $meta->get_type( 'Enum' ) unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 1 172 173
1058 172 my $coercion;
1059 172 ▶ if ( ref( $_[0] ) and ref( $_[0] ) eq 'SCALAR' ) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $_[0] and ref $_[0] eq 'SCALAR') { } 1 171 172
elsif (ref $_[0] and not builtin::blessed($_[0]) or builtin::blessed($_[0]) and $_[0]->isa('Type::Coercion')) { } 1 339 340
Condition100%3/3
ref $_[0] and ref $_[0] eq "SCALAR"
!ll&&!rl&&r
16921
MC/DC100%2/2
ref $_[0] and ref $_[0] eq "SCALAR"
ref $_[0] ref $_[0] eq "SCALAR"
Truth table100%3/3
A and B
A= ref $_[0]B= ref $_[0] eq "SCALAR"
ABresult
0X0
100
111
1060 1 $coercion = ${ +shift };
1061 }
1062 ▶ elsif ( ref( $_[0] ) && !blessed( $_[0] )
Condition77%7/9
ref $_[0] and not builtin::blessed($_[0]) or builtin::blessed($_[0]) and $_[0]->isa("Type::Coercion")
l!l&&r!l&&!r
10170
ref $_[0] and not builtin::blessed($_[0])
!ll&&!rl&&r
16911
builtin::blessed($_[0]) and $_[0]->isa("Type::Coercion")
!ll&&!rl&&r
16910
MC/DC50%2/4
ref $_[0] and not builtin::blessed($_[0]) or builtin::blessed($_[0]) and $_[0]->isa("Type::Coercion")
ref $_[0] not builtin::blessed($_[0]) builtin::blessed($_[0]) $_[0]->isa("Type::Coercion")
Truth table42%3/7
A and not(B) or C and D
A= ref $_[0]B= not builtin::blessed($_[0])C= builtin::blessed($_[0])D= $_[0]->isa("Type::Coercion")
ABCDresult
11XX1
0X111
10111
0X0X0
0X100
100X0
10100
1063 or blessed( $_[0] ) && $_[0]->isa( 'Type::Coercion' ) )
1064 {
1065 1 $coercion = shift;
1066 }
1067 172 require B;
1068 172 require Type::Tiny::Enum;
1069 172 ▶ return "Type::Tiny::Enum"->new(
Branch: 1 branch
BranchTrueFalseTotal
$coercion ? : 2 170 172
1070 values => \@_,
1071 display_name => sprintf( 'Enum[%s]', join q[,], map B::perlstring( $_ ), @_ ),
1072 $coercion ? ( coercion => $coercion ) : (),
1073 );
1074 },
1075 274 type_default => undef,
1076 }
1077 );
1078  
1079 274 $meta->add_coercion(
1080 {
1081 name => "MkOpt",
1082 type_constraint => $meta->get_type( "OptList" ),
1083 type_coercion_map => [
1084 $_arr, q{ Exporter::Tiny::mkopt($_) },
1085 $_hash, q{ Exporter::Tiny::mkopt($_) },
1086 $_undef, q{ [] },
1087 ],
1088 }
1089 );
1090  
1091 $meta->add_coercion(
1092 {
1093 name => "Join",
1094 type_constraint => $_str,
1095 4 ▶ coercion_generator => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
1096 4 my ( $self, $target, $sep ) = @_;
1097 4 ▶ Types::TypeTiny::is_StringLike( $sep )
Branch: 1 branch
BranchTrueFalseTotal
Types::TypeTiny::is_StringLike($sep) or &_croak("Parameter to Join[`a] expected to be a string; got $sep") 4 0 4
1098 or _croak( "Parameter to Join[`a] expected to be a string; got $sep" );
1099 4 require B;
1100 4 $sep = B::perlstring( $sep );
1101 4 return ( ArrayRef(), qq{ join($sep, \@\$_) } );
1102 },
1103 }
1104 274 );
1105  
1106 $meta->add_coercion(
1107 {
1108 name => "Split",
1109 type_constraint => $_arr,
1110 8 ▶ coercion_generator => sub {
Subroutine __ANON__: called CC=2 SCAR=7.0
1111 8 my ( $self, $target, $re ) = @_;
1112 8 ▶ ref( $re ) eq q(Regexp)
Branch: 1 branch
BranchTrueFalseTotal
ref $re eq "Regexp" or &_croak("Parameter to Split[`a] expected to be a regular expression; got $re") 8 0 8
1113 or _croak(
1114 "Parameter to Split[`a] expected to be a regular expression; got $re" );
1115 8 my $regexp_string = "$re";
1116 8 $regexp_string =~ s/\\\//\\\\\//g; # toothpicks
1117 8 return ( Str(), qq{ [split /$regexp_string/, \$_] } );
1118 },
1119 }
1120 274 );
1121  
1122 274 __PACKAGE__->meta->make_immutable;
1123  
1124 274 1;
1125  
1126 __END__
« blib/lib/Type/Tiny/Class.pm ↑ Summary blib/lib/Reply/Plugin/TypeTiny.pm »