Filename | /opt/perl-5.18.1/lib/site_perl/5.18.1/Types/Standard.pm |
Statements | Executed 113 statements in 7.69ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 2.54ms | 18.5ms | BEGIN@18 | Types::Standard::
1 | 1 | 1 | 28µs | 82µs | __ANON__[:564] | Types::Standard::
1 | 1 | 1 | 24µs | 24µs | BEGIN@3 | Types::Standard::
24 | 6 | 1 | 21µs | 21µs | LazyLoad | Types::Standard::
1 | 1 | 1 | 13µs | 48µs | BEGIN@53 | Types::Standard::LazyLoad::
1 | 1 | 1 | 13µs | 63µs | __ANON__[:577] | Types::Standard::
1 | 1 | 1 | 12µs | 73µs | __ANON__[:159] | Types::Standard::
1 | 1 | 1 | 12µs | 45µs | BEGIN@45 | Types::Standard::_Stringable::
1 | 1 | 1 | 12µs | 25µs | BEGIN@70 | Types::Standard::
1 | 1 | 1 | 11µs | 56µs | BEGIN@22 | Types::Standard::
1 | 1 | 1 | 9µs | 25µs | BEGIN@4 | Types::Standard::
1 | 1 | 1 | 9µs | 14µs | BEGIN@5 | Types::Standard::
1 | 1 | 1 | 8µs | 22µs | BEGIN@28 | Types::Standard::
1 | 1 | 1 | 6µs | 6µs | BEGIN@7 | Types::Standard::
1 | 1 | 1 | 5µs | 5µs | BEGIN@72 | Types::Standard::
1 | 1 | 1 | 5µs | 5µs | BEGIN@443 | Types::Standard::
1 | 1 | 1 | 4µs | 4µs | BEGIN@13 | Types::Standard::
1 | 1 | 1 | 4µs | 4µs | BEGIN@23 | Types::Standard::
1 | 1 | 1 | 4µs | 4µs | __ANON__[:126] | Types::Standard::
1 | 1 | 1 | 3µs | 3µs | __ANON__[:188] | Types::Standard::
1 | 1 | 1 | 3µs | 3µs | __ANON__[:133] | Types::Standard::
1 | 1 | 1 | 3µs | 3µs | __ANON__[:448] | Types::Standard::
1 | 1 | 1 | 2µs | 2µs | __ANON__[:116] | Types::Standard::
1 | 1 | 1 | 2µs | 2µs | __ANON__[:274] | Types::Standard::
1 | 1 | 1 | 2µs | 2µs | __ANON__[:196] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:66] | Types::Standard::LazyLoad::
0 | 0 | 0 | 0s | 0s | Stringable | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:45] | Types::Standard::_Stringable::
0 | 0 | 0 | 0s | 0s | __ANON__[:100] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:107] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:108] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:115] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:123] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:132] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:148] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:172] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:173] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:180] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:181] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:187] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:195] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:208] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:209] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:216] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:217] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:228] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:235] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:236] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:243] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:244] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:251] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:252] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:262] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:266] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:273] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:285] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:286] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:297] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:298] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:309] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:310] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:330] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:331] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:339] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:340] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:350] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:356] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:379] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:380] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:388] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:389] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:399] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:405] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:420] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:436] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:447] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:465] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:466] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:474] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:475] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:504] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:508] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:510] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:528] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:539] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:541] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:554] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:572] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:590] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:607] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:608] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:628] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:629] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:651] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:673] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:687] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:701] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:724] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:737] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:77] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:83] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:91] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:92] | Types::Standard::
0 | 0 | 0 | 0s | 0s | __ANON__[:99] | Types::Standard::
0 | 0 | 0 | 0s | 0s | _croak | Types::Standard::
0 | 0 | 0 | 0s | 0s | _is_class_loaded | Types::Standard::
0 | 0 | 0 | 0s | 0s | slurpy | Types::Standard::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Types::Standard; | ||||
2 | |||||
3 | 2 | 67µs | 1 | 24µs | # spent 24µs within Types::Standard::BEGIN@3 which was called:
# once (24µs+0s) by Typed::BEGIN@10 at line 3 # spent 24µs making 1 call to Types::Standard::BEGIN@3 |
4 | 2 | 29µs | 2 | 40µ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 # spent 25µs making 1 call to Types::Standard::BEGIN@4
# spent 16µs making 1 call to strict::import |
5 | 2 | 72µs | 2 | 18µ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 # 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 | ||||
8 | 2 | 1µs | eval { require re }; | ||
9 | 1 | 700ns | if ($] < 5.008) { require Devel::TypeTiny::Perl56Compat }; | ||
10 | 1 | 6µs | if ($] < 5.010) { require Devel::TypeTiny::Perl58Compat }; | ||
11 | 1 | 39µs | 1 | 6µ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 | ||||
14 | 1 | 500ns | $Types::Standard::AUTHORITY = 'cpan:TOBYINK'; | ||
15 | 1 | 5µs | $Types::Standard::VERSION = '0.038'; | ||
16 | 1 | 29µs | 1 | 4µs | } # spent 4µs making 1 call to Types::Standard::BEGIN@13 |
17 | |||||
18 | 2 | 162µs | 2 | 18.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 # spent 18.5ms making 1 call to Types::Standard::BEGIN@18
# spent 206µs making 1 call to Exporter::Tiny::import |
19 | |||||
20 | 1 | 2µs | our @EXPORT_OK = qw( slurpy ); | ||
21 | |||||
22 | 2 | 32µs | 2 | 101µ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 # spent 56µs making 1 call to Types::Standard::BEGIN@22
# spent 45µs making 1 call to Exporter::import |
23 | 2 | 65µs | 1 | 4µs | # spent 4µs within Types::Standard::BEGIN@23 which was called:
# once (4µs+0s) by Typed::BEGIN@10 at line 23 # spent 4µs making 1 call to Types::Standard::BEGIN@23 |
24 | |||||
25 | sub _is_class_loaded { | ||||
26 | return !!0 if ref $_[0]; | ||||
27 | return !!0 if not $_[0]; | ||||
28 | 2 | 221µs | 2 | 35µ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 # 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 | |||||
37 | sub _croak ($;@) { require Error::TypeTiny; goto \&Error::TypeTiny::croak } | ||||
38 | |||||
39 | 1 | 7µs | 1 | 12µs | my $meta = __PACKAGE__->meta; # spent 12µs making 1 call to Type::Library::meta |
40 | |||||
41 | sub Stringable (&) | ||||
42 | { | ||||
43 | package #private | ||||
44 | Types::Standard::_Stringable; | ||||
45 | 2 | 255µs | 2 | 77µ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 # 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 | |||||
49 | sub 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 | ||||
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"); | ||||
66 | 2 | 61µs | 2 | 83µs | }; # spent 48µs making 1 call to Types::Standard::LazyLoad::BEGIN@53
# spent 35µs making 1 call to overload::import |
67 | 24 | 56µs | bless \@_; | ||
68 | } | ||||
69 | |||||
70 | 2 | 79µs | 2 | 38µ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 # spent 25µs making 1 call to Types::Standard::BEGIN@70
# spent 14µs making 1 call to warnings::unimport |
71 | |||||
72 | 1 | 3.26ms | 1 | 5µs | # spent 5µs within Types::Standard::BEGIN@72 which was called:
# once (5µs+0s) by Typed::BEGIN@10 at line 72 # spent 5µs making 1 call to Types::Standard::BEGIN@72 |
73 | |||||
74 | my $_any = $meta->add_type({ | ||||
75 | name => "Any", | ||||
76 | _is_core => 1, | ||||
77 | inlined => sub { "!!1" }, | ||||
78 | 1 | 8µs | 1 | 6.07ms | }); # spent 6.07ms making 1 call to Type::Library::add_type |
79 | |||||
80 | my $_item = $meta->add_type({ | ||||
81 | name => "Item", | ||||
82 | _is_core => 1, | ||||
83 | inlined => sub { "!!1" }, | ||||
84 | 1 | 6µs | 1 | 568µ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'" }, | ||||
93 | 1 | 8µs | 1 | 539µs | }); # spent 539µs making 1 call to Type::Library::add_type |
94 | |||||
95 | my $_undef = $meta->add_type({ | ||||
96 | name => "Undef", | ||||
97 | _is_core => 1, | ||||
98 | parent => $_item, | ||||
99 | constraint => sub { !defined $_ }, | ||||
100 | inlined => sub { "!defined($_[1])" }, | ||||
101 | 1 | 8µs | 1 | 540µs | }); # spent 540µs making 1 call to Type::Library::add_type |
102 | |||||
103 | my $_def = $meta->add_type({ | ||||
104 | name => "Defined", | ||||
105 | _is_core => 1, | ||||
106 | parent => $_item, | ||||
107 | constraint => sub { defined $_ }, | ||||
108 | inlined => sub { "defined($_[1])" }, | ||||
109 | 1 | 8µs | 1 | 548µs | }); # spent 548µs making 1 call to Type::Library::add_type |
110 | |||||
111 | my $_val = $meta->add_type({ | ||||
112 | name => "Value", | ||||
113 | _is_core => 1, | ||||
114 | parent => $_def, | ||||
115 | constraint => sub { not ref $_ }, | ||||
116 | 1 | 5µ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 | ||
117 | 1 | 8µs | 1 | 529µs | }); # spent 529µs making 1 call to Type::Library::add_type |
118 | |||||
119 | my $_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 | ||||
125 | 1 | 6µs | "defined($_[1]) and do { ref(\\$_[1]) eq 'SCALAR' or ref(\\(my \$val = $_[1])) eq 'SCALAR' }" | ||
126 | }, | ||||
127 | 1 | 8µs | 1 | 544µs | }); # spent 544µs making 1 call to Type::Library::add_type |
128 | |||||
129 | my $_laxnum = $meta->add_type({ | ||||
130 | name => "LaxNum", | ||||
131 | parent => $_str, | ||||
132 | constraint => sub { looks_like_number $_ }, | ||||
133 | 1 | 5µ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 | ||
134 | 1 | 8µs | 1 | 830µs | }); # spent 830µs making 1 call to Type::Library::add_type |
135 | |||||
136 | my $_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 | ||||
150 | 1 | 20µs | 2 | 900ns | '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 | }, | ||||
160 | 1 | 8µs | 1 | 912µs | }); # spent 912µs making 1 call to Type::Library::add_type |
161 | |||||
162 | 1 | 4µs | 1 | 535µs | my $_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/" }, | ||||
174 | 1 | 7µs | 1 | 546µs | }); # spent 546µs making 1 call to Type::Library::add_type |
175 | |||||
176 | my $_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])" }, | ||||
182 | 1 | 8µs | 1 | 539µ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") }, | ||||
188 | 1 | 6µ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 | ||
189 | 1 | 8µs | 1 | 781µs | }); # spent 781µs making 1 call to Type::Library::add_type |
190 | |||||
191 | my $_ref = $meta->add_type({ | ||||
192 | name => "Ref", | ||||
193 | _is_core => 1, | ||||
194 | parent => $_def, | ||||
195 | constraint => sub { ref $_ }, | ||||
196 | 1 | 4µ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 | ||
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 | }, | ||||
229 | 1 | 13µs | 1 | 624µ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'" }, | ||||
237 | 1 | 8µs | 1 | 519µ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])" }, | ||||
245 | 1 | 8µs | 1 | 537µ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'" }, | ||||
253 | 1 | 7µs | 1 | 536µ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 | }, | ||||
267 | 1 | 8µs | 1 | 536µs | }); # spent 536µs making 1 call to Type::Library::add_type |
268 | |||||
269 | my $_arr = $meta->add_type({ | ||||
270 | name => "ArrayRef", | ||||
271 | _is_core => 1, | ||||
272 | parent => $_ref, | ||||
273 | constraint => sub { ref $_ eq "ARRAY" }, | ||||
274 | 1 | 4µ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 | ||
275 | 1 | 12µs | 5 | 594µ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 | |||||
281 | my $_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'" }, | ||||
287 | 1 | 12µs | 5 | 580µ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'" }, | ||||
299 | 1 | 12µs | 5 | 581µ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 | |||||
305 | my $_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])" }, | ||||
311 | 1 | 8µs | 1 | 542µ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 | }, | ||||
357 | 1 | 17µs | 1 | 579µs | }); # spent 579µs making 1 call to Type::Library::add_type |
358 | |||||
359 | 1 | 8µs | 5 | 581µs | my $_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 | |||||
368 | my $_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 | }, | ||||
406 | 1 | 12µs | 1 | 606µs | }); # spent 606µs making 1 call to Type::Library::add_type |
407 | |||||
408 | sub 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 | }, | ||||
421 | 1 | 10µs | 5 | 605µ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 | }, | ||||
437 | 1 | 14µs | 5 | 594µ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 | |||||
443 | 2 | 2.70ms | 1 | 5µs | # spent 5µs within Types::Standard::BEGIN@443 which was called:
# once (5µs+0s) by Typed::BEGIN@10 at line 443 # 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($_) }, | ||||
448 | 1 | 6µ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 | ||
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 | }, | ||||
476 | 1 | 12µs | 1 | 840µs | }); # spent 840µs making 1 call to Type::Library::add_type |
477 | |||||
478 | 1 | 200ns | our %_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 | }, | ||||
542 | 1 | 9µs | 1 | 594µ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 | ||||
556 | 1 | 800ns | my ($self, $var) = @_; | ||
557 | 1 | 2µs | 2 | 900ns | 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 |
558 | 1 | 800ns | my @code = 'do { my $ok = 1; '; | ||
559 | 1 | 2µs | push @code, sprintf('for my $inner (@{%s}) { no warnings; ', $var); | ||
560 | 1 | 2µs | push @code, sprintf('($ok=0) && last unless ref($inner) eq q(ARRAY) && @$inner == 2 && (%s); ', $Str_check); | ||
561 | 1 | 300ns | push @code, '} '; | ||
562 | 1 | 600ns | push @code, '$ok }'; | ||
563 | 1 | 6µs | return (undef, join(q( ), @code)); | ||
564 | }, | ||||
565 | 1 | 14µs | 1 | 1.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 | ||||
574 | 1 | 600ns | my ($self, $var) = @_; | ||
575 | 1 | 14µs | 2 | 1µ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 | }, | ||||
630 | 1 | 19µs | 1 | 925µ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 | }, | ||||
652 | 1 | 7µs | 1 | 687µ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 | }, | ||||
674 | 1 | 7µs | 1 | 588µ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 | }, | ||||
688 | 1 | 7µs | 1 | 6.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 | }, | ||||
702 | 1 | 7µs | 1 | 605µs | }); # spent 605µs making 1 call to Type::Library::add_type |
703 | |||||
704 | 1 | 12µs | 2 | 5.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 | }, | ||||
725 | 1 | 8µs | 1 | 364µ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 | }, | ||||
738 | 1 | 8µs | 1 | 368µs | }); # spent 368µs making 1 call to Type::Library::add_coercion |
739 | |||||
740 | 1 | 97µs | 1; | ||
741 | |||||
742 | __END__ |