← Index
NYTProf Performance Profile   « line view »
For ../prof.pl
  Run on Wed Dec 14 15:33:55 2022
Reported on Wed Dec 14 15:40:03 2022

Filename/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Type/Library.pm
StatementsExecuted 3521 statements in 9.65ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11110.2ms18.1msType::Library::::BEGIN@16Type::Library::BEGIN@16
1113.21ms3.78msType::Library::::BEGIN@14Type::Library::BEGIN@14
371812.68ms38.1msType::Library::::add_typeType::Library::add_type
294123748µs944µsType::Library::::metaType::Library::meta
4011659µs1.68msType::Library::::_exporter_expand_subType::Library::_exporter_expand_sub
4011557µs1.25msType::Library::::_exporter_install_subType::Library::_exporter_install_sub
4021152µs260µsType::Library::::has_typeType::Library::has_type
111147µs1.63msType::Library::::make_immutableType::Library::make_immutable
4021115µs214µsType::Library::::has_coercionType::Library::has_coercion
33189µs657µsType::Library::::add_coercionType::Library::add_coercion
81167µs98µsType::Library::::_exporter_validate_optsType::Library::_exporter_validate_opts
112154µs112µsType::Library::::get_typeType::Library::get_type
11138µs38µsType::Library::::BEGIN@3Type::Library::BEGIN@3
772127µs27µsType::Library::::CORE:matchType::Library::CORE:match (opcode)
11118µs20µsType::Library::::setup_type_libraryType::Library::setup_type_library
11116µs22µsType::Library::::BEGIN@284Type::Library::BEGIN@284
11112µs21µsType::Library::::BEGIN@188Type::Library::BEGIN@188
11111µs178µsType::Library::::BEGIN@15Type::Library::BEGIN@15
1119µs13µsType::Library::::BEGIN@207Type::Library::BEGIN@207
1119µs13µsType::Library::::BEGIN@314Type::Library::BEGIN@314
1119µs13µsType::Library::::BEGIN@4Type::Library::BEGIN@4
1118µs35µsType::Library::::BEGIN@208Type::Library::BEGIN@208
1118µs21µsType::Library::::BEGIN@315Type::Library::BEGIN@315
1116µs6µsType::Library::::BEGIN@17Type::Library::BEGIN@17
1116µs10µsType::Library::::BEGIN@232Type::Library::BEGIN@232
1116µs28µsType::Library::::BEGIN@285Type::Library::BEGIN@285
1116µs48µsType::Library::::BEGIN@5Type::Library::BEGIN@5
1115µs19µsType::Library::::BEGIN@233Type::Library::BEGIN@233
1112µs2µsType::Library::::BEGIN@7Type::Library::BEGIN@7
1112µs2µsType::Library::::CORE:substType::Library::CORE:subst (opcode)
0000s0sType::Library::::_croakType::Library::_croak
0000s0sType::Library::::_exporter_failType::Library::_exporter_fail
0000s0sType::Library::::coercion_namesType::Library::coercion_names
0000s0sType::Library::::get_coercionType::Library::get_coercion
0000s0sType::Library::::type_namesType::Library::type_names
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Type::Library;
2
3287µs138µs
# spent 38µs within Type::Library::BEGIN@3 which was called: # once (38µs+0s) by Types::Standard::BEGIN@19 at line 3
use 5.008001;
# spent 38µs making 1 call to Type::Library::BEGIN@3
4230µs217µs
# spent 13µs (9+4) within Type::Library::BEGIN@4 which was called: # once (9µs+4µs) by Types::Standard::BEGIN@19 at line 4
use strict;
# spent 13µs making 1 call to Type::Library::BEGIN@4 # spent 4µs making 1 call to strict::import
5274µs290µs
# spent 48µs (6+42) within Type::Library::BEGIN@5 which was called: # once (6µs+42µs) by Types::Standard::BEGIN@19 at line 5
use warnings;
# spent 48µs making 1 call to Type::Library::BEGIN@5 # spent 42µ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
BEGIN {
810s $Type::Library::AUTHORITY = 'cpan:TOBYINK';
913µs $Type::Library::VERSION = '2.000001';
10153µs12µs}
# spent 2µs making 1 call to Type::Library::BEGIN@7
11
1211µs$Type::Library::VERSION =~ tr/_//d;
13
142960µs24.25ms
# spent 3.78ms (3.21+573µs) within Type::Library::BEGIN@14 which was called: # once (3.21ms+573µs) by Types::Standard::BEGIN@19 at line 14
use Eval::TypeTiny qw< eval_closure set_subname type_to_coderef NICE_PROTOTYPES >;
# spent 3.78ms making 1 call to Type::Library::BEGIN@14 # spent 475µs making 1 call to Eval::TypeTiny::import
15239µs2345µs
# spent 178µs (11+167) within Type::Library::BEGIN@15 which was called: # once (11µs+167µs) by Types::Standard::BEGIN@19 at line 15
use Scalar::Util qw< blessed refaddr >;
# spent 178µs making 1 call to Type::Library::BEGIN@15 # spent 167µs making 1 call to Exporter::import
162728µs118.1ms
# spent 18.1ms (10.2+7.92) within Type::Library::BEGIN@16 which was called: # once (10.2ms+7.92ms) by Types::Standard::BEGIN@19 at line 16
use Type::Tiny ();
# spent 18.1ms making 1 call to Type::Library::BEGIN@16
172656µs16µs
# spent 6µs within Type::Library::BEGIN@17 which was called: # once (6µs+0s) by Types::Standard::BEGIN@19 at line 17
use Types::TypeTiny ();
# spent 6µs making 1 call to Type::Library::BEGIN@17
18
1911µsrequire Exporter::Tiny;
20110µsour @ISA = 'Exporter::Tiny';
21
22sub _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 98µs (67+31) within Type::Library::_exporter_validate_opts which was called 8 times, avg 12µs/call: # 8 times (67µs+31µs) by Exporter::Tiny::import at line 77 of Exporter/Tiny.pm, avg 12µs/call
sub _exporter_validate_opts {
3186µs my ( $class, $opts ) = ( shift, @_ );
32
33 $class->setup_type_library( @{$opts}{qw/ into utils extends /} )
34812µs120µs if $_[0]{base} || $_[0]{extends};
# spent 20µs making 1 call to Type::Library::setup_type_library
35
36842µs811µs return $class->SUPER::_exporter_validate_opts( @_ );
# spent 11µ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.68ms (659µs+1.02) within Type::Library::_exporter_expand_sub which was called 40 times, avg 42µs/call: # 40 times (659µs+1.02ms) by Exporter::Tiny::import at line 82 of Exporter/Tiny.pm, avg 42µs/call
sub _exporter_expand_sub {
45408µs my $class = shift;
464012µ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 #
534069µs4012µs if ( $name =~ /^\+(.+)/ and $class->has_type( "$1" ) ) {
# spent 12µs making 40 calls to Type::Library::CORE:match, avg 300ns/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 #
6740172µs79266µs if ( my $f = $class->meta->{'functions'}{$name}
# spent 266µs making 79 calls to Type::Library::meta, avg 3µs/call
68 and defined $class->meta->{'functions'}{$name}{'type'} ) {
69
703813µs my $type = $f->{type};
713821µs my $tag = $f->{tags}[0];
723845µs3852µs my $typename = $type->name;
# spent 52µs making 38 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 #
77386µs my $custom_type = 0;
783825µs for my $param ( qw/ of where / ) {
797623µ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 #
903813µs if ( $tag eq 'types' ) {
91386µs my $post_method = q();
92389µs $post_method = '->mouse_type' if $globals->{mouse};
93386µs $post_method = '->moose_type' if $globals->{moose};
94384µ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 #
1053810µ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 #
11340103µs40693µs return $class->SUPER::_exporter_expand_sub( @_ );
# spent 693µ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.25ms (557µs+696µs) within Type::Library::_exporter_install_sub which was called 40 times, avg 31µs/call: # 40 times (557µs+696µs) by Exporter::Tiny::import at line 84 of Exporter/Tiny.pm, avg 31µs/call
sub _exporter_install_sub {
120406µs my $class = shift;
1214010µs my ( $name, $value, $globals, $sym ) = @_;
122
1234012µs my $into = $globals->{into};
1244045µs4093µs my $type = $class->meta->{'functions'}{$name}{'type'};
# spent 93µs making 40 calls to Type::Library::meta, avg 2µs/call
1254039µs4083µs my $tags = $class->meta->{'functions'}{$name}{'tags'};
# spent 83µ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",
1334045µs3837µs ) if ( defined $type and $type->deprecated and not $globals->{allow_deprecated} );
# spent 37µs making 38 calls to Type::Tiny::deprecated, avg 974ns/call
134
135 # If exporting a type constraint into a real package, then
136 # add it to the package's type registry.
137 #
1384053µ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.
1453866µs my ( $prefix ) = grep defined, $value->{-prefix}, $globals->{prefix}, q();
1463822µs my ( $suffix ) = grep defined, $value->{-suffix}, $globals->{suffix}, q();
1473814µs my $as = $prefix . ( $value->{-as} || $name ) . $suffix;
148
149 $INC{'Type/Registry.pm'}
150 ? 'Type::Registry'->for_class( $into )->add_type( $type, $as )
1513844µs : ( $Type::Registry::DELAYED{$into}{$as} = $type );
152 }
153
15440113µs40483µs $class->SUPER::_exporter_install_sub( @_ );
# spent 483µs making 40 calls to Exporter::Tiny::_exporter_install_sub, avg 12µs/call
155} #/ sub _exporter_install_sub
156
157sub _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 20µs (18+2) within Type::Library::setup_type_library which was called: # once (18µs+2µs) by Type::Library::_exporter_validate_opts at line 34
sub setup_type_library {
18211µs my ( $class, $type_library, $install_utils, $extends ) = @_;
183
18411µs my @extends = ref( $extends ) ? @$extends : $extends ? $extends : ();
18511µs unshift @extends, $class if $class ne __PACKAGE__;
186
18710s if ( not ref $type_library ) {
1882151µs230µs
# spent 21µs (12+9) within Type::Library::BEGIN@188 which was called: # once (12µs+9µs) by Types::Standard::BEGIN@19 at line 188
no strict "refs";
# spent 21µs making 1 call to Type::Library::BEGIN@188 # spent 9µs making 1 call to strict::unimport
18918µs push @{"$type_library\::ISA"}, $class;
19017µs12µs ( my $file = $type_library ) =~ s{::}{/}g;
# spent 2µs making 1 call to Type::Library::CORE:subst
19111µs $INC{"$file.pm"} ||= __FILE__;
192 }
193
19410s if ( $install_utils ) {
195 require Type::Utils;
196 'Type::Utils'->import( { into => $type_library }, '-default' );
197 }
198
19913µ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 944µs (748+196) within Type::Library::meta which was called 294 times, avg 3µs/call: # 79 times (231µs+35µs) by Type::Library::_exporter_expand_sub at line 67, avg 3µs/call # 40 times (89µs+19µs) by Type::Library::has_type at line 258, avg 3µs/call # 40 times (75µs+24µs) by Type::Library::has_coercion at line 301, avg 2µs/call # 40 times (83µs+10µs) by Type::Library::_exporter_install_sub at line 124, avg 2µs/call # 40 times (65µs+18µs) by Type::Library::_exporter_install_sub at line 125, avg 2µs/call # 37 times (116µs+65µs) by Type::Library::add_type at line 214, avg 5µs/call # 11 times (48µs+10µs) by Type::Library::get_type at line 253, avg 5µs/call # 3 times (5µs+2µs) by Type::Library::add_coercion at line 268, avg 2µs/call # once (25µs+12µs) by JSON::Schema::Modern::BEGIN@31 at line 144 of Types/Standard.pm # once (8µs+1µ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 (2µs+0s) by JSON::Schema::Modern::BEGIN@31 at line 1107 of Types/Standard.pm # once (1µs+0s) by Type::Library::make_immutable at line 311
sub meta {
207231µs217µs
# spent 13µs (9+4) within Type::Library::BEGIN@207 which was called: # once (9µs+4µs) by Types::Standard::BEGIN@19 at line 207
no strict "refs";
# spent 13µs making 1 call to Type::Library::BEGIN@207 # spent 4µs making 1 call to strict::unimport
2082175µs262µs
# spent 35µs (8+27) within Type::Library::BEGIN@208 which was called: # once (8µs+27µs) by Types::Standard::BEGIN@19 at line 208
no warnings "once";
# spent 35µs making 1 call to Type::Library::BEGIN@208 # spent 27µs making 1 call to warnings::unimport
209294914µs294196µs return $_[0] if blessed $_[0];
# spent 196µs making 294 calls to Scalar::Util::blessed, avg 667ns/call
210162298µs ${"$_[0]\::META"} ||= bless {}, $_[0];
211}
212
213
# spent 38.1ms (2.68+35.4) within Type::Library::add_type which was called 37 times, avg 1.03ms/call: # 20 times (1.51ms+20.6ms) 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.11ms/call # once (88µs+1.39ms) by JSON::Schema::Modern::BEGIN@31 at line 332 of Types/Standard.pm # once (90µs+1.34ms) by JSON::Schema::Modern::BEGIN@31 at line 364 of Types/Standard.pm # once (77µs+1.19ms) by JSON::Schema::Modern::BEGIN@31 at line 957 of Types/Standard.pm # once (56µs+1.12ms) by JSON::Schema::Modern::BEGIN@31 at line 924 of Types/Standard.pm # once (67µs+907µs) by JSON::Schema::Modern::BEGIN@31 at line 299 of Types/Standard.pm # once (78µs+878µs) by JSON::Schema::Modern::BEGIN@31 at line 1018 of Types/Standard.pm # once (71µs+877µs) by JSON::Schema::Modern::BEGIN@31 at line 989 of Types/Standard.pm # once (81µs+845µs) by JSON::Schema::Modern::BEGIN@31 at line 334 of Types/Standard.pm # once (71µs+826µs) by JSON::Schema::Modern::BEGIN@31 at line 827 of Types/Standard.pm # once (58µs+833µs) by JSON::Schema::Modern::BEGIN@31 at line 770 of Types/Standard.pm # once (66µs+799µs) by JSON::Schema::Modern::BEGIN@31 at line 377 of Types/Standard.pm # once (68µs+764µs) by JSON::Schema::Modern::BEGIN@31 at line 883 of Types/Standard.pm # once (83µs+687µs) by JSON::Schema::Modern::BEGIN@31 at line 706 of Types/Standard.pm # once (61µs+703µs) by JSON::Schema::Modern::BEGIN@31 at line 887 of Types/Standard.pm # once (63µs+644µs) by JSON::Schema::Modern::BEGIN@31 at line 802 of Types/Standard.pm # once (48µs+556µs) by JSON::Schema::Modern::BEGIN@31 at line 1035 of Types/Standard.pm # once (43µs+442µs) by JSON::Schema::Modern::BEGIN@31 at line 1060 of Types/Standard.pm
sub add_type {
2143760µs37181µs my $meta = shift->meta;
# spent 181µs making 37 calls to Type::Library::meta, avg 5µs/call
2153795µs3724µs my $class = blessed( $meta ) ;
# spent 24µs making 37 calls to Scalar::Util::blessed, avg 649ns/call
216
2173718µ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] ) :
22237304µs1112.38ms ref( $_[0] ) eq q(HASH) ? 'Type::Tiny'->new( library => $class, %{ $_[0] } ) :
# spent 2.34ms making 37 calls to Type::Tiny::new, avg 63µs/call # spent 15µs making 37 calls to Scalar::Util::blessed, avg 405ns/call # spent 15µs making 37 calls to Type::Library::CORE:match, avg 405ns/call
223 "Type::Tiny"->new( library => $class, @_ );
2243712µs my $name = $type->{name};
225
2263767µs37249µs _croak( 'Type %s already exists in this library', $name ) if $meta->has_type( $name );
# spent 249µs making 37 calls to Type::Library::has_type, avg 7µs/call
2273750µs37205µs _croak( 'Type %s conflicts with coercion of same name', $name ) if $meta->has_coercion( $name );
# spent 205µs making 37 calls to Type::Library::has_coercion, avg 6µs/call
2283750µs37143µs _croak( 'Cannot add anonymous type to a library' ) if $type->is_anon;
# spent 143µs making 37 calls to Type::Tiny::is_anon, avg 4µs/call
2293711µs $meta->{types} ||= {};
2303729µs $meta->{types}{$name} = $type;
231
232231µs214µs
# spent 10µs (6+4) within Type::Library::BEGIN@232 which was called: # once (6µs+4µs) by Types::Standard::BEGIN@19 at line 232
no strict "refs";
# spent 10µs making 1 call to Type::Library::BEGIN@232 # spent 4µs making 1 call to strict::unimport
2332809µs233µs
# spent 19µs (5+14) within Type::Library::BEGIN@233 which was called: # once (5µs+14µs) by Types::Standard::BEGIN@19 at line 233
no warnings "redefine", "prototype";
# spent 19µs making 1 call to Type::Library::BEGIN@233 # spent 14µs making 1 call to warnings::unimport
234
23537128µs3731.4ms for my $exportable ( @{ $type->exportables } ) {
# spent 31.4ms making 37 calls to Type::Tiny::exportables, avg 847µs/call
23614843µs my $name = $exportable->{name};
23714835µs my $code = $exportable->{code};
23814825µs my $tags = $exportable->{tags};
239148492µs148898µs *{"$class\::$name"} = set_subname( "$class\::$name", $code );
# spent 898µs making 148 calls to Eval::TypeTiny::set_subname, avg 6µs/call
240148134µs push @{"$class\::EXPORT_OK"}, $name;
241148233µs push @{ ${"$class\::EXPORT_TAGS"}{$_} ||= [] }, $name for @$tags;
242148522µ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 )
2473745µs : ( $Type::Registry::DELAYED{$class}{$name} = $type );
248
24937160µs return $type;
250} #/ sub add_type
251
252
# spent 112µs (54+58) within Type::Library::get_type which was called 11 times, avg 10µs/call: # 10 times (51µs+55µ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 11µs/call # once (3µs+3µs) by JSON::Schema::Modern::BEGIN@31 at line 1064 of Types/Standard.pm
sub get_type {
2531124µs1158µs my $meta = shift->meta;
# spent 58µs making 11 calls to Type::Library::meta, avg 5µs/call
2541136µs $meta->{types}{ $_[0] };
255}
256
257
# spent 260µs (152+108) within Type::Library::has_type which was called 40 times, avg 6µs/call: # 37 times (145µs+104µs) by Type::Library::add_type at line 226, avg 7µs/call # 3 times (7µs+4µs) by Type::Library::add_coercion at line 278, avg 4µs/call
sub has_type {
2584041µs40108µs my $meta = shift->meta;
# spent 108µs making 40 calls to Type::Library::meta, avg 3µs/call
25940111µs exists $meta->{types}{ $_[0] };
260}
261
262sub type_names {
263 my $meta = shift->meta;
264 keys %{ $meta->{types} };
265}
266
267
# spent 657µs (89+568) within Type::Library::add_coercion which was called 3 times, avg 219µs/call: # once (61µs+269µs) by JSON::Schema::Modern::BEGIN@31 at line 1064 of Types/Standard.pm # once (16µs+153µs) by JSON::Schema::Modern::BEGIN@31 at line 1089 of Types/Standard.pm # once (12µs+146µs) by JSON::Schema::Modern::BEGIN@31 at line 1105 of Types/Standard.pm
sub add_coercion {
26831µs37µs my $meta = shift->meta;
# spent 7µs making 3 calls to Type::Library::meta, avg 2µs/call
26936µs32µs my $class = blessed( $meta );
# spent 2µs making 3 calls to Scalar::Util::blessed, avg 667ns/call
270
27131µs _croak( 'Type library is immutable' ) if $meta->{immutable};
272
27331µs require Type::Coercion;
27439µs6199µs my $c = blessed( $_[0] ) ? $_[0] : "Type::Coercion"->new( @_ );
# spent 199µs making 3 calls to Type::Coercion::new, avg 66µs/call # spent 0s making 3 calls to Scalar::Util::blessed, avg 0s/call
27533µs30s my $name = $c->name;
# spent 0s making 3 calls to Type::Coercion::name, avg 0s/call
276
27732µs39µs _croak( 'Coercion %s already exists in this library', $name ) if $meta->has_coercion( $name );
# spent 9µs making 3 calls to Type::Library::has_coercion, avg 3µs/call
27831µs311µs _croak( 'Coercion %s conflicts with type of same name', $name ) if $meta->has_type( $name );
# spent 11µs making 3 calls to Type::Library::has_type, avg 4µs/call
27931µs36µ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
28130s $meta->{coercions} ||= {};
28232µs $meta->{coercions}{$name} = $c;
283
284244µs228µs
# spent 22µs (16+6) within Type::Library::BEGIN@284 which was called: # once (16µs+6µs) by Types::Standard::BEGIN@19 at line 284
no strict "refs";
# spent 22µs making 1 call to Type::Library::BEGIN@284 # spent 6µs making 1 call to strict::unimport
2852204µs250µs
# spent 28µs (6+22) within Type::Library::BEGIN@285 which was called: # once (6µs+22µs) by Types::Standard::BEGIN@19 at line 285
no warnings "redefine", "prototype";
# spent 28µs making 1 call to Type::Library::BEGIN@285 # spent 22µs making 1 call to warnings::unimport
286
28737µs3334µs *{"$class\::$name"} = type_to_coderef( $c );
# spent 334µs making 3 calls to Eval::TypeTiny::type_to_coderef, avg 111µs/call
28833µs push @{"$class\::EXPORT_OK"}, $name;
28933µs push @{ ${"$class\::EXPORT_TAGS"}{'coercions'} ||= [] }, $name;
29038µs $meta->{'functions'}{$name} = { coercion => $c, tags => [ 'coercions' ] };
291
29236µs return $c;
293} #/ sub add_coercion
294
295sub get_coercion {
296 my $meta = shift->meta;
297 $meta->{coercions}{ $_[0] };
298}
299
300
# spent 214µs (115+99) within Type::Library::has_coercion which was called 40 times, avg 5µs/call: # 37 times (111µs+94µs) by Type::Library::add_type at line 227, avg 6µs/call # 3 times (4µs+5µs) by Type::Library::add_coercion at line 277, avg 3µs/call
sub has_coercion {
3014032µs4099µs my $meta = shift->meta;
# spent 99µs making 40 calls to Type::Library::meta, avg 2µs/call
3024083µs exists $meta->{coercions}{ $_[0] };
303}
304
305sub coercion_names {
306 my $meta = shift->meta;
307 keys %{ $meta->{coercions} };
308}
309
310
# spent 1.63ms (147µs+1.48) within Type::Library::make_immutable which was called: # once (147µs+1.48ms) by JSON::Schema::Modern::BEGIN@31 at line 1107 of Types/Standard.pm
sub make_immutable {
31111µs11µs my $meta = shift->meta;
# spent 1µs making 1 call to Type::Library::meta
31210s my $class = ref( $meta );
313
314231µs217µs
# spent 13µs (9+4) within Type::Library::BEGIN@314 which was called: # once (9µs+4µs) by Types::Standard::BEGIN@19 at line 314
no strict "refs";
# spent 13µs making 1 call to Type::Library::BEGIN@314 # spent 4µs making 1 call to strict::unimport
3152233µs234µs
# spent 21µs (8+13) within Type::Library::BEGIN@315 which was called: # once (8µs+13µs) by Types::Standard::BEGIN@19 at line 315
no warnings "redefine", "prototype";
# spent 21µs making 1 call to Type::Library::BEGIN@315 # spent 13µs making 1 call to warnings::unimport
316
31718µs for my $type ( values %{ $meta->{types} } ) {
3183739µs74955µs $type->coercion->freeze;
# spent 936µs making 37 calls to Type::Tiny::coercion, avg 25µs/call # spent 19µs making 37 calls to Type::Coercion::freeze, avg 514ns/call
3193730µs39148µs next unless $type->has_coercion && $type->coercion->frozen;
# spent 145µs making 37 calls to Type::Tiny::has_coercion, avg 4µs/call # spent 2µs making 1 call to Type::Coercion::frozen # spent 1µs making 1 call to Type::Tiny::coercion
32013µs1372µs for my $e ( $type->exportables_by_tag( 'to' ) ) {
# spent 372µs making 1 call to Type::Tiny::exportables_by_tag
32111µs my $qualified_name = $class . '::' . $e->{name};
32218µs18µs *$qualified_name = set_subname( $qualified_name, $e->{code} );
# spent 8µs making 1 call to Eval::TypeTiny::set_subname
323 }
324 }
325
32616µs $meta->{immutable} = 1;
327}
328
32915µs1;
330
331__END__
 
# spent 27µs within Type::Library::CORE:match which was called 77 times, avg 351ns/call: # 40 times (12µs+0s) by Type::Library::_exporter_expand_sub at line 53, avg 300ns/call # 37 times (15µs+0s) by Type::Library::add_type at line 222, avg 405ns/call
sub Type::Library::CORE:match; # opcode
# spent 2µs within Type::Library::CORE:subst which was called: # once (2µs+0s) by Type::Library::setup_type_library at line 190
sub Type::Library::CORE:subst; # opcode