← Index
NYTProf Performance Profile   « line view »
For fastest.pl
  Run on Fri Jan 31 20:48:16 2014
Reported on Fri Jan 31 20:49:41 2014

Filename/opt/perl-5.18.1/lib/site_perl/5.18.1/Types/Standard.pm
StatementsExecuted 113 statements in 7.69ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1112.54ms18.5msTypes::Standard::::BEGIN@18 Types::Standard::BEGIN@18
11128µs82µsTypes::Standard::::__ANON__[:564] Types::Standard::__ANON__[:564]
11124µs24µsTypes::Standard::::BEGIN@3 Types::Standard::BEGIN@3
246121µs21µsTypes::Standard::::LazyLoad Types::Standard::LazyLoad
11113µs48µsTypes::Standard::LazyLoad::::BEGIN@53 Types::Standard::LazyLoad::BEGIN@53
11113µs63µsTypes::Standard::::__ANON__[:577] Types::Standard::__ANON__[:577]
11112µs73µsTypes::Standard::::__ANON__[:159] Types::Standard::__ANON__[:159]
11112µs45µsTypes::Standard::_Stringable::::BEGIN@45Types::Standard::_Stringable::BEGIN@45
11112µs25µsTypes::Standard::::BEGIN@70 Types::Standard::BEGIN@70
11111µs56µsTypes::Standard::::BEGIN@22 Types::Standard::BEGIN@22
1119µs25µsTypes::Standard::::BEGIN@4 Types::Standard::BEGIN@4
1119µs14µsTypes::Standard::::BEGIN@5 Types::Standard::BEGIN@5
1118µs22µsTypes::Standard::::BEGIN@28 Types::Standard::BEGIN@28
1116µs6µsTypes::Standard::::BEGIN@7 Types::Standard::BEGIN@7
1115µs5µsTypes::Standard::::BEGIN@72 Types::Standard::BEGIN@72
1115µs5µsTypes::Standard::::BEGIN@443 Types::Standard::BEGIN@443
1114µs4µsTypes::Standard::::BEGIN@13 Types::Standard::BEGIN@13
1114µs4µsTypes::Standard::::BEGIN@23 Types::Standard::BEGIN@23
1114µs4µsTypes::Standard::::__ANON__[:126] Types::Standard::__ANON__[:126]
1113µs3µsTypes::Standard::::__ANON__[:188] Types::Standard::__ANON__[:188]
1113µs3µsTypes::Standard::::__ANON__[:133] Types::Standard::__ANON__[:133]
1113µs3µsTypes::Standard::::__ANON__[:448] Types::Standard::__ANON__[:448]
1112µs2µsTypes::Standard::::__ANON__[:116] Types::Standard::__ANON__[:116]
1112µs2µsTypes::Standard::::__ANON__[:274] Types::Standard::__ANON__[:274]
1112µs2µsTypes::Standard::::__ANON__[:196] Types::Standard::__ANON__[:196]
0000s0sTypes::Standard::LazyLoad::::__ANON__[:66] Types::Standard::LazyLoad::__ANON__[:66]
0000s0sTypes::Standard::::Stringable Types::Standard::Stringable
0000s0sTypes::Standard::_Stringable::::__ANON__[:45]Types::Standard::_Stringable::__ANON__[:45]
0000s0sTypes::Standard::::__ANON__[:100] Types::Standard::__ANON__[:100]
0000s0sTypes::Standard::::__ANON__[:107] Types::Standard::__ANON__[:107]
0000s0sTypes::Standard::::__ANON__[:108] Types::Standard::__ANON__[:108]
0000s0sTypes::Standard::::__ANON__[:115] Types::Standard::__ANON__[:115]
0000s0sTypes::Standard::::__ANON__[:123] Types::Standard::__ANON__[:123]
0000s0sTypes::Standard::::__ANON__[:132] Types::Standard::__ANON__[:132]
0000s0sTypes::Standard::::__ANON__[:148] Types::Standard::__ANON__[:148]
0000s0sTypes::Standard::::__ANON__[:172] Types::Standard::__ANON__[:172]
0000s0sTypes::Standard::::__ANON__[:173] Types::Standard::__ANON__[:173]
0000s0sTypes::Standard::::__ANON__[:180] Types::Standard::__ANON__[:180]
0000s0sTypes::Standard::::__ANON__[:181] Types::Standard::__ANON__[:181]
0000s0sTypes::Standard::::__ANON__[:187] Types::Standard::__ANON__[:187]
0000s0sTypes::Standard::::__ANON__[:195] Types::Standard::__ANON__[:195]
0000s0sTypes::Standard::::__ANON__[:208] Types::Standard::__ANON__[:208]
0000s0sTypes::Standard::::__ANON__[:209] Types::Standard::__ANON__[:209]
0000s0sTypes::Standard::::__ANON__[:216] Types::Standard::__ANON__[:216]
0000s0sTypes::Standard::::__ANON__[:217] Types::Standard::__ANON__[:217]
0000s0sTypes::Standard::::__ANON__[:228] Types::Standard::__ANON__[:228]
0000s0sTypes::Standard::::__ANON__[:235] Types::Standard::__ANON__[:235]
0000s0sTypes::Standard::::__ANON__[:236] Types::Standard::__ANON__[:236]
0000s0sTypes::Standard::::__ANON__[:243] Types::Standard::__ANON__[:243]
0000s0sTypes::Standard::::__ANON__[:244] Types::Standard::__ANON__[:244]
0000s0sTypes::Standard::::__ANON__[:251] Types::Standard::__ANON__[:251]
0000s0sTypes::Standard::::__ANON__[:252] Types::Standard::__ANON__[:252]
0000s0sTypes::Standard::::__ANON__[:262] Types::Standard::__ANON__[:262]
0000s0sTypes::Standard::::__ANON__[:266] Types::Standard::__ANON__[:266]
0000s0sTypes::Standard::::__ANON__[:273] Types::Standard::__ANON__[:273]
0000s0sTypes::Standard::::__ANON__[:285] Types::Standard::__ANON__[:285]
0000s0sTypes::Standard::::__ANON__[:286] Types::Standard::__ANON__[:286]
0000s0sTypes::Standard::::__ANON__[:297] Types::Standard::__ANON__[:297]
0000s0sTypes::Standard::::__ANON__[:298] Types::Standard::__ANON__[:298]
0000s0sTypes::Standard::::__ANON__[:309] Types::Standard::__ANON__[:309]
0000s0sTypes::Standard::::__ANON__[:310] Types::Standard::__ANON__[:310]
0000s0sTypes::Standard::::__ANON__[:330] Types::Standard::__ANON__[:330]
0000s0sTypes::Standard::::__ANON__[:331] Types::Standard::__ANON__[:331]
0000s0sTypes::Standard::::__ANON__[:339] Types::Standard::__ANON__[:339]
0000s0sTypes::Standard::::__ANON__[:340] Types::Standard::__ANON__[:340]
0000s0sTypes::Standard::::__ANON__[:350] Types::Standard::__ANON__[:350]
0000s0sTypes::Standard::::__ANON__[:356] Types::Standard::__ANON__[:356]
0000s0sTypes::Standard::::__ANON__[:379] Types::Standard::__ANON__[:379]
0000s0sTypes::Standard::::__ANON__[:380] Types::Standard::__ANON__[:380]
0000s0sTypes::Standard::::__ANON__[:388] Types::Standard::__ANON__[:388]
0000s0sTypes::Standard::::__ANON__[:389] Types::Standard::__ANON__[:389]
0000s0sTypes::Standard::::__ANON__[:399] Types::Standard::__ANON__[:399]
0000s0sTypes::Standard::::__ANON__[:405] Types::Standard::__ANON__[:405]
0000s0sTypes::Standard::::__ANON__[:420] Types::Standard::__ANON__[:420]
0000s0sTypes::Standard::::__ANON__[:436] Types::Standard::__ANON__[:436]
0000s0sTypes::Standard::::__ANON__[:447] Types::Standard::__ANON__[:447]
0000s0sTypes::Standard::::__ANON__[:465] Types::Standard::__ANON__[:465]
0000s0sTypes::Standard::::__ANON__[:466] Types::Standard::__ANON__[:466]
0000s0sTypes::Standard::::__ANON__[:474] Types::Standard::__ANON__[:474]
0000s0sTypes::Standard::::__ANON__[:475] Types::Standard::__ANON__[:475]
0000s0sTypes::Standard::::__ANON__[:504] Types::Standard::__ANON__[:504]
0000s0sTypes::Standard::::__ANON__[:508] Types::Standard::__ANON__[:508]
0000s0sTypes::Standard::::__ANON__[:510] Types::Standard::__ANON__[:510]
0000s0sTypes::Standard::::__ANON__[:528] Types::Standard::__ANON__[:528]
0000s0sTypes::Standard::::__ANON__[:539] Types::Standard::__ANON__[:539]
0000s0sTypes::Standard::::__ANON__[:541] Types::Standard::__ANON__[:541]
0000s0sTypes::Standard::::__ANON__[:554] Types::Standard::__ANON__[:554]
0000s0sTypes::Standard::::__ANON__[:572] Types::Standard::__ANON__[:572]
0000s0sTypes::Standard::::__ANON__[:590] Types::Standard::__ANON__[:590]
0000s0sTypes::Standard::::__ANON__[:607] Types::Standard::__ANON__[:607]
0000s0sTypes::Standard::::__ANON__[:608] Types::Standard::__ANON__[:608]
0000s0sTypes::Standard::::__ANON__[:628] Types::Standard::__ANON__[:628]
0000s0sTypes::Standard::::__ANON__[:629] Types::Standard::__ANON__[:629]
0000s0sTypes::Standard::::__ANON__[:651] Types::Standard::__ANON__[:651]
0000s0sTypes::Standard::::__ANON__[:673] Types::Standard::__ANON__[:673]
0000s0sTypes::Standard::::__ANON__[:687] Types::Standard::__ANON__[:687]
0000s0sTypes::Standard::::__ANON__[:701] Types::Standard::__ANON__[:701]
0000s0sTypes::Standard::::__ANON__[:724] Types::Standard::__ANON__[:724]
0000s0sTypes::Standard::::__ANON__[:737] Types::Standard::__ANON__[:737]
0000s0sTypes::Standard::::__ANON__[:77] Types::Standard::__ANON__[:77]
0000s0sTypes::Standard::::__ANON__[:83] Types::Standard::__ANON__[:83]
0000s0sTypes::Standard::::__ANON__[:91] Types::Standard::__ANON__[:91]
0000s0sTypes::Standard::::__ANON__[:92] Types::Standard::__ANON__[:92]
0000s0sTypes::Standard::::__ANON__[:99] Types::Standard::__ANON__[:99]
0000s0sTypes::Standard::::_croak Types::Standard::_croak
0000s0sTypes::Standard::::_is_class_loaded Types::Standard::_is_class_loaded
0000s0sTypes::Standard::::slurpy Types::Standard::slurpy
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Types::Standard;
2
3267µs124µs
# spent 24µs within Types::Standard::BEGIN@3 which was called: # once (24µs+0s) by Typed::BEGIN@10 at line 3
use 5.006001;
# spent 24µs making 1 call to Types::Standard::BEGIN@3
4229µs240µs
# spent 25µs (9+16) within Types::Standard::BEGIN@4 which was called: # once (9µs+16µs) by Typed::BEGIN@10 at line 4
use strict;
# spent 25µs making 1 call to Types::Standard::BEGIN@4 # spent 16µs making 1 call to strict::import
5272µs218µs
# spent 14µs (9+5) within Types::Standard::BEGIN@5 which was called: # once (9µs+5µs) by Typed::BEGIN@10 at line 5
use warnings;
# spent 14µs making 1 call to Types::Standard::BEGIN@5 # spent 5µs making 1 call to warnings::import
6
7
# spent 6µs within Types::Standard::BEGIN@7 which was called: # once (6µs+0s) by Typed::BEGIN@10 at line 11
BEGIN {
821µs eval { require re };
91700ns if ($] < 5.008) { require Devel::TypeTiny::Perl56Compat };
1016µs if ($] < 5.010) { require Devel::TypeTiny::Perl58Compat };
11139µs16µs}
# spent 6µs making 1 call to Types::Standard::BEGIN@7
12
13
# spent 4µs within Types::Standard::BEGIN@13 which was called: # once (4µs+0s) by Typed::BEGIN@10 at line 16
BEGIN {
141500ns $Types::Standard::AUTHORITY = 'cpan:TOBYINK';
1515µs $Types::Standard::VERSION = '0.038';
16129µs14µs}
# spent 4µs making 1 call to Types::Standard::BEGIN@13
17
182162µs218.7ms
# spent 18.5ms (2.54+15.9) within Types::Standard::BEGIN@18 which was called: # once (2.54ms+15.9ms) by Typed::BEGIN@10 at line 18
use Type::Library -base;
# spent 18.5ms making 1 call to Types::Standard::BEGIN@18 # spent 206µs making 1 call to Exporter::Tiny::import
19
2012µsour @EXPORT_OK = qw( slurpy );
21
22232µs2101µs
# spent 56µs (11+45) within Types::Standard::BEGIN@22 which was called: # once (11µs+45µs) by Typed::BEGIN@10 at line 22
use Scalar::Util qw( blessed looks_like_number );
# spent 56µs making 1 call to Types::Standard::BEGIN@22 # spent 45µs making 1 call to Exporter::import
23265µs14µs
# spent 4µs within Types::Standard::BEGIN@23 which was called: # once (4µs+0s) by Typed::BEGIN@10 at line 23
use Types::TypeTiny ();
# spent 4µs making 1 call to Types::Standard::BEGIN@23
24
25sub _is_class_loaded {
26 return !!0 if ref $_[0];
27 return !!0 if not $_[0];
282221µs235µs
# spent 22µs (8+13) within Types::Standard::BEGIN@28 which was called: # once (8µs+13µs) by Typed::BEGIN@10 at line 28
my $stash = do { no strict 'refs'; \%{"$_[0]\::"} };
# spent 22µs making 1 call to Types::Standard::BEGIN@28 # spent 13µs making 1 call to strict::unimport
29 return !!1 if exists $stash->{'ISA'};
30 return !!1 if exists $stash->{'VERSION'};
31 foreach my $globref (values %$stash) {
32 return !!1 if *{$globref}{CODE};
33 }
34 return !!0;
35}
36
37sub _croak ($;@) { require Error::TypeTiny; goto \&Error::TypeTiny::croak }
38
3917µs112µsmy $meta = __PACKAGE__->meta;
# spent 12µs making 1 call to Type::Library::meta
40
41sub Stringable (&)
42{
43 package #private
44 Types::Standard::_Stringable;
452255µs277µs
# spent 45µs (12+32) within Types::Standard::_Stringable::BEGIN@45 which was called: # once (12µs+32µs) by Typed::BEGIN@10 at line 45
use overload q[""] => sub { $_[0]{text} ||= $_[0]{code}->() }, fallback => 1;
# spent 45µs making 1 call to Types::Standard::_Stringable::BEGIN@45 # spent 32µs making 1 call to overload::import
46 bless +{ code => $_[0] };
47}
48
49sub LazyLoad ($$)
50
# spent 21µs within Types::Standard::LazyLoad which was called 24 times, avg 879ns/call: # 4 times (4µs+0s) by Typed::BEGIN@10 at line 437, avg 925ns/call # 4 times (4µs+0s) by Typed::BEGIN@10 at line 275, avg 900ns/call # 4 times (4µs+0s) by Typed::BEGIN@10 at line 421, avg 900ns/call # 4 times (4µs+0s) by Typed::BEGIN@10 at line 359, avg 875ns/call # 4 times (3µs+0s) by Typed::BEGIN@10 at line 299, avg 850ns/call # 4 times (3µs+0s) by Typed::BEGIN@10 at line 287, avg 825ns/call
{
51 package #private
52 Types::Standard::LazyLoad;
53
# spent 48µs (13+35) within Types::Standard::LazyLoad::BEGIN@53 which was called: # once (13µs+35µs) by Typed::BEGIN@10 at line 66
use overload fallback => 1, q[&{}] => sub {
54 my ($typename, $function) = @{$_[0]};
55 my $type = $meta->get_type($typename);
56 my $class = "Types::Standard::$typename";
57 eval "require $class; 1" or die($@);
58 # Majorly break encapsulation for Type::Tiny :-O
59 for my $key (keys %$type)
60 {
61 next unless ref($type->{$key}) eq __PACKAGE__;
62 my $f = $type->{$key}[1];
63 $type->{$key} = $class->can("__$f");
64 }
65 return $class->can("__$function");
66261µs283µs };
# spent 48µs making 1 call to Types::Standard::LazyLoad::BEGIN@53 # spent 35µs making 1 call to overload::import
672456µs bless \@_;
68}
69
70279µs238µs
# spent 25µs (12+14) within Types::Standard::BEGIN@70 which was called: # once (12µs+14µs) by Typed::BEGIN@10 at line 70
no warnings;
# spent 25µs making 1 call to Types::Standard::BEGIN@70 # spent 14µs making 1 call to warnings::unimport
71
7213.26ms15µs
# spent 5µs within Types::Standard::BEGIN@72 which was called: # once (5µs+0s) by Typed::BEGIN@10 at line 72
BEGIN { *STRICTNUM = $ENV{PERL_TYPES_STANDARD_STRICTNUM} ? sub(){!!1} : sub(){!!0} };
# spent 5µs making 1 call to Types::Standard::BEGIN@72
73
74my $_any = $meta->add_type({
75 name => "Any",
76 _is_core => 1,
77 inlined => sub { "!!1" },
7818µs16.07ms});
# spent 6.07ms making 1 call to Type::Library::add_type
79
80my $_item = $meta->add_type({
81 name => "Item",
82 _is_core => 1,
83 inlined => sub { "!!1" },
8416µs1568µs parent => $_any,
# spent 568µs making 1 call to Type::Library::add_type
85});
86
87$meta->add_type({
88 name => "Bool",
89 _is_core => 1,
90 parent => $_item,
91 constraint => sub { !defined $_ or $_ eq q() or $_ eq '0' or $_ eq '1' },
92 inlined => sub { "!defined $_[1] or $_[1] eq q() or $_[1] eq '0' or $_[1] eq '1'" },
9318µs1539µs});
# spent 539µs making 1 call to Type::Library::add_type
94
95my $_undef = $meta->add_type({
96 name => "Undef",
97 _is_core => 1,
98 parent => $_item,
99 constraint => sub { !defined $_ },
100 inlined => sub { "!defined($_[1])" },
10118µs1540µs});
# spent 540µs making 1 call to Type::Library::add_type
102
103my $_def = $meta->add_type({
104 name => "Defined",
105 _is_core => 1,
106 parent => $_item,
107 constraint => sub { defined $_ },
108 inlined => sub { "defined($_[1])" },
10918µs1548µs});
# spent 548µs making 1 call to Type::Library::add_type
110
111my $_val = $meta->add_type({
112 name => "Value",
113 _is_core => 1,
114 parent => $_def,
115 constraint => sub { not ref $_ },
11615µs
# spent 2µs within Types::Standard::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/Types/Standard.pm:116] which was called: # once (2µs+0s) by Type::Tiny::inline_check at line 605 of Type/Tiny.pm
inlined => sub { "defined($_[1]) and not ref($_[1])" },
11718µs1529µs});
# spent 529µs making 1 call to Type::Library::add_type
118
119my $_str = $meta->add_type({
120 name => "Str",
121 _is_core => 1,
122 parent => $_val,
123 constraint => sub { ref(\$_) eq 'SCALAR' or ref(\(my $val = $_)) eq 'SCALAR' },
124
# spent 4µs within Types::Standard::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/Types/Standard.pm:126] which was called: # once (4µs+0s) by Type::Tiny::inline_check at line 605 of Type/Tiny.pm
inlined => sub {
12516µs "defined($_[1]) and do { ref(\\$_[1]) eq 'SCALAR' or ref(\\(my \$val = $_[1])) eq 'SCALAR' }"
126 },
12718µs1544µs});
# spent 544µs making 1 call to Type::Library::add_type
128
129my $_laxnum = $meta->add_type({
130 name => "LaxNum",
131 parent => $_str,
132 constraint => sub { looks_like_number $_ },
13315µs
# spent 3µs within Types::Standard::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/Types/Standard.pm:133] which was called: # once (3µs+0s) by Type::Tiny::inline_check at line 605 of Type/Tiny.pm
inlined => sub { "defined($_[1]) && !ref($_[1]) && Scalar::Util::looks_like_number($_[1])" },
13418µs1830µs});
# spent 830µs making 1 call to Type::Library::add_type
135
136my $_strictnum = $meta->add_type({
137 name => "StrictNum",
138 parent => $_str,
139 constraint => sub {
140 my $val = $_;
141 ($val =~ /\A[+-]?[0-9]+\z/) ||
142 ( $val =~ /\A(?:[+-]?) #matches optional +- in the beginning
143 (?=[0-9]|\.[0-9]) #matches previous +- only if there is something like 3 or .3
144 [0-9]* #matches 0-9 zero or more times
145 (?:\.[0-9]+)? #matches optional .89 or nothing
146 (?:[Ee](?:[+-]?[0-9]+))? #matches E1 or e1 or e-1 or e+1 etc
147 \z/x );
148 },
149
# spent 73µs (12+61) within Types::Standard::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/Types/Standard.pm:159] which was called: # once (12µs+61µs) by Type::Tiny::inline_check at line 605 of Type/Tiny.pm
inlined => sub {
150120µs2900ns 'my $val = '.$_[1].';'.
# spent 900ns making 1 call to Types::Standard::Value # spent 60µs making 1 call to Type::Tiny::inline_check, recursion: max depth 1, sum of overlapping time 60µs
151 Value()->inline_check('$val')
152 .' && ( $val =~ /\A[+-]?[0-9]+\z/ || '
153 . '$val =~ /\A(?:[+-]?) # matches optional +- in the beginning
154 (?=[0-9]|\.[0-9]) # matches previous +- only if there is something like 3 or .3
155 [0-9]* # matches 0-9 zero or more times
156 (?:\.[0-9]+)? # matches optional .89 or nothing
157 (?:[Ee](?:[+-]?[0-9]+))? # matches E1 or e1 or e-1 or e+1 etc
158 \z/x ); '
159 },
16018µs1912µs});
# spent 912µs making 1 call to Type::Library::add_type
161
16214µs1535µsmy $_num = $meta->add_type({
# spent 535µs making 1 call to Type::Library::add_type
163 name => "Num",
164 _is_core => 1,
165 parent => (STRICTNUM ? $_strictnum : $_laxnum),
166});
167
168$meta->add_type({
169 name => "Int",
170 _is_core => 1,
171 parent => $_num,
172 constraint => sub { /\A-?[0-9]+\z/ },
173 inlined => sub { "defined $_[1] and $_[1] =~ /\\A-?[0-9]+\\z/" },
17417µs1546µs});
# spent 546µs making 1 call to Type::Library::add_type
175
176my $_classn = $meta->add_type({
177 name => "ClassName",
178 _is_core => 1,
179 parent => $_str,
180 constraint => sub { goto \&_is_class_loaded },
181 inlined => sub { "Types::Standard::_is_class_loaded($_[1])" },
18218µs1539µs});
# spent 539µs making 1 call to Type::Library::add_type
183
184$meta->add_type({
185 name => "RoleName",
186 parent => $_classn,
187 constraint => sub { not $_->can("new") },
18816µs
# spent 3µs within Types::Standard::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/Types/Standard.pm:188] which was called: # once (3µs+0s) by Type::Tiny::inline_check at line 605 of Type/Tiny.pm
inlined => sub { "Types::Standard::_is_class_loaded($_[1]) and not $_[1]\->can('new')" },
18918µs1781µs});
# spent 781µs making 1 call to Type::Library::add_type
190
191my $_ref = $meta->add_type({
192 name => "Ref",
193 _is_core => 1,
194 parent => $_def,
195 constraint => sub { ref $_ },
19614µs
# spent 2µs within Types::Standard::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/Types/Standard.pm:196] which was called: # once (2µs+0s) by Type::Tiny::inline_check at line 605 of Type/Tiny.pm
inlined => sub { "!!ref($_[1])" },
197 constraint_generator => sub
198 {
199 return $meta->get_type('Ref') unless @_;
200
201 my $reftype = shift;
202 Types::TypeTiny::StringLike->check($reftype)
203 or _croak("Parameter to Ref[`a] expected to be string; got $reftype");
204
205 $reftype = "$reftype";
206 return sub {
207 ref($_[0]) and Scalar::Util::reftype($_[0]) eq $reftype;
208 }
209 },
210 inline_generator => sub
211 {
212 my $reftype = shift;
213 return sub {
214 my $v = $_[1];
215 "ref($v) and Scalar::Util::reftype($v) eq q($reftype)";
216 };
217 },
218 deep_explanation => sub {
219 require B;
220 my ($type, $value, $varname) = @_;
221 my $param = $type->parameters->[0];
222 return if $type->check($value);
223 my $reftype = Scalar::Util::reftype($value);
224 return [
225 sprintf('"%s" constrains reftype(%s) to be equal to %s', $type, $varname, B::perlstring($param)),
226 sprintf('reftype(%s) is %s', $varname, defined($reftype) ? B::perlstring($reftype) : "undef"),
227 ];
228 },
229113µs1624µs});
# spent 624µs making 1 call to Type::Library::add_type
230
231$meta->add_type({
232 name => "CodeRef",
233 _is_core => 1,
234 parent => $_ref,
235 constraint => sub { ref $_ eq "CODE" },
236 inlined => sub { "ref($_[1]) eq 'CODE'" },
23718µs1519µs});
# spent 519µs making 1 call to Type::Library::add_type
238
239$meta->add_type({
240 name => "RegexpRef",
241 _is_core => 1,
242 parent => $_ref,
243 constraint => sub { ref($_) && !!re::is_regexp($_) },
244 inlined => sub { "ref($_[1]) && !!re::is_regexp($_[1])" },
24518µs1537µs});
# spent 537µs making 1 call to Type::Library::add_type
246
247$meta->add_type({
248 name => "GlobRef",
249 _is_core => 1,
250 parent => $_ref,
251 constraint => sub { ref $_ eq "GLOB" },
252 inlined => sub { "ref($_[1]) eq 'GLOB'" },
25317µs1536µs});
# spent 536µs making 1 call to Type::Library::add_type
254
255$meta->add_type({
256 name => "FileHandle",
257 _is_core => 1,
258 parent => $_ref,
259 constraint => sub {
260 (ref($_) eq "GLOB" && Scalar::Util::openhandle($_))
261 or (blessed($_) && $_->isa("IO::Handle"))
262 },
263 inlined => sub {
264 "(ref($_[1]) eq \"GLOB\" && Scalar::Util::openhandle($_[1])) ".
265 "or (Scalar::Util::blessed($_[1]) && $_[1]\->isa(\"IO::Handle\"))"
266 },
26718µs1536µs});
# spent 536µs making 1 call to Type::Library::add_type
268
269my $_arr = $meta->add_type({
270 name => "ArrayRef",
271 _is_core => 1,
272 parent => $_ref,
273 constraint => sub { ref $_ eq "ARRAY" },
27414µs
# spent 2µs within Types::Standard::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/Types/Standard.pm:274] which was called: # once (2µs+0s) by Type::Tiny::inline_check at line 605 of Type/Tiny.pm
inlined => sub { "ref($_[1]) eq 'ARRAY'" },
275112µs5594µs constraint_generator => LazyLoad(ArrayRef => 'constraint_generator'),
# spent 590µs making 1 call to Type::Library::add_type # spent 4µs making 4 calls to Types::Standard::LazyLoad, avg 900ns/call
276 inline_generator => LazyLoad(ArrayRef => 'inline_generator'),
277 deep_explanation => LazyLoad(ArrayRef => 'deep_explanation'),
278 coercion_generator => LazyLoad(ArrayRef => 'coercion_generator'),
279});
280
281my $_hash = $meta->add_type({
282 name => "HashRef",
283 _is_core => 1,
284 parent => $_ref,
285 constraint => sub { ref $_ eq "HASH" },
286 inlined => sub { "ref($_[1]) eq 'HASH'" },
287112µs5580µs constraint_generator => LazyLoad(HashRef => 'constraint_generator'),
# spent 576µs making 1 call to Type::Library::add_type # spent 3µs making 4 calls to Types::Standard::LazyLoad, avg 825ns/call
288 inline_generator => LazyLoad(HashRef => 'inline_generator'),
289 deep_explanation => LazyLoad(HashRef => 'deep_explanation'),
290 coercion_generator => LazyLoad(HashRef => 'coercion_generator'),
291});
292
293$meta->add_type({
294 name => "ScalarRef",
295 _is_core => 1,
296 parent => $_ref,
297 constraint => sub { ref $_ eq "SCALAR" or ref $_ eq "REF" },
298 inlined => sub { "ref($_[1]) eq 'SCALAR' or ref($_[1]) eq 'REF'" },
299112µs5581µs constraint_generator => LazyLoad(ScalarRef => 'constraint_generator'),
# spent 578µs making 1 call to Type::Library::add_type # spent 3µs making 4 calls to Types::Standard::LazyLoad, avg 850ns/call
300 inline_generator => LazyLoad(ScalarRef => 'inline_generator'),
301 deep_explanation => LazyLoad(ScalarRef => 'deep_explanation'),
302 coercion_generator => LazyLoad(ScalarRef => 'coercion_generator'),
303});
304
305my $_obj = $meta->add_type({
306 name => "Object",
307 _is_core => 1,
308 parent => $_ref,
309 constraint => sub { blessed $_ },
310 inlined => sub { "Scalar::Util::blessed($_[1])" },
31118µs1542µs});
# spent 542µs making 1 call to Type::Library::add_type
312
313$meta->add_type({
314 name => "Maybe",
315 _is_core => 1,
316 parent => $_item,
317 constraint_generator => sub
318 {
319 return $meta->get_type('Maybe') unless @_;
320
321 my $param = Types::TypeTiny::to_TypeTiny(shift);
322 Types::TypeTiny::TypeTiny->check($param)
323 or _croak("Parameter to Maybe[`a] expected to be a type constraint; got $param");
324
325 return sub
326 {
327 my $value = shift;
328 return !!1 unless defined $value;
329 return $param->check($value);
330 };
331 },
332 inline_generator => sub {
333 my $param = shift;
334 return unless $param->can_be_inlined;
335 return sub {
336 my $v = $_[1];
337 my $param_check = $param->inline_check($v);
338 "!defined($v) or $param_check";
339 };
340 },
341 deep_explanation => sub {
342 my ($type, $value, $varname) = @_;
343 my $param = $type->parameters->[0];
344
345 return [
346 sprintf('%s is defined', Type::Tiny::_dd($value)),
347 sprintf('"%s" constrains the value with "%s" if it is defined', $type, $param),
348 @{ $param->validate_explain($value, $varname) },
349 ];
350 },
351 coercion_generator => sub
352 {
353 my ($parent, $child, $param) = @_;
354 return unless $param->has_coercion;
355 return $param->coercion;
356 },
357117µs1579µs});
# spent 579µs making 1 call to Type::Library::add_type
358
35918µs5581µsmy $_map = $meta->add_type({
# spent 578µs making 1 call to Type::Library::add_type # spent 4µs making 4 calls to Types::Standard::LazyLoad, avg 875ns/call
360 name => "Map",
361 parent => $_hash,
362 constraint_generator => LazyLoad(Map => 'constraint_generator'),
363 inline_generator => LazyLoad(Map => 'inline_generator'),
364 deep_explanation => LazyLoad(Map => 'deep_explanation'),
365 coercion_generator => LazyLoad(Map => 'coercion_generator'),
366});
367
368my $_Optional = $meta->add_type({
369 name => "Optional",
370 parent => $_item,
371 constraint_generator => sub
372 {
373 return $meta->get_type('Optional') unless @_;
374
375 my $param = Types::TypeTiny::to_TypeTiny(shift);
376 Types::TypeTiny::TypeTiny->check($param)
377 or _croak("Parameter to Optional[`a] expected to be a type constraint; got $param");
378
379 sub { exists($_[0]) ? $param->check($_[0]) : !!1 }
380 },
381 inline_generator => sub {
382 my $param = shift;
383 return unless $param->can_be_inlined;
384 return sub {
385 my $v = $_[1];
386 my $param_check = $param->inline_check($v);
387 "!exists($v) or $param_check";
388 };
389 },
390 deep_explanation => sub {
391 my ($type, $value, $varname) = @_;
392 my $param = $type->parameters->[0];
393
394 return [
395 sprintf('%s exists', $varname),
396 sprintf('"%s" constrains %s with "%s" if it exists', $type, $varname, $param),
397 @{ $param->validate_explain($value, $varname) },
398 ];
399 },
400 coercion_generator => sub
401 {
402 my ($parent, $child, $param) = @_;
403 return unless $param->has_coercion;
404 return $param->coercion;
405 },
406112µs1606µs});
# spent 606µs making 1 call to Type::Library::add_type
407
408sub slurpy {
409 my $t = shift;
410 wantarray ? (+{ slurpy => $t }, @_) : +{ slurpy => $t };
411}
412
413$meta->add_type({
414 name => "Tuple",
415 parent => $_arr,
416 name_generator => sub
417 {
418 my ($s, @a) = @_;
419 sprintf('%s[%s]', $s, join q[,], map { ref($_) eq "HASH" ? sprintf("slurpy %s", $_->{slurpy}) : $_ } @a);
420 },
421110µs5605µs constraint_generator => LazyLoad(Tuple => 'constraint_generator'),
# spent 601µs making 1 call to Type::Library::add_type # spent 4µs making 4 calls to Types::Standard::LazyLoad, avg 900ns/call
422 inline_generator => LazyLoad(Tuple => 'inline_generator'),
423 deep_explanation => LazyLoad(Tuple => 'deep_explanation'),
424 coercion_generator => LazyLoad(Tuple => 'coercion_generator'),
425});
426
427$meta->add_type({
428 name => "Dict",
429 parent => $_hash,
430 name_generator => sub
431 {
432 my ($s, @p) = @_;
433 my $l = ref($p[-1]) eq q(HASH) ? pop(@p)->{slurpy} : undef;
434 my %a = @p;
435 sprintf('%s[%s%s]', $s, join(q[,], map sprintf("%s=>%s", $_, $a{$_}), sort keys %a), $l ? ",slurpy $l" : '');
436 },
437114µs5594µs constraint_generator => LazyLoad(Dict => 'constraint_generator'),
# spent 590µs making 1 call to Type::Library::add_type # spent 4µs making 4 calls to Types::Standard::LazyLoad, avg 925ns/call
438 inline_generator => LazyLoad(Dict => 'inline_generator'),
439 deep_explanation => LazyLoad(Dict => 'deep_explanation'),
440 coercion_generator => LazyLoad(Dict => 'coercion_generator'),
441});
442
44322.70ms15µs
# spent 5µs within Types::Standard::BEGIN@443 which was called: # once (5µs+0s) by Typed::BEGIN@10 at line 443
use overload ();
# spent 5µs making 1 call to Types::Standard::BEGIN@443
444$meta->add_type({
445 name => "Overload",
446 parent => $_obj,
447 constraint => sub { overload::Overloaded($_) },
44816µs
# spent 3µs within Types::Standard::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/Types/Standard.pm:448] which was called: # once (3µs+0s) by Type::Tiny::inline_check at line 605 of Type/Tiny.pm
inlined => sub { "Scalar::Util::blessed($_[1]) and overload::Overloaded($_[1])" },
449 constraint_generator => sub
450 {
451 return $meta->get_type('Overload') unless @_;
452
453 my @operations = map {
454 Types::TypeTiny::StringLike->check($_)
455 ? "$_"
456 : _croak("Parameters to Overload[`a] expected to be a strings; got $_");
457 } @_;
458
459 return sub {
460 my $value = shift;
461 for my $op (@operations) {
462 return unless overload::Method($value, $op);
463 }
464 return !!1;
465 }
466 },
467 inline_generator => sub {
468 my @operations = @_;
469 return sub {
470 my $v = $_[1];
471 join " and ",
472 "Scalar::Util::blessed($v)",
473 map "overload::Method($v, q[$_])", @operations;
474 };
475 },
476112µs1840µs});
# spent 840µs making 1 call to Type::Library::add_type
477
4781200nsour %_StrMatch;
479$meta->add_type({
480 name => "StrMatch",
481 parent => $_str,
482 constraint_generator => sub
483 {
484 return $meta->get_type('StrMatch') unless @_;
485
486 my ($regexp, $checker) = @_;
487
488 ref($regexp) eq 'Regexp'
489 or _croak("First parameter to StrMatch[`a] expected to be a Regexp; got $regexp");
490
491 if (@_ > 1)
492 {
493 $checker = Types::TypeTiny::to_TypeTiny($checker);
494 Types::TypeTiny::TypeTiny->check($checker)
495 or _croak("Second parameter to StrMatch[`a] expected to be a type constraint; got $checker")
496 }
497
498 $checker
499 ? sub {
500 my $value = shift;
501 return if ref($value);
502 my @m = ($value =~ $regexp);
503 $checker->check(\@m);
504 }
505 : sub {
506 my $value = shift;
507 !ref($value) and $value =~ $regexp;
508 }
509 ;
510 },
511 inline_generator => sub
512 {
513 require B;
514 my ($regexp, $checker) = @_;
515 my $regexp_string = "$regexp";
516 $_StrMatch{$regexp_string} = $regexp;
517 if ($checker)
518 {
519 return unless $checker->can_be_inlined;
520 return sub
521 {
522 my $v = $_[1];
523 sprintf
524 "!ref($v) and do { my \$m = [$v =~ \$Types::Standard::_StrMatch{%s}]; %s }",
525 B::perlstring($regexp_string),
526 $checker->inline_check('$m'),
527 ;
528 };
529 }
530 else
531 {
532 return sub
533 {
534 my $v = $_[1];
535 sprintf
536 "!ref($v) and $v =~ \$Types::Standard::_StrMatch{%s}",
537 B::perlstring($regexp_string),
538 ;
539 };
540 }
541 },
54219µs1594µs});
# spent 594µs making 1 call to Type::Library::add_type
543
544$meta->add_type({
545 name => "OptList",
546 parent => $_arr,
547 constraint => sub {
548 for my $inner (@$_) {
549 return unless ref($inner) eq q(ARRAY);
550 return unless @$inner == 2;
551 return unless is_Str($inner->[0]);
552 }
553 return !!1;
554 },
555
# spent 82µs (28+54) within Types::Standard::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/Types/Standard.pm:564] which was called: # once (28µs+54µs) by Type::Tiny::inline_check at line 605 of Type/Tiny.pm
inlined => sub {
5561800ns my ($self, $var) = @_;
55712µs2900ns my $Str_check = Str()->inline_check('$inner->[0]');
# spent 900ns making 1 call to Types::Standard::Str # spent 53µs making 1 call to Type::Tiny::inline_check, recursion: max depth 1, sum of overlapping time 53µs
5581800ns my @code = 'do { my $ok = 1; ';
55912µs push @code, sprintf('for my $inner (@{%s}) { no warnings; ', $var);
56012µs push @code, sprintf('($ok=0) && last unless ref($inner) eq q(ARRAY) && @$inner == 2 && (%s); ', $Str_check);
5611300ns push @code, '} ';
5621600ns push @code, '$ok }';
56316µs return (undef, join(q( ), @code));
564 },
565114µs11.06ms});
# spent 1.06ms making 1 call to Type::Library::add_type
566
567$meta->add_type({
568 name => "Tied",
569 parent => $_ref,
570 constraint => sub {
571 !!tied(Scalar::Util::reftype($_) eq 'HASH' ? %{$_} : Scalar::Util::reftype($_) eq 'ARRAY' ? @{$_} : ${$_})
572 },
573
# spent 63µs (13+50) within Types::Standard::__ANON__[/opt/perl-5.18.1/lib/site_perl/5.18.1/Types/Standard.pm:577] which was called: # once (13µs+50µs) by Type::Tiny::inline_check at line 605 of Type/Tiny.pm
inlined => sub {
5741600ns my ($self, $var) = @_;
575114µs21µs $self->parent->inline_check($var)
# spent 1µs making 1 call to Type::Tiny::parent # spent 49µs making 1 call to Type::Tiny::inline_check, recursion: max depth 1, sum of overlapping time 49µs
576 . " and !!tied(Scalar::Util::reftype($var) eq 'HASH' ? \%{$var} : Scalar::Util::reftype($var) eq 'ARRAY' ? \@{$var} : \${$var})"
577 },
578 name_generator => sub
579 {
580 my $self = shift;
581 my $param = Types::TypeTiny::to_TypeTiny(shift);
582 unless (Types::TypeTiny::TypeTiny->check($param))
583 {
584 Types::TypeTiny::StringLike->check($param)
585 or _croak("Parameter to Tied[`a] expected to be a class name; got $param");
586 require B;
587 return sprintf("%s[%s]", $self, B::perlstring($param));
588 }
589 return sprintf("%s[%s]", $self, $param);
590 },
591 constraint_generator => sub
592 {
593 return $meta->get_type('Tied') unless @_;
594
595 my $param = Types::TypeTiny::to_TypeTiny(shift);
596 unless (Types::TypeTiny::TypeTiny->check($param))
597 {
598 Types::TypeTiny::StringLike->check($param)
599 or _croak("Parameter to Tied[`a] expected to be a class name; got $param");
600 require Type::Tiny::Class;
601 $param = "Type::Tiny::Class"->new(class => "$param");
602 }
603
604 my $check = $param->compiled_check;
605 return sub {
606 $check->(tied(Scalar::Util::reftype($_) eq 'HASH' ? %{$_} : Scalar::Util::reftype($_) eq 'ARRAY' ? @{$_} : ${$_}));
607 };
608 },
609 inline_generator => sub {
610 my $param = Types::TypeTiny::to_TypeTiny(shift);
611 unless (Types::TypeTiny::TypeTiny->check($param))
612 {
613 Types::TypeTiny::StringLike->check($param)
614 or _croak("Parameter to Tied[`a] expected to be a class name; got $param");
615 require Type::Tiny::Class;
616 $param = "Type::Tiny::Class"->new(class => "$param");
617 }
618 return unless $param->can_be_inlined;
619
620 return sub {
621 require B;
622 my $var = $_[1];
623 sprintf(
624 "%s and do { my \$TIED = tied(Scalar::Util::reftype($var) eq 'HASH' ? \%{$var} : Scalar::Util::reftype($var) eq 'ARRAY' ? \@{$var} : \${$var}); %s }",
625 Ref()->inline_check($var),
626 $param->inline_check('$TIED')
627 );
628 };
629 },
630119µs1925µs});
# spent 925µs making 1 call to Type::Library::add_type
631
632$meta->add_type({
633 name => "InstanceOf",
634 parent => $_obj,
635 constraint_generator => sub {
636 return $meta->get_type('InstanceOf') unless @_;
637 require Type::Tiny::Class;
638 my @classes = map {
639 Types::TypeTiny::TypeTiny->check($_)
640 ? $_
641 : "Type::Tiny::Class"->new(class => $_, display_name => sprintf('InstanceOf[%s]', B::perlstring($_)))
642 } @_;
643 return $classes[0] if @classes == 1;
644
645 require B;
646 require Type::Tiny::Union;
647 return "Type::Tiny::Union"->new(
648 type_constraints => \@classes,
649 display_name => sprintf('InstanceOf[%s]', join q[,], map B::perlstring($_->class), @classes),
650 );
651 },
65217µs1687µs});
# spent 687µs making 1 call to Type::Library::add_type
653
654$meta->add_type({
655 name => "ConsumerOf",
656 parent => $_obj,
657 constraint_generator => sub {
658 return $meta->get_type('ConsumerOf') unless @_;
659 require B;
660 require Type::Tiny::Role;
661 my @roles = map {
662 Types::TypeTiny::TypeTiny->check($_)
663 ? $_
664 : "Type::Tiny::Role"->new(role => $_, display_name => sprintf('ConsumerOf[%s]', B::perlstring($_)))
665 } @_;
666 return $roles[0] if @roles == 1;
667
668 require Type::Tiny::Intersection;
669 return "Type::Tiny::Intersection"->new(
670 type_constraints => \@roles,
671 display_name => sprintf('ConsumerOf[%s]', join q[,], map B::perlstring($_->role), @roles),
672 );
673 },
67417µs1588µs});
# spent 588µs making 1 call to Type::Library::add_type
675
676$meta->add_type({
677 name => "HasMethods",
678 parent => $_obj,
679 constraint_generator => sub {
680 return $meta->get_type('HasMethods') unless @_;
681 require B;
682 require Type::Tiny::Duck;
683 return "Type::Tiny::Duck"->new(
684 methods => \@_,
685 display_name => sprintf('HasMethods[%s]', join q[,], map B::perlstring($_), @_),
686 );
687 },
68817µs16.40ms});
# spent 6.40ms making 1 call to Type::Library::add_type
689
690$meta->add_type({
691 name => "Enum",
692 parent => $_str,
693 constraint_generator => sub {
694 return $meta->get_type('Enum') unless @_;
695 require B;
696 require Type::Tiny::Enum;
697 return "Type::Tiny::Enum"->new(
698 values => \@_,
699 display_name => sprintf('Enum[%s]', join q[,], map B::perlstring($_), @_),
700 );
701 },
70217µs1605µs});
# spent 605µs making 1 call to Type::Library::add_type
703
704112µs25.12ms$meta->add_coercion({
# spent 5.11ms making 1 call to Type::Library::add_coercion # spent 16µs making 1 call to Type::Library::get_type
705 name => "MkOpt",
706 type_constraint => $meta->get_type("OptList"),
707 type_coercion_map => [
708 $_arr, q{ Exporter::Tiny::mkopt($_) },
709 $_hash, q{ Exporter::Tiny::mkopt($_) },
710 $_undef, q{ [] },
711 ],
712});
713
714$meta->add_coercion({
715 name => "Join",
716 type_constraint => $_str,
717 coercion_generator => sub {
718 my ($self, $target, $sep) = @_;
719 Types::TypeTiny::StringLike->check($sep)
720 or _croak("Parameter to Join[`a] expected to be a string; got $sep");
721 require B;
722 $sep = B::perlstring($sep);
723 return (ArrayRef(), qq{ join($sep, \@\$_) });
724 },
72518µs1364µs});
# spent 364µs making 1 call to Type::Library::add_coercion
726
727$meta->add_coercion({
728 name => "Split",
729 type_constraint => $_arr,
730 coercion_generator => sub {
731 my ($self, $target, $re) = @_;
732 ref($re) eq q(Regexp)
733 or _croak("Parameter to Split[`a] expected to be a regular expresssion; got $re");
734 my $regexp_string = "$re";
735 $regexp_string =~ s/\\\//\\\\\//g; # toothpicks
736 return (Str(), qq{ [split /$regexp_string/, \$_] });
737 },
73818µs1368µs});
# spent 368µs making 1 call to Type::Library::add_coercion
739
740197µs1;
741
742__END__