Filename | /Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Type/Library.pm |
Statements | Executed 3557 statements in 8.09ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 9.66ms | 15.0ms | BEGIN@16 | Type::Library::
1 | 1 | 1 | 2.58ms | 2.99ms | BEGIN@14 | Type::Library::
37 | 18 | 1 | 2.32ms | 33.0ms | add_type | Type::Library::
40 | 1 | 1 | 804µs | 1.79ms | _exporter_expand_sub | Type::Library::
295 | 12 | 3 | 679µs | 854µs | meta | Type::Library::
40 | 1 | 1 | 517µs | 1.34ms | _exporter_install_sub | Type::Library::
1 | 1 | 1 | 261µs | 3.89ms | make_immutable | Type::Library::
3 | 3 | 1 | 152µs | 1.22ms | add_coercion | Type::Library::
40 | 2 | 1 | 130µs | 242µs | has_type | Type::Library::
40 | 2 | 1 | 106µs | 186µs | has_coercion | Type::Library::
8 | 1 | 1 | 88µs | 116µs | _exporter_validate_opts | Type::Library::
11 | 2 | 1 | 67µs | 125µs | get_type | Type::Library::
1 | 1 | 1 | 51µs | 51µs | BEGIN@3 | Type::Library::
77 | 2 | 1 | 29µs | 29µs | CORE:match (opcode) | Type::Library::
1 | 1 | 1 | 15µs | 18µs | setup_type_library | Type::Library::
1 | 1 | 1 | 11µs | 19µs | BEGIN@284 | Type::Library::
1 | 1 | 1 | 9µs | 12µs | BEGIN@314 | Type::Library::
1 | 1 | 1 | 8µs | 23µs | BEGIN@315 | Type::Library::
1 | 1 | 1 | 7µs | 30µs | BEGIN@15 | Type::Library::
1 | 1 | 1 | 7µs | 14µs | BEGIN@188 | Type::Library::
1 | 1 | 1 | 6µs | 25µs | BEGIN@285 | Type::Library::
1 | 1 | 1 | 5µs | 26µs | BEGIN@208 | Type::Library::
1 | 1 | 1 | 5µs | 7µs | BEGIN@4 | Type::Library::
1 | 1 | 1 | 5µs | 32µs | BEGIN@5 | Type::Library::
1 | 1 | 1 | 4µs | 4µs | BEGIN@17 | Type::Library::
1 | 1 | 1 | 4µs | 7µs | BEGIN@207 | Type::Library::
1 | 1 | 1 | 4µs | 7µs | BEGIN@232 | Type::Library::
1 | 1 | 1 | 3µs | 3µs | CORE:subst (opcode) | Type::Library::
1 | 1 | 1 | 2µs | 18µs | BEGIN@233 | Type::Library::
1 | 1 | 1 | 2µs | 2µs | BEGIN@7 | Type::Library::
0 | 0 | 0 | 0s | 0s | _croak | Type::Library::
0 | 0 | 0 | 0s | 0s | _exporter_fail | Type::Library::
0 | 0 | 0 | 0s | 0s | coercion_names | Type::Library::
0 | 0 | 0 | 0s | 0s | get_coercion | Type::Library::
0 | 0 | 0 | 0s | 0s | type_names | Type::Library::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Type::Library; | ||||
2 | |||||
3 | 2 | 33µs | 1 | 51µs | # spent 51µs within Type::Library::BEGIN@3 which was called:
# once (51µs+0s) by Types::Standard::BEGIN@19 at line 3 # spent 51µs making 1 call to Type::Library::BEGIN@3 |
4 | 2 | 43µs | 2 | 9µs | # spent 7µs (5+2) within Type::Library::BEGIN@4 which was called:
# once (5µs+2µs) by Types::Standard::BEGIN@19 at line 4 # spent 7µs making 1 call to Type::Library::BEGIN@4
# spent 2µs making 1 call to strict::import |
5 | 2 | 38µs | 2 | 59µs | # spent 32µs (5+27) within Type::Library::BEGIN@5 which was called:
# once (5µs+27µs) by Types::Standard::BEGIN@19 at line 5 # spent 32µs making 1 call to Type::Library::BEGIN@5
# spent 27µs making 1 call to warnings::import |
6 | |||||
7 | # spent 2µs within Type::Library::BEGIN@7 which was called:
# once (2µs+0s) by Types::Standard::BEGIN@19 at line 10 | ||||
8 | 1 | 1µs | $Type::Library::AUTHORITY = 'cpan:TOBYINK'; | ||
9 | 1 | 2µs | $Type::Library::VERSION = '2.000001'; | ||
10 | 1 | 29µs | 1 | 2µs | } # spent 2µs making 1 call to Type::Library::BEGIN@7 |
11 | |||||
12 | 1 | 1µs | $Type::Library::VERSION =~ tr/_//d; | ||
13 | |||||
14 | 2 | 534µs | 2 | 3.28ms | # spent 2.99ms (2.58+402µs) within Type::Library::BEGIN@14 which was called:
# once (2.58ms+402µs) by Types::Standard::BEGIN@19 at line 14 # spent 2.99ms making 1 call to Type::Library::BEGIN@14
# spent 289µs making 1 call to Eval::TypeTiny::import |
15 | 2 | 17µs | 2 | 53µs | # spent 30µs (7+23) within Type::Library::BEGIN@15 which was called:
# once (7µs+23µs) by Types::Standard::BEGIN@19 at line 15 # spent 30µs making 1 call to Type::Library::BEGIN@15
# spent 23µs making 1 call to Exporter::import |
16 | 2 | 562µs | 1 | 15.0ms | # spent 15.0ms (9.66+5.32) within Type::Library::BEGIN@16 which was called:
# once (9.66ms+5.32ms) by Types::Standard::BEGIN@19 at line 16 # spent 15.0ms making 1 call to Type::Library::BEGIN@16 |
17 | 2 | 463µs | 1 | 4µs | # spent 4µs within Type::Library::BEGIN@17 which was called:
# once (4µs+0s) by Types::Standard::BEGIN@19 at line 17 # spent 4µs making 1 call to Type::Library::BEGIN@17 |
18 | |||||
19 | 1 | 1µs | require Exporter::Tiny; | ||
20 | 1 | 9µs | our @ISA = 'Exporter::Tiny'; | ||
21 | |||||
22 | sub _croak ($;@) { require Error::TypeTiny; goto \&Error::TypeTiny::croak } | ||||
23 | |||||
24 | #### | ||||
25 | #### Hooks for Exporter::Tiny | ||||
26 | #### | ||||
27 | |||||
28 | # Handling for -base, -extends, and -utils tags. | ||||
29 | # | ||||
30 | # spent 116µs (88+28) within Type::Library::_exporter_validate_opts which was called 8 times, avg 14µs/call:
# 8 times (88µs+28µs) by Exporter::Tiny::import at line 77 of Exporter/Tiny.pm, avg 14µs/call | ||||
31 | 8 | 5µs | my ( $class, $opts ) = ( shift, @_ ); | ||
32 | |||||
33 | $class->setup_type_library( @{$opts}{qw/ into utils extends /} ) | ||||
34 | 8 | 9µs | 1 | 18µs | if $_[0]{base} || $_[0]{extends}; # spent 18µs making 1 call to Type::Library::setup_type_library |
35 | |||||
36 | 8 | 44µs | 8 | 10µs | return $class->SUPER::_exporter_validate_opts( @_ ); # spent 10µs making 8 calls to Exporter::Tiny::_exporter_validate_opts, avg 1µs/call |
37 | } | ||||
38 | |||||
39 | # In Exporter::Tiny, this method takes a sub name, a 'value' (i.e. | ||||
40 | # potentially an options hashref for the export), and some global | ||||
41 | # options, and returns a list of name+coderef pairs to actually | ||||
42 | # export. We override it to provide some useful features. | ||||
43 | # | ||||
44 | # spent 1.79ms (804µs+986µs) within Type::Library::_exporter_expand_sub which was called 40 times, avg 45µs/call:
# 40 times (804µs+986µs) by Exporter::Tiny::import at line 82 of Exporter/Tiny.pm, avg 45µs/call | ||||
45 | 40 | 4µs | my $class = shift; | ||
46 | 40 | 12µs | my ( $name, $value, $globals ) = @_; | ||
47 | |||||
48 | # Handle exporting '+Type'. | ||||
49 | # | ||||
50 | # Note that this recurses, so if used in conjunction with the other | ||||
51 | # special cases handled by this method, will still work. | ||||
52 | # | ||||
53 | 40 | 99µs | 40 | 15µs | if ( $name =~ /^\+(.+)/ and $class->has_type( "$1" ) ) { # spent 15µs making 40 calls to Type::Library::CORE:match, avg 375ns/call |
54 | my $type = $class->get_type( "$1" ); | ||||
55 | my $exported = $type->exportables; | ||||
56 | return map $class->_exporter_expand_sub( | ||||
57 | $_->{name}, | ||||
58 | +{ %{ $value || {} } }, | ||||
59 | $globals, | ||||
60 | ), @$exported; | ||||
61 | } | ||||
62 | |||||
63 | # Is the function being exported one which is associated with a | ||||
64 | # type constraint? If so, which one. If not, then forget the rest | ||||
65 | # and just use the superclass method. | ||||
66 | # | ||||
67 | 40 | 178µs | 80 | 221µs | if ( my $f = $class->meta->{'functions'}{$name} # spent 221µs making 80 calls to Type::Library::meta, avg 3µs/call |
68 | and defined $class->meta->{'functions'}{$name}{'type'} ) { | ||||
69 | |||||
70 | 40 | 8µs | my $type = $f->{type}; | ||
71 | 40 | 29µs | my $tag = $f->{tags}[0]; | ||
72 | 40 | 41µs | 40 | 60µs | my $typename = $type->name; # spent 60µs making 40 calls to Type::Tiny::name, avg 2µs/call |
73 | |||||
74 | # If $value has `of` or `where` options, then this is a | ||||
75 | # custom type. | ||||
76 | # | ||||
77 | 40 | 8µs | my $custom_type = 0; | ||
78 | 40 | 17µs | for my $param ( qw/ of where / ) { | ||
79 | 80 | 47µs | exists $value->{$param} or next; | ||
80 | defined $value->{-as} or _croak( "Parameter '-as' not supplied" ); | ||||
81 | $type = $type->$param( $value->{$param} ); | ||||
82 | $name = $value->{-as}; | ||||
83 | ++$custom_type; | ||||
84 | } | ||||
85 | |||||
86 | # If we're exporting a type itself, then export a custom | ||||
87 | # function if they customized the type or want a Moose/Mouse | ||||
88 | # type constraint. | ||||
89 | # | ||||
90 | 40 | 18µs | if ( $tag eq 'types' ) { | ||
91 | 40 | 4µs | my $post_method = q(); | ||
92 | 40 | 13µs | $post_method = '->mouse_type' if $globals->{mouse}; | ||
93 | 40 | 7µs | $post_method = '->moose_type' if $globals->{moose}; | ||
94 | 40 | 8µs | return ( $name => type_to_coderef( $type, post_method => $post_method ) ) | ||
95 | if $post_method || $custom_type; | ||||
96 | } | ||||
97 | |||||
98 | # If they're exporting some other type of function, like | ||||
99 | # 'to', 'is', or 'assert', then find the correct exportable | ||||
100 | # by tag name, and return that. | ||||
101 | # | ||||
102 | # XXX: this will fail for tags like 'constants' where there | ||||
103 | # will be multiple exportables which match! | ||||
104 | # | ||||
105 | 40 | 11µs | if ( $custom_type and $tag ne 'types' ) { | ||
106 | my $exportable = $type->exportables_by_tag( $tag, $typename ); | ||||
107 | return ( $value->{-as} || $exportable->{name}, $exportable->{code} ); | ||||
108 | } | ||||
109 | } | ||||
110 | |||||
111 | # In all other cases, the superclass method will work. | ||||
112 | # | ||||
113 | 40 | 111µs | 40 | 690µs | return $class->SUPER::_exporter_expand_sub( @_ ); # spent 690µs making 40 calls to Exporter::Tiny::_exporter_expand_sub, avg 17µs/call |
114 | } | ||||
115 | |||||
116 | # Mostly just rely on superclass to do the actual export, but add | ||||
117 | # a couple of useful behaviours. | ||||
118 | # | ||||
119 | # spent 1.34ms (517µs+826µs) within Type::Library::_exporter_install_sub which was called 40 times, avg 34µs/call:
# 40 times (517µs+826µs) by Exporter::Tiny::import at line 84 of Exporter/Tiny.pm, avg 34µs/call | ||||
120 | 40 | 6µs | my $class = shift; | ||
121 | 40 | 9µs | my ( $name, $value, $globals, $sym ) = @_; | ||
122 | |||||
123 | 40 | 15µs | my $into = $globals->{into}; | ||
124 | 40 | 41µs | 40 | 90µs | my $type = $class->meta->{'functions'}{$name}{'type'}; # spent 90µs making 40 calls to Type::Library::meta, avg 2µs/call |
125 | 40 | 29µs | 40 | 84µs | my $tags = $class->meta->{'functions'}{$name}{'tags'}; # spent 84µs making 40 calls to Type::Library::meta, avg 2µs/call |
126 | |||||
127 | # Issue a warning if exporting a deprecated type constraint. | ||||
128 | # | ||||
129 | Exporter::Tiny::_carp( | ||||
130 | "Exporting deprecated type %s to %s", | ||||
131 | $type->qualified_name, | ||||
132 | ref( $into ) ? "reference" : "package $into", | ||||
133 | 40 | 64µs | 40 | 64µs | ) if ( defined $type and $type->deprecated and not $globals->{allow_deprecated} ); # spent 64µs making 40 calls to Type::Tiny::deprecated, avg 2µs/call |
134 | |||||
135 | # If exporting a type constraint into a real package, then | ||||
136 | # add it to the package's type registry. | ||||
137 | # | ||||
138 | 40 | 39µs | if ( !ref $into | ||
139 | and $into ne '-lexical' | ||||
140 | and defined $type | ||||
141 | and grep $_ eq 'types', @$tags ) { | ||||
142 | |||||
143 | # If they're renaming it, figure out what name, and use that. | ||||
144 | # XXX: `-as` can be a coderef, and can be in $globals in that case. | ||||
145 | 40 | 37µs | my ( $prefix ) = grep defined, $value->{-prefix}, $globals->{prefix}, q(); | ||
146 | 40 | 28µs | my ( $suffix ) = grep defined, $value->{-suffix}, $globals->{suffix}, q(); | ||
147 | 40 | 13µs | my $as = $prefix . ( $value->{-as} || $name ) . $suffix; | ||
148 | |||||
149 | $INC{'Type/Registry.pm'} | ||||
150 | ? 'Type::Registry'->for_class( $into )->add_type( $type, $as ) | ||||
151 | 40 | 36µs | : ( $Type::Registry::DELAYED{$into}{$as} = $type ); | ||
152 | } | ||||
153 | |||||
154 | 40 | 121µs | 40 | 588µs | $class->SUPER::_exporter_install_sub( @_ ); # spent 588µs making 40 calls to Exporter::Tiny::_exporter_install_sub, avg 15µs/call |
155 | } #/ sub _exporter_install_sub | ||||
156 | |||||
157 | sub _exporter_fail { | ||||
158 | my $class = shift; | ||||
159 | my ( $name, $value, $globals ) = @_; | ||||
160 | |||||
161 | # Passing the `-declare` flag means that if a type isn't found, then | ||||
162 | # we export a placeholder function instead of failing. | ||||
163 | if ( $globals->{declare} ) { | ||||
164 | return ( | ||||
165 | $name, | ||||
166 | type_to_coderef( | ||||
167 | undef, | ||||
168 | type_name => $name, | ||||
169 | type_library => $globals->{into} || _croak( "Parameter 'into' not supplied" ), | ||||
170 | ), | ||||
171 | ); | ||||
172 | } #/ if ( $globals->{declare...}) | ||||
173 | |||||
174 | return $class->SUPER::_exporter_fail( @_ ); | ||||
175 | } #/ sub _exporter_fail | ||||
176 | |||||
177 | #### | ||||
178 | #### Type library functionality | ||||
179 | #### | ||||
180 | |||||
181 | # spent 18µs (15+3) within Type::Library::setup_type_library which was called:
# once (15µs+3µs) by Type::Library::_exporter_validate_opts at line 34 | ||||
182 | 1 | 0s | my ( $class, $type_library, $install_utils, $extends ) = @_; | ||
183 | |||||
184 | 1 | 0s | my @extends = ref( $extends ) ? @$extends : $extends ? $extends : (); | ||
185 | 1 | 1µs | unshift @extends, $class if $class ne __PACKAGE__; | ||
186 | |||||
187 | 1 | 0s | if ( not ref $type_library ) { | ||
188 | 2 | 106µs | 2 | 21µs | # spent 14µs (7+7) within Type::Library::BEGIN@188 which was called:
# once (7µs+7µs) by Types::Standard::BEGIN@19 at line 188 # spent 14µs making 1 call to Type::Library::BEGIN@188
# spent 7µs making 1 call to strict::unimport |
189 | 1 | 6µs | push @{"$type_library\::ISA"}, $class; | ||
190 | 1 | 8µs | 1 | 3µs | ( my $file = $type_library ) =~ s{::}{/}g; # spent 3µs making 1 call to Type::Library::CORE:subst |
191 | 1 | 1µs | $INC{"$file.pm"} ||= __FILE__; | ||
192 | } | ||||
193 | |||||
194 | 1 | 0s | if ( $install_utils ) { | ||
195 | require Type::Utils; | ||||
196 | 'Type::Utils'->import( { into => $type_library }, '-default' ); | ||||
197 | } | ||||
198 | |||||
199 | 1 | 3µs | if ( @extends and not ref $type_library ) { | ||
200 | require Type::Utils; | ||||
201 | my $wrapper = eval "sub { package $type_library; &Type::Utils::extends; }"; | ||||
202 | $wrapper->( @extends ); | ||||
203 | } | ||||
204 | } | ||||
205 | |||||
206 | # spent 854µs (679+175) within Type::Library::meta which was called 295 times, avg 3µs/call:
# 80 times (189µs+32µs) by Type::Library::_exporter_expand_sub at line 67, avg 3µs/call
# 40 times (92µs+20µs) by Type::Library::has_type at line 258, avg 3µs/call
# 40 times (76µs+14µs) by Type::Library::_exporter_install_sub at line 124, avg 2µs/call
# 40 times (72µs+12µs) by Type::Library::_exporter_install_sub at line 125, avg 2µs/call
# 40 times (61µs+19µs) by Type::Library::has_coercion at line 301, avg 2µs/call
# 37 times (90µs+52µs) by Type::Library::add_type at line 214, avg 4µs/call
# 11 times (45µs+13µs) by Type::Library::get_type at line 253, avg 5µs/call
# 3 times (5µs+3µs) by Type::Library::add_coercion at line 268, avg 3µs/call
# once (23µs+6µs) by JSON::Schema::Modern::BEGIN@31 at line 144 of Types/Standard.pm
# once (14µs+2µs) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:190] at line 22 of Types/Standard/Map.pm
# once (10µs+1000ns) by JSON::Schema::Modern::BEGIN@31 at line 1107 of Types/Standard.pm
# once (2µs+1µs) by Type::Library::make_immutable at line 311 | ||||
207 | 2 | 19µs | 2 | 10µs | # spent 7µs (4+3) within Type::Library::BEGIN@207 which was called:
# once (4µs+3µs) by Types::Standard::BEGIN@19 at line 207 # spent 7µs making 1 call to Type::Library::BEGIN@207
# spent 3µs making 1 call to strict::unimport |
208 | 2 | 126µs | 2 | 47µs | # spent 26µs (5+21) within Type::Library::BEGIN@208 which was called:
# once (5µs+21µs) by Types::Standard::BEGIN@19 at line 208 # spent 26µs making 1 call to Type::Library::BEGIN@208
# spent 21µs making 1 call to warnings::unimport |
209 | 295 | 786µs | 295 | 175µs | return $_[0] if blessed $_[0]; # spent 175µs making 295 calls to Scalar::Util::blessed, avg 593ns/call |
210 | 163 | 295µs | ${"$_[0]\::META"} ||= bless {}, $_[0]; | ||
211 | } | ||||
212 | |||||
213 | # spent 33.0ms (2.32+30.7) within Type::Library::add_type which was called 37 times, avg 893µs/call:
# 20 times (1.42ms+18.7ms) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:127] at line 126 of Types/Standard.pm, avg 1.01ms/call
# once (74µs+1.59ms) by JSON::Schema::Modern::BEGIN@31 at line 924 of Types/Standard.pm
# once (82µs+924µs) by JSON::Schema::Modern::BEGIN@31 at line 377 of Types/Standard.pm
# once (47µs+895µs) by JSON::Schema::Modern::BEGIN@31 at line 957 of Types/Standard.pm
# once (58µs+844µs) by JSON::Schema::Modern::BEGIN@31 at line 299 of Types/Standard.pm
# once (84µs+816µs) by JSON::Schema::Modern::BEGIN@31 at line 1035 of Types/Standard.pm
# once (59µs+839µs) by JSON::Schema::Modern::BEGIN@31 at line 364 of Types/Standard.pm
# once (36µs+823µs) by JSON::Schema::Modern::BEGIN@31 at line 883 of Types/Standard.pm
# once (48µs+790µs) by JSON::Schema::Modern::BEGIN@31 at line 332 of Types/Standard.pm
# once (64µs+718µs) by JSON::Schema::Modern::BEGIN@31 at line 1060 of Types/Standard.pm
# once (49µs+579µs) by JSON::Schema::Modern::BEGIN@31 at line 887 of Types/Standard.pm
# once (58µs+541µs) by JSON::Schema::Modern::BEGIN@31 at line 334 of Types/Standard.pm
# once (44µs+484µs) by JSON::Schema::Modern::BEGIN@31 at line 706 of Types/Standard.pm
# once (34µs+463µs) by JSON::Schema::Modern::BEGIN@31 at line 770 of Types/Standard.pm
# once (43µs+438µs) by JSON::Schema::Modern::BEGIN@31 at line 1018 of Types/Standard.pm
# once (35µs+445µs) by JSON::Schema::Modern::BEGIN@31 at line 827 of Types/Standard.pm
# once (40µs+424µs) by JSON::Schema::Modern::BEGIN@31 at line 989 of Types/Standard.pm
# once (46µs+410µs) by JSON::Schema::Modern::BEGIN@31 at line 802 of Types/Standard.pm | ||||
214 | 37 | 46µs | 37 | 142µs | my $meta = shift->meta; # spent 142µs making 37 calls to Type::Library::meta, avg 4µs/call |
215 | 37 | 98µs | 37 | 27µs | my $class = blessed( $meta ) ; # spent 27µs making 37 calls to Scalar::Util::blessed, avg 730ns/call |
216 | |||||
217 | 37 | 19µs | _croak( 'Type library is immutable' ) if $meta->{immutable}; | ||
218 | |||||
219 | my $type = | ||||
220 | ref( $_[0] ) =~ /^Type::Tiny\b/ ? $_[0] : | ||||
221 | blessed( $_[0] ) ? Types::TypeTiny::to_TypeTiny( $_[0] ) : | ||||
222 | 37 | 338µs | 111 | 2.15ms | ref( $_[0] ) eq q(HASH) ? 'Type::Tiny'->new( library => $class, %{ $_[0] } ) : # spent 2.13ms making 37 calls to Type::Tiny::new, avg 58µs/call
# spent 14µs making 37 calls to Type::Library::CORE:match, avg 378ns/call
# spent 6µs making 37 calls to Scalar::Util::blessed, avg 162ns/call |
223 | "Type::Tiny"->new( library => $class, @_ ); | ||||
224 | 37 | 17µs | my $name = $type->{name}; | ||
225 | |||||
226 | 37 | 51µs | 37 | 225µs | _croak( 'Type %s already exists in this library', $name ) if $meta->has_type( $name ); # spent 225µs making 37 calls to Type::Library::has_type, avg 6µs/call |
227 | 37 | 44µs | 37 | 171µs | _croak( 'Type %s conflicts with coercion of same name', $name ) if $meta->has_coercion( $name ); # spent 171µs making 37 calls to Type::Library::has_coercion, avg 5µs/call |
228 | 37 | 45µs | 37 | 146µs | _croak( 'Cannot add anonymous type to a library' ) if $type->is_anon; # spent 146µs making 37 calls to Type::Tiny::is_anon, avg 4µs/call |
229 | 37 | 8µs | $meta->{types} ||= {}; | ||
230 | 37 | 31µs | $meta->{types}{$name} = $type; | ||
231 | |||||
232 | 2 | 18µs | 2 | 10µs | # spent 7µs (4+3) within Type::Library::BEGIN@232 which was called:
# once (4µs+3µs) by Types::Standard::BEGIN@19 at line 232 # spent 7µs making 1 call to Type::Library::BEGIN@232
# spent 3µs making 1 call to strict::unimport |
233 | 2 | 646µs | 2 | 34µs | # spent 18µs (2+16) within Type::Library::BEGIN@233 which was called:
# once (2µs+16µs) by Types::Standard::BEGIN@19 at line 233 # spent 18µs making 1 call to Type::Library::BEGIN@233
# spent 16µs making 1 call to warnings::unimport |
234 | |||||
235 | 37 | 98µs | 37 | 27.1ms | for my $exportable ( @{ $type->exportables } ) { # spent 27.1ms making 37 calls to Type::Tiny::exportables, avg 732µs/call |
236 | 148 | 44µs | my $name = $exportable->{name}; | ||
237 | 148 | 19µs | my $code = $exportable->{code}; | ||
238 | 148 | 22µs | my $tags = $exportable->{tags}; | ||
239 | 148 | 407µs | 148 | 795µs | *{"$class\::$name"} = set_subname( "$class\::$name", $code ); # spent 795µs making 148 calls to Eval::TypeTiny::set_subname, avg 5µs/call |
240 | 148 | 99µs | push @{"$class\::EXPORT_OK"}, $name; | ||
241 | 148 | 200µs | push @{ ${"$class\::EXPORT_TAGS"}{$_} ||= [] }, $name for @$tags; | ||
242 | 148 | 442µs | $meta->{'functions'}{$name} = { type => $type, tags => $tags }; | ||
243 | } | ||||
244 | |||||
245 | $INC{'Type/Registry.pm'} | ||||
246 | ? 'Type::Registry'->for_class( $class )->add_type( $type, $name ) | ||||
247 | 37 | 55µs | : ( $Type::Registry::DELAYED{$class}{$name} = $type ); | ||
248 | |||||
249 | 37 | 145µs | return $type; | ||
250 | } #/ sub add_type | ||||
251 | |||||
252 | # spent 125µs (67+58) within Type::Library::get_type which was called 11 times, avg 11µs/call:
# 10 times (62µs+53µs) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:190] at line 169 of Types/Standard.pm, avg 12µs/call
# once (5µs+5µs) by JSON::Schema::Modern::BEGIN@31 at line 1064 of Types/Standard.pm | ||||
253 | 11 | 25µs | 11 | 58µs | my $meta = shift->meta; # spent 58µs making 11 calls to Type::Library::meta, avg 5µs/call |
254 | 11 | 36µs | $meta->{types}{ $_[0] }; | ||
255 | } | ||||
256 | |||||
257 | sub has_type { | ||||
258 | 40 | 26µs | 40 | 112µs | my $meta = shift->meta; # spent 112µs making 40 calls to Type::Library::meta, avg 3µs/call |
259 | 40 | 90µs | exists $meta->{types}{ $_[0] }; | ||
260 | } | ||||
261 | |||||
262 | sub type_names { | ||||
263 | my $meta = shift->meta; | ||||
264 | keys %{ $meta->{types} }; | ||||
265 | } | ||||
266 | |||||
267 | # spent 1.22ms (152µs+1.07) within Type::Library::add_coercion which was called 3 times, avg 407µs/call:
# once (98µs+441µs) by JSON::Schema::Modern::BEGIN@31 at line 1064 of Types/Standard.pm
# once (25µs+338µs) by JSON::Schema::Modern::BEGIN@31 at line 1089 of Types/Standard.pm
# once (29µs+289µs) by JSON::Schema::Modern::BEGIN@31 at line 1105 of Types/Standard.pm | ||||
268 | 3 | 2µs | 3 | 8µs | my $meta = shift->meta; # spent 8µs making 3 calls to Type::Library::meta, avg 3µs/call |
269 | 3 | 7µs | 3 | 1µs | my $class = blessed( $meta ); # spent 1µs making 3 calls to Scalar::Util::blessed, avg 333ns/call |
270 | |||||
271 | 3 | 3µs | _croak( 'Type library is immutable' ) if $meta->{immutable}; | ||
272 | |||||
273 | 3 | 2µs | require Type::Coercion; | ||
274 | 3 | 14µs | 6 | 308µs | my $c = blessed( $_[0] ) ? $_[0] : "Type::Coercion"->new( @_ ); # spent 306µs making 3 calls to Type::Coercion::new, avg 102µs/call
# spent 2µs making 3 calls to Scalar::Util::blessed, avg 667ns/call |
275 | 3 | 3µs | 3 | 2µs | my $name = $c->name; # spent 2µs making 3 calls to Type::Coercion::name, avg 667ns/call |
276 | |||||
277 | 3 | 6µs | 3 | 15µs | _croak( 'Coercion %s already exists in this library', $name ) if $meta->has_coercion( $name ); # spent 15µs making 3 calls to Type::Library::has_coercion, avg 5µs/call |
278 | 3 | 5µs | 3 | 17µs | _croak( 'Coercion %s conflicts with type of same name', $name ) if $meta->has_type( $name ); # spent 17µs making 3 calls to Type::Library::has_type, avg 6µs/call |
279 | 3 | 3µs | 3 | 6µs | _croak( 'Cannot add anonymous type to a library' ) if $c->is_anon; # spent 6µs making 3 calls to Type::Coercion::is_anon, avg 2µs/call |
280 | |||||
281 | 3 | 1µs | $meta->{coercions} ||= {}; | ||
282 | 3 | 3µs | $meta->{coercions}{$name} = $c; | ||
283 | |||||
284 | 2 | 37µs | 2 | 27µs | # spent 19µs (11+8) within Type::Library::BEGIN@284 which was called:
# once (11µs+8µs) by Types::Standard::BEGIN@19 at line 284 # spent 19µs making 1 call to Type::Library::BEGIN@284
# spent 8µs making 1 call to strict::unimport |
285 | 2 | 208µs | 2 | 44µs | # spent 25µs (6+19) within Type::Library::BEGIN@285 which was called:
# once (6µs+19µs) by Types::Standard::BEGIN@19 at line 285 # spent 25µs making 1 call to Type::Library::BEGIN@285
# spent 19µs making 1 call to warnings::unimport |
286 | |||||
287 | 3 | 11µs | 3 | 711µs | *{"$class\::$name"} = type_to_coderef( $c ); # spent 711µs making 3 calls to Eval::TypeTiny::type_to_coderef, avg 237µs/call |
288 | 3 | 4µs | push @{"$class\::EXPORT_OK"}, $name; | ||
289 | 3 | 4µs | push @{ ${"$class\::EXPORT_TAGS"}{'coercions'} ||= [] }, $name; | ||
290 | 3 | 20µs | $meta->{'functions'}{$name} = { coercion => $c, tags => [ 'coercions' ] }; | ||
291 | |||||
292 | 3 | 11µs | return $c; | ||
293 | } #/ sub add_coercion | ||||
294 | |||||
295 | sub get_coercion { | ||||
296 | my $meta = shift->meta; | ||||
297 | $meta->{coercions}{ $_[0] }; | ||||
298 | } | ||||
299 | |||||
300 | sub has_coercion { | ||||
301 | 40 | 29µs | 40 | 80µs | my $meta = shift->meta; # spent 80µs making 40 calls to Type::Library::meta, avg 2µs/call |
302 | 40 | 72µs | exists $meta->{coercions}{ $_[0] }; | ||
303 | } | ||||
304 | |||||
305 | sub coercion_names { | ||||
306 | my $meta = shift->meta; | ||||
307 | keys %{ $meta->{coercions} }; | ||||
308 | } | ||||
309 | |||||
310 | # spent 3.89ms (261µs+3.63) within Type::Library::make_immutable which was called:
# once (261µs+3.63ms) by JSON::Schema::Modern::BEGIN@31 at line 1107 of Types/Standard.pm | ||||
311 | 1 | 1µs | 1 | 3µs | my $meta = shift->meta; # spent 3µs making 1 call to Type::Library::meta |
312 | 1 | 1µs | my $class = ref( $meta ); | ||
313 | |||||
314 | 2 | 34µs | 2 | 15µs | # spent 12µs (9+3) within Type::Library::BEGIN@314 which was called:
# once (9µs+3µs) by Types::Standard::BEGIN@19 at line 314 # spent 12µs making 1 call to Type::Library::BEGIN@314
# spent 3µs making 1 call to strict::unimport |
315 | 2 | 166µs | 2 | 38µs | # spent 23µs (8+15) within Type::Library::BEGIN@315 which was called:
# once (8µs+15µs) by Types::Standard::BEGIN@19 at line 315 # spent 23µs making 1 call to Type::Library::BEGIN@315
# spent 15µs making 1 call to warnings::unimport |
316 | |||||
317 | 1 | 15µs | for my $type ( values %{ $meta->{types} } ) { | ||
318 | 37 | 77µs | 74 | 2.69ms | $type->coercion->freeze; # spent 2.65ms making 37 calls to Type::Tiny::coercion, avg 72µs/call
# spent 42µs making 37 calls to Type::Coercion::freeze, avg 1µs/call |
319 | 37 | 44µs | 39 | 292µs | next unless $type->has_coercion && $type->coercion->frozen; # spent 288µs making 37 calls to Type::Tiny::has_coercion, avg 8µs/call
# spent 2µs making 1 call to Type::Coercion::frozen
# spent 2µs making 1 call to Type::Tiny::coercion |
320 | 1 | 4µs | 1 | 628µs | for my $e ( $type->exportables_by_tag( 'to' ) ) { # spent 628µs making 1 call to Type::Tiny::exportables_by_tag |
321 | 1 | 1µs | my $qualified_name = $class . '::' . $e->{name}; | ||
322 | 1 | 14µs | 1 | 12µs | *$qualified_name = set_subname( $qualified_name, $e->{code} ); # spent 12µs making 1 call to Eval::TypeTiny::set_subname |
323 | } | ||||
324 | } | ||||
325 | |||||
326 | 1 | 18µs | $meta->{immutable} = 1; | ||
327 | } | ||||
328 | |||||
329 | 1 | 5µs | 1; | ||
330 | |||||
331 | __END__ | ||||
sub Type::Library::CORE:match; # opcode | |||||
# spent 3µs within Type::Library::CORE:subst which was called:
# once (3µs+0s) by Type::Library::setup_type_library at line 190 |