Filename | /Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Type/Library.pm |
Statements | Executed 3557 statements in 10.1ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 9.91ms | 15.1ms | BEGIN@16 | Type::Library::
37 | 18 | 1 | 2.79ms | 38.8ms | add_type | Type::Library::
1 | 1 | 1 | 2.47ms | 2.89ms | BEGIN@14 | Type::Library::
295 | 12 | 3 | 781µs | 1.02ms | meta | Type::Library::
40 | 1 | 1 | 747µs | 1.91ms | _exporter_expand_sub | Type::Library::
40 | 1 | 1 | 717µs | 1.58ms | _exporter_install_sub | Type::Library::
1 | 1 | 1 | 335µs | 3.26ms | make_immutable | Type::Library::
3 | 3 | 1 | 196µs | 1.36ms | add_coercion | Type::Library::
40 | 2 | 1 | 166µs | 286µs | has_type | Type::Library::
8 | 1 | 1 | 161µs | 192µs | _exporter_validate_opts | Type::Library::
40 | 2 | 1 | 130µs | 208µs | has_coercion | Type::Library::
11 | 2 | 1 | 84µs | 155µs | get_type | Type::Library::
1 | 1 | 1 | 41µs | 41µs | BEGIN@3 | Type::Library::
77 | 2 | 1 | 39µs | 39µs | CORE:match (opcode) | Type::Library::
1 | 1 | 1 | 22µs | 56µs | BEGIN@5 | Type::Library::
1 | 1 | 1 | 21µs | 24µs | setup_type_library | Type::Library::
1 | 1 | 1 | 20µs | 52µs | BEGIN@284 | Type::Library::
1 | 1 | 1 | 15µs | 28µs | BEGIN@188 | Type::Library::
1 | 1 | 1 | 13µs | 35µs | BEGIN@315 | Type::Library::
1 | 1 | 1 | 12µs | 18µs | BEGIN@207 | Type::Library::
1 | 1 | 1 | 12µs | 17µs | BEGIN@314 | Type::Library::
1 | 1 | 1 | 11µs | 17µs | BEGIN@232 | Type::Library::
1 | 1 | 1 | 11µs | 42µs | BEGIN@285 | Type::Library::
1 | 1 | 1 | 10µs | 41µs | BEGIN@15 | Type::Library::
1 | 1 | 1 | 8µs | 30µs | BEGIN@233 | Type::Library::
1 | 1 | 1 | 8µs | 12µs | BEGIN@4 | Type::Library::
1 | 1 | 1 | 6µs | 37µs | BEGIN@208 | Type::Library::
1 | 1 | 1 | 4µs | 4µs | BEGIN@17 | Type::Library::
1 | 1 | 1 | 4µs | 4µs | BEGIN@7 | Type::Library::
1 | 1 | 1 | 3µs | 3µs | CORE:subst (opcode) | 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 | 41µs | 1 | 41µs | # spent 41µs within Type::Library::BEGIN@3 which was called:
# once (41µs+0s) by Types::Standard::BEGIN@19 at line 3 # spent 41µs making 1 call to Type::Library::BEGIN@3 |
4 | 2 | 22µs | 2 | 16µs | # spent 12µs (8+4) within Type::Library::BEGIN@4 which was called:
# once (8µs+4µs) by Types::Standard::BEGIN@19 at line 4 # spent 12µs making 1 call to Type::Library::BEGIN@4
# spent 4µs making 1 call to strict::import |
5 | 2 | 52µs | 2 | 90µs | # spent 56µs (22+34) within Type::Library::BEGIN@5 which was called:
# once (22µs+34µs) by Types::Standard::BEGIN@19 at line 5 # spent 56µs making 1 call to Type::Library::BEGIN@5
# spent 34µs making 1 call to warnings::import |
6 | |||||
7 | # spent 4µs within Type::Library::BEGIN@7 which was called:
# once (4µs+0s) by Types::Standard::BEGIN@19 at line 10 | ||||
8 | 1 | 1µs | $Type::Library::AUTHORITY = 'cpan:TOBYINK'; | ||
9 | 1 | 3µs | $Type::Library::VERSION = '2.000001'; | ||
10 | 1 | 38µs | 1 | 4µs | } # spent 4µs making 1 call to Type::Library::BEGIN@7 |
11 | |||||
12 | 1 | 1µs | $Type::Library::VERSION =~ tr/_//d; | ||
13 | |||||
14 | 2 | 413µs | 2 | 3.23ms | # spent 2.89ms (2.47+425µs) within Type::Library::BEGIN@14 which was called:
# once (2.47ms+425µs) by Types::Standard::BEGIN@19 at line 14 # spent 2.89ms making 1 call to Type::Library::BEGIN@14
# spent 335µs making 1 call to Eval::TypeTiny::import |
15 | 2 | 20µs | 2 | 72µs | # spent 41µs (10+31) within Type::Library::BEGIN@15 which was called:
# once (10µs+31µs) by Types::Standard::BEGIN@19 at line 15 # spent 41µs making 1 call to Type::Library::BEGIN@15
# spent 31µs making 1 call to Exporter::import |
16 | 2 | 621µs | 1 | 15.1ms | # spent 15.1ms (9.91+5.18) within Type::Library::BEGIN@16 which was called:
# once (9.91ms+5.18ms) by Types::Standard::BEGIN@19 at line 16 # spent 15.1ms making 1 call to Type::Library::BEGIN@16 |
17 | 2 | 894µ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 | 12µ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 192µs (161+31) within Type::Library::_exporter_validate_opts which was called 8 times, avg 24µs/call:
# 8 times (161µs+31µs) by Exporter::Tiny::import at line 77 of Exporter/Tiny.pm, avg 24µs/call | ||||
31 | 8 | 7µs | my ( $class, $opts ) = ( shift, @_ ); | ||
32 | |||||
33 | $class->setup_type_library( @{$opts}{qw/ into utils extends /} ) | ||||
34 | 8 | 28µs | 1 | 24µs | if $_[0]{base} || $_[0]{extends}; # spent 24µs making 1 call to Type::Library::setup_type_library |
35 | |||||
36 | 8 | 39µs | 8 | 7µs | return $class->SUPER::_exporter_validate_opts( @_ ); # spent 7µs making 8 calls to Exporter::Tiny::_exporter_validate_opts, avg 875ns/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.91ms (747µs+1.17) within Type::Library::_exporter_expand_sub which was called 40 times, avg 48µs/call:
# 40 times (747µs+1.17ms) by Exporter::Tiny::import at line 82 of Exporter/Tiny.pm, avg 48µs/call | ||||
45 | 40 | 8µs | my $class = shift; | ||
46 | 40 | 14µ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 | 86µs | 40 | 21µs | if ( $name =~ /^\+(.+)/ and $class->has_type( "$1" ) ) { # spent 21µs making 40 calls to Type::Library::CORE:match, avg 525ns/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 | 127µs | 80 | 237µs | if ( my $f = $class->meta->{'functions'}{$name} # spent 237µs making 80 calls to Type::Library::meta, avg 3µs/call |
68 | and defined $class->meta->{'functions'}{$name}{'type'} ) { | ||||
69 | |||||
70 | 40 | 17µs | my $type = $f->{type}; | ||
71 | 40 | 24µs | my $tag = $f->{tags}[0]; | ||
72 | 40 | 52µs | 40 | 53µs | my $typename = $type->name; # spent 53µs making 40 calls to Type::Tiny::name, avg 1µs/call |
73 | |||||
74 | # If $value has `of` or `where` options, then this is a | ||||
75 | # custom type. | ||||
76 | # | ||||
77 | 40 | 5µs | my $custom_type = 0; | ||
78 | 40 | 73µs | for my $param ( qw/ of where / ) { | ||
79 | 80 | 15µ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 | 23µs | if ( $tag eq 'types' ) { | ||
91 | 40 | 8µs | my $post_method = q(); | ||
92 | 40 | 15µs | $post_method = '->mouse_type' if $globals->{mouse}; | ||
93 | 40 | 3µs | $post_method = '->moose_type' if $globals->{moose}; | ||
94 | 40 | 11µ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 | 18µ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 | 123µs | 40 | 856µs | return $class->SUPER::_exporter_expand_sub( @_ ); # spent 856µs making 40 calls to Exporter::Tiny::_exporter_expand_sub, avg 21µ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.58ms (717µs+863µs) within Type::Library::_exporter_install_sub which was called 40 times, avg 40µs/call:
# 40 times (717µs+863µs) by Exporter::Tiny::import at line 84 of Exporter/Tiny.pm, avg 40µs/call | ||||
120 | 40 | 7µs | my $class = shift; | ||
121 | 40 | 11µs | my ( $name, $value, $globals, $sym ) = @_; | ||
122 | |||||
123 | 40 | 22µs | my $into = $globals->{into}; | ||
124 | 40 | 47µs | 40 | 155µs | my $type = $class->meta->{'functions'}{$name}{'type'}; # spent 155µs making 40 calls to Type::Library::meta, avg 4µs/call |
125 | 40 | 39µs | 40 | 69µs | my $tags = $class->meta->{'functions'}{$name}{'tags'}; # spent 69µ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 | 65µs | 40 | 45µs | ) if ( defined $type and $type->deprecated and not $globals->{allow_deprecated} ); # spent 45µs making 40 calls to Type::Tiny::deprecated, avg 1µ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 | 55µ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 | 44µs | my ( $prefix ) = grep defined, $value->{-prefix}, $globals->{prefix}, q(); | ||
146 | 40 | 30µs | my ( $suffix ) = grep defined, $value->{-suffix}, $globals->{suffix}, q(); | ||
147 | 40 | 14µ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 | 39µs | : ( $Type::Registry::DELAYED{$into}{$as} = $type ); | ||
152 | } | ||||
153 | |||||
154 | 40 | 113µs | 40 | 594µs | $class->SUPER::_exporter_install_sub( @_ ); # spent 594µ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 24µs (21+3) within Type::Library::setup_type_library which was called:
# once (21µs+3µs) by Type::Library::_exporter_validate_opts at line 34 | ||||
182 | 1 | 1µs | my ( $class, $type_library, $install_utils, $extends ) = @_; | ||
183 | |||||
184 | 1 | 1µs | 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 | 181µs | 2 | 41µs | # spent 28µs (15+13) within Type::Library::BEGIN@188 which was called:
# once (15µs+13µs) by Types::Standard::BEGIN@19 at line 188 # spent 28µs making 1 call to Type::Library::BEGIN@188
# spent 13µs making 1 call to strict::unimport |
189 | 1 | 9µs | push @{"$type_library\::ISA"}, $class; | ||
190 | 1 | 9µ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 1.02ms (781µs+234µs) within Type::Library::meta which was called 295 times, avg 3µs/call:
# 80 times (191µs+46µs) by Type::Library::_exporter_expand_sub at line 67, avg 3µs/call
# 40 times (138µs+17µs) by Type::Library::_exporter_install_sub at line 124, avg 4µs/call
# 40 times (84µs+36µs) by Type::Library::has_type at line 258, avg 3µs/call
# 40 times (60µs+18µs) by Type::Library::has_coercion at line 301, avg 2µs/call
# 40 times (59µs+10µs) by Type::Library::_exporter_install_sub at line 125, avg 2µs/call
# 37 times (144µs+69µs) by Type::Library::add_type at line 214, avg 6µs/call
# 11 times (47µs+24µs) by Type::Library::get_type at line 253, avg 6µs/call
# 3 times (7µs+3µs) by Type::Library::add_coercion at line 268, avg 3µs/call
# once (24µs+7µs) by JSON::Schema::Modern::BEGIN@31 at line 144 of Types/Standard.pm
# once (20µ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 (5µ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 | 42µs | 2 | 24µs | # spent 18µs (12+6) within Type::Library::BEGIN@207 which was called:
# once (12µs+6µs) by Types::Standard::BEGIN@19 at line 207 # spent 18µs making 1 call to Type::Library::BEGIN@207
# spent 6µs making 1 call to strict::unimport |
208 | 2 | 229µs | 2 | 68µs | # spent 37µs (6+31) within Type::Library::BEGIN@208 which was called:
# once (6µs+31µs) by Types::Standard::BEGIN@19 at line 208 # spent 37µs making 1 call to Type::Library::BEGIN@208
# spent 31µs making 1 call to warnings::unimport |
209 | 295 | 975µs | 295 | 234µs | return $_[0] if blessed $_[0]; # spent 234µs making 295 calls to Scalar::Util::blessed, avg 793ns/call |
210 | 163 | 372µs | ${"$_[0]\::META"} ||= bless {}, $_[0]; | ||
211 | } | ||||
212 | |||||
213 | # spent 38.8ms (2.79+36.0) within Type::Library::add_type which was called 37 times, avg 1.05ms/call:
# 20 times (1.37ms+20.2ms) 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.08ms/call
# once (123µs+1.30ms) by JSON::Schema::Modern::BEGIN@31 at line 827 of Types/Standard.pm
# once (68µs+1.30ms) by JSON::Schema::Modern::BEGIN@31 at line 924 of Types/Standard.pm
# once (86µs+1.25ms) by JSON::Schema::Modern::BEGIN@31 at line 770 of Types/Standard.pm
# once (91µs+1.16ms) by JSON::Schema::Modern::BEGIN@31 at line 883 of Types/Standard.pm
# once (152µs+1.10ms) by JSON::Schema::Modern::BEGIN@31 at line 1018 of Types/Standard.pm
# once (71µs+1.05ms) by JSON::Schema::Modern::BEGIN@31 at line 957 of Types/Standard.pm
# once (155µs+963µs) by JSON::Schema::Modern::BEGIN@31 at line 706 of Types/Standard.pm
# once (81µs+958µs) by JSON::Schema::Modern::BEGIN@31 at line 887 of Types/Standard.pm
# once (82µs+944µs) by JSON::Schema::Modern::BEGIN@31 at line 802 of Types/Standard.pm
# once (71µs+841µs) by JSON::Schema::Modern::BEGIN@31 at line 1035 of Types/Standard.pm
# once (45µs+853µs) by JSON::Schema::Modern::BEGIN@31 at line 332 of Types/Standard.pm
# once (68µs+806µs) by JSON::Schema::Modern::BEGIN@31 at line 989 of Types/Standard.pm
# once (85µs+782µs) by JSON::Schema::Modern::BEGIN@31 at line 1060 of Types/Standard.pm
# once (49µs+704µs) by JSON::Schema::Modern::BEGIN@31 at line 334 of Types/Standard.pm
# once (83µs+658µs) by JSON::Schema::Modern::BEGIN@31 at line 364 of Types/Standard.pm
# once (40µs+587µs) by JSON::Schema::Modern::BEGIN@31 at line 377 of Types/Standard.pm
# once (66µs+492µs) by JSON::Schema::Modern::BEGIN@31 at line 299 of Types/Standard.pm | ||||
214 | 37 | 77µs | 37 | 213µs | my $meta = shift->meta; # spent 213µs making 37 calls to Type::Library::meta, avg 6µs/call |
215 | 37 | 90µs | 37 | 18µs | my $class = blessed( $meta ) ; # spent 18µs making 37 calls to Scalar::Util::blessed, avg 486ns/call |
216 | |||||
217 | 37 | 15µ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 | 321µs | 111 | 2.80ms | ref( $_[0] ) eq q(HASH) ? 'Type::Tiny'->new( library => $class, %{ $_[0] } ) : # spent 2.77ms making 37 calls to Type::Tiny::new, avg 75µs/call
# spent 18µs making 37 calls to Type::Library::CORE:match, avg 486ns/call
# spent 15µs making 37 calls to Scalar::Util::blessed, avg 405ns/call |
223 | "Type::Tiny"->new( library => $class, @_ ); | ||||
224 | 37 | 62µs | my $name = $type->{name}; | ||
225 | |||||
226 | 37 | 72µs | 37 | 270µs | _croak( 'Type %s already exists in this library', $name ) if $meta->has_type( $name ); # spent 270µs making 37 calls to Type::Library::has_type, avg 7µs/call |
227 | 37 | 56µs | 37 | 185µs | _croak( 'Type %s conflicts with coercion of same name', $name ) if $meta->has_coercion( $name ); # spent 185µs making 37 calls to Type::Library::has_coercion, avg 5µs/call |
228 | 37 | 112µs | 37 | 222µs | _croak( 'Cannot add anonymous type to a library' ) if $type->is_anon; # spent 222µs making 37 calls to Type::Tiny::is_anon, avg 6µs/call |
229 | 37 | 11µs | $meta->{types} ||= {}; | ||
230 | 37 | 39µs | $meta->{types}{$name} = $type; | ||
231 | |||||
232 | 2 | 40µs | 2 | 23µs | # spent 17µs (11+6) within Type::Library::BEGIN@232 which was called:
# once (11µs+6µs) by Types::Standard::BEGIN@19 at line 232 # spent 17µs making 1 call to Type::Library::BEGIN@232
# spent 6µs making 1 call to strict::unimport |
233 | 2 | 796µs | 2 | 52µs | # spent 30µs (8+22) within Type::Library::BEGIN@233 which was called:
# once (8µs+22µs) by Types::Standard::BEGIN@19 at line 233 # spent 30µs making 1 call to Type::Library::BEGIN@233
# spent 22µs making 1 call to warnings::unimport |
234 | |||||
235 | 37 | 156µs | 37 | 31.4ms | for my $exportable ( @{ $type->exportables } ) { # spent 31.4ms making 37 calls to Type::Tiny::exportables, avg 848µs/call |
236 | 148 | 46µs | my $name = $exportable->{name}; | ||
237 | 148 | 21µs | my $code = $exportable->{code}; | ||
238 | 148 | 13µs | my $tags = $exportable->{tags}; | ||
239 | 148 | 505µs | 148 | 905µs | *{"$class\::$name"} = set_subname( "$class\::$name", $code ); # spent 905µs making 148 calls to Eval::TypeTiny::set_subname, avg 6µs/call |
240 | 148 | 116µs | push @{"$class\::EXPORT_OK"}, $name; | ||
241 | 148 | 280µs | push @{ ${"$class\::EXPORT_TAGS"}{$_} ||= [] }, $name for @$tags; | ||
242 | 148 | 542µ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 | 201µs | return $type; | ||
250 | } #/ sub add_type | ||||
251 | |||||
252 | # spent 155µs (84+71) within Type::Library::get_type which was called 11 times, avg 14µs/call:
# 10 times (79µs+65µ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 14µs/call
# once (5µs+6µs) by JSON::Schema::Modern::BEGIN@31 at line 1064 of Types/Standard.pm | ||||
253 | 11 | 24µs | 11 | 71µs | my $meta = shift->meta; # spent 71µs making 11 calls to Type::Library::meta, avg 6µs/call |
254 | 11 | 58µs | $meta->{types}{ $_[0] }; | ||
255 | } | ||||
256 | |||||
257 | sub has_type { | ||||
258 | 40 | 53µs | 40 | 120µs | my $meta = shift->meta; # spent 120µs making 40 calls to Type::Library::meta, avg 3µs/call |
259 | 40 | 101µ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.36ms (196µs+1.17) within Type::Library::add_coercion which was called 3 times, avg 454µs/call:
# once (118µs+503µs) by JSON::Schema::Modern::BEGIN@31 at line 1064 of Types/Standard.pm
# once (43µs+344µs) by JSON::Schema::Modern::BEGIN@31 at line 1105 of Types/Standard.pm
# once (35µs+319µs) by JSON::Schema::Modern::BEGIN@31 at line 1089 of Types/Standard.pm | ||||
268 | 3 | 3µs | 3 | 10µs | my $meta = shift->meta; # spent 10µs making 3 calls to Type::Library::meta, avg 3µs/call |
269 | 3 | 7µs | 3 | 2µs | my $class = blessed( $meta ); # spent 2µs making 3 calls to Scalar::Util::blessed, avg 667ns/call |
270 | |||||
271 | 3 | 0s | _croak( 'Type library is immutable' ) if $meta->{immutable}; | ||
272 | |||||
273 | 3 | 3µs | require Type::Coercion; | ||
274 | 3 | 15µs | 6 | 383µs | my $c = blessed( $_[0] ) ? $_[0] : "Type::Coercion"->new( @_ ); # spent 382µs making 3 calls to Type::Coercion::new, avg 127µs/call
# spent 1µs making 3 calls to Scalar::Util::blessed, avg 333ns/call |
275 | 3 | 16µs | 3 | 2µs | my $name = $c->name; # spent 2µs making 3 calls to Type::Coercion::name, avg 667ns/call |
276 | |||||
277 | 3 | 5µs | 3 | 23µs | _croak( 'Coercion %s already exists in this library', $name ) if $meta->has_coercion( $name ); # spent 23µs making 3 calls to Type::Library::has_coercion, avg 8µs/call |
278 | 3 | 5µs | 3 | 16µs | _croak( 'Coercion %s conflicts with type of same name', $name ) if $meta->has_type( $name ); # spent 16µs making 3 calls to Type::Library::has_type, avg 5µs/call |
279 | 3 | 1µs | 3 | 7µs | _croak( 'Cannot add anonymous type to a library' ) if $c->is_anon; # spent 7µs making 3 calls to Type::Coercion::is_anon, avg 2µs/call |
280 | |||||
281 | 3 | 3µs | $meta->{coercions} ||= {}; | ||
282 | 3 | 1µs | $meta->{coercions}{$name} = $c; | ||
283 | |||||
284 | 2 | 92µs | 2 | 84µs | # spent 52µs (20+32) within Type::Library::BEGIN@284 which was called:
# once (20µs+32µs) by Types::Standard::BEGIN@19 at line 284 # spent 52µs making 1 call to Type::Library::BEGIN@284
# spent 32µs making 1 call to strict::unimport |
285 | 2 | 279µs | 2 | 73µs | # spent 42µs (11+31) within Type::Library::BEGIN@285 which was called:
# once (11µs+31µs) by Types::Standard::BEGIN@19 at line 285 # spent 42µs making 1 call to Type::Library::BEGIN@285
# spent 31µs making 1 call to warnings::unimport |
286 | |||||
287 | 3 | 14µs | 3 | 723µs | *{"$class\::$name"} = type_to_coderef( $c ); # spent 723µs making 3 calls to Eval::TypeTiny::type_to_coderef, avg 241µs/call |
288 | 3 | 3µs | push @{"$class\::EXPORT_OK"}, $name; | ||
289 | 3 | 7µs | push @{ ${"$class\::EXPORT_TAGS"}{'coercions'} ||= [] }, $name; | ||
290 | 3 | 19µ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 | 35µs | 40 | 78µs | my $meta = shift->meta; # spent 78µs making 40 calls to Type::Library::meta, avg 2µs/call |
302 | 40 | 95µ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.26ms (335µs+2.92) within Type::Library::make_immutable which was called:
# once (335µs+2.92ms) 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 | 43µs | 2 | 22µs | # spent 17µs (12+5) within Type::Library::BEGIN@314 which was called:
# once (12µs+5µs) by Types::Standard::BEGIN@19 at line 314 # spent 17µs making 1 call to Type::Library::BEGIN@314
# spent 5µs making 1 call to strict::unimport |
315 | 2 | 230µs | 2 | 57µs | # spent 35µs (13+22) within Type::Library::BEGIN@315 which was called:
# once (13µs+22µs) by Types::Standard::BEGIN@19 at line 315 # spent 35µs making 1 call to Type::Library::BEGIN@315
# spent 22µs making 1 call to warnings::unimport |
316 | |||||
317 | 1 | 24µs | for my $type ( values %{ $meta->{types} } ) { | ||
318 | 37 | 73µs | 74 | 1.98ms | $type->coercion->freeze; # spent 1.88ms making 37 calls to Type::Tiny::coercion, avg 51µs/call
# spent 94µs making 37 calls to Type::Coercion::freeze, avg 3µs/call |
319 | 37 | 42µs | 39 | 329µs | next unless $type->has_coercion && $type->coercion->frozen; # spent 324µs making 37 calls to Type::Tiny::has_coercion, avg 9µs/call
# spent 3µs making 1 call to Type::Tiny::coercion
# spent 2µs making 1 call to Type::Coercion::frozen |
320 | 1 | 4µs | 1 | 605µs | for my $e ( $type->exportables_by_tag( 'to' ) ) { # spent 605µs making 1 call to Type::Tiny::exportables_by_tag |
321 | 1 | 1µs | my $qualified_name = $class . '::' . $e->{name}; | ||
322 | 1 | 12µ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 | 54µs | $meta->{immutable} = 1; | ||
327 | } | ||||
328 | |||||
329 | 1 | 6µ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 |