← Index
NYTProf Performance Profile   « line view »
For ../prof.pl
  Run on Wed Dec 14 16:10:05 2022
Reported on Wed Dec 14 16:12:57 2022

Filename/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Type/Library.pm
StatementsExecuted 3557 statements in 8.09ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1119.66ms15.0msType::Library::::BEGIN@16Type::Library::BEGIN@16
1112.58ms2.99msType::Library::::BEGIN@14Type::Library::BEGIN@14
371812.32ms33.0msType::Library::::add_typeType::Library::add_type
4011804µs1.79msType::Library::::_exporter_expand_subType::Library::_exporter_expand_sub
295123679µs854µsType::Library::::metaType::Library::meta
4011517µs1.34msType::Library::::_exporter_install_subType::Library::_exporter_install_sub
111261µs3.89msType::Library::::make_immutableType::Library::make_immutable
331152µs1.22msType::Library::::add_coercionType::Library::add_coercion
4021130µs242µsType::Library::::has_typeType::Library::has_type
4021106µs186µsType::Library::::has_coercionType::Library::has_coercion
81188µs116µsType::Library::::_exporter_validate_optsType::Library::_exporter_validate_opts
112167µs125µsType::Library::::get_typeType::Library::get_type
11151µs51µsType::Library::::BEGIN@3Type::Library::BEGIN@3
772129µs29µsType::Library::::CORE:matchType::Library::CORE:match (opcode)
11115µs18µsType::Library::::setup_type_libraryType::Library::setup_type_library
11111µs19µsType::Library::::BEGIN@284Type::Library::BEGIN@284
1119µs12µsType::Library::::BEGIN@314Type::Library::BEGIN@314
1118µs23µsType::Library::::BEGIN@315Type::Library::BEGIN@315
1117µs30µsType::Library::::BEGIN@15Type::Library::BEGIN@15
1117µs14µsType::Library::::BEGIN@188Type::Library::BEGIN@188
1116µs25µsType::Library::::BEGIN@285Type::Library::BEGIN@285
1115µs26µsType::Library::::BEGIN@208Type::Library::BEGIN@208
1115µs7µsType::Library::::BEGIN@4Type::Library::BEGIN@4
1115µs32µsType::Library::::BEGIN@5Type::Library::BEGIN@5
1114µs4µsType::Library::::BEGIN@17Type::Library::BEGIN@17
1114µs7µsType::Library::::BEGIN@207Type::Library::BEGIN@207
1114µs7µsType::Library::::BEGIN@232Type::Library::BEGIN@232
1113µs3µsType::Library::::CORE:substType::Library::CORE:subst (opcode)
1112µs18µsType::Library::::BEGIN@233Type::Library::BEGIN@233
1112µs2µsType::Library::::BEGIN@7Type::Library::BEGIN@7
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
3233µs151µs
# spent 51µs within Type::Library::BEGIN@3 which was called: # once (51µs+0s) by Types::Standard::BEGIN@19 at line 3
use 5.008001;
# spent 51µs making 1 call to Type::Library::BEGIN@3
4243µs29µ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
use strict;
# spent 7µs making 1 call to Type::Library::BEGIN@4 # spent 2µs making 1 call to strict::import
5238µs259µ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
use warnings;
# 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
BEGIN {
811µs $Type::Library::AUTHORITY = 'cpan:TOBYINK';
912µs $Type::Library::VERSION = '2.000001';
10129µs12µs}
# spent 2µs making 1 call to Type::Library::BEGIN@7
11
1211µs$Type::Library::VERSION =~ tr/_//d;
13
142534µs23.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
use Eval::TypeTiny qw< eval_closure set_subname type_to_coderef NICE_PROTOTYPES >;
# spent 2.99ms making 1 call to Type::Library::BEGIN@14 # spent 289µs making 1 call to Eval::TypeTiny::import
15217µs253µ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
use Scalar::Util qw< blessed refaddr >;
# spent 30µs making 1 call to Type::Library::BEGIN@15 # spent 23µs making 1 call to Exporter::import
162562µs115.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
use Type::Tiny ();
# spent 15.0ms making 1 call to Type::Library::BEGIN@16
172463µs14µs
# spent 4µs within Type::Library::BEGIN@17 which was called: # once (4µs+0s) by Types::Standard::BEGIN@19 at line 17
use Types::TypeTiny ();
# spent 4µs making 1 call to Type::Library::BEGIN@17
18
1911µsrequire Exporter::Tiny;
2019µ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 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
sub _exporter_validate_opts {
3185µs my ( $class, $opts ) = ( shift, @_ );
32
33 $class->setup_type_library( @{$opts}{qw/ into utils extends /} )
3489µs118µs if $_[0]{base} || $_[0]{extends};
# spent 18µs making 1 call to Type::Library::setup_type_library
35
36844µs810µ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
sub _exporter_expand_sub {
45404µ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 #
534099µs4015µ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 #
6740178µs80221µ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
70408µs my $type = $f->{type};
714029µs my $tag = $f->{tags}[0];
724041µs4060µ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 #
77408µs my $custom_type = 0;
784017µs for my $param ( qw/ of where / ) {
798047µ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 #
904018µs if ( $tag eq 'types' ) {
91404µs my $post_method = q();
924013µs $post_method = '->mouse_type' if $globals->{mouse};
93407µs $post_method = '->moose_type' if $globals->{moose};
94408µ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 #
1054011µ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 #
11340111µs40690µ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
sub _exporter_install_sub {
120406µs my $class = shift;
121409µs my ( $name, $value, $globals, $sym ) = @_;
122
1234015µs my $into = $globals->{into};
1244041µs4090µs my $type = $class->meta->{'functions'}{$name}{'type'};
# spent 90µs making 40 calls to Type::Library::meta, avg 2µs/call
1254029µs4084µ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",
1334064µs4064µ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 #
1384039µ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.
1454037µs my ( $prefix ) = grep defined, $value->{-prefix}, $globals->{prefix}, q();
1464028µs my ( $suffix ) = grep defined, $value->{-suffix}, $globals->{suffix}, q();
1474013µs my $as = $prefix . ( $value->{-as} || $name ) . $suffix;
148
149 $INC{'Type/Registry.pm'}
150 ? 'Type::Registry'->for_class( $into )->add_type( $type, $as )
1514036µs : ( $Type::Registry::DELAYED{$into}{$as} = $type );
152 }
153
15440121µs40588µ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
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 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
sub setup_type_library {
18210s my ( $class, $type_library, $install_utils, $extends ) = @_;
183
18410s my @extends = ref( $extends ) ? @$extends : $extends ? $extends : ();
18511µs unshift @extends, $class if $class ne __PACKAGE__;
186
18710s if ( not ref $type_library ) {
1882106µs221µ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
no strict "refs";
# spent 14µs making 1 call to Type::Library::BEGIN@188 # spent 7µs making 1 call to strict::unimport
18916µs push @{"$type_library\::ISA"}, $class;
19018µs13µs ( my $file = $type_library ) =~ s{::}{/}g;
# spent 3µ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 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
sub meta {
207219µs210µ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
no strict "refs";
# spent 7µs making 1 call to Type::Library::BEGIN@207 # spent 3µs making 1 call to strict::unimport
2082126µs247µ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
no warnings "once";
# spent 26µs making 1 call to Type::Library::BEGIN@208 # spent 21µs making 1 call to warnings::unimport
209295786µs295175µs return $_[0] if blessed $_[0];
# spent 175µs making 295 calls to Scalar::Util::blessed, avg 593ns/call
210163295µ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
sub add_type {
2143746µs37142µs my $meta = shift->meta;
# spent 142µs making 37 calls to Type::Library::meta, avg 4µs/call
2153798µs3727µs my $class = blessed( $meta ) ;
# spent 27µs making 37 calls to Scalar::Util::blessed, avg 730ns/call
216
2173719µ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] ) :
22237338µs1112.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, @_ );
2243717µs my $name = $type->{name};
225
2263751µs37225µ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
2273744µs37171µ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
2283745µs37146µ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
229378µs $meta->{types} ||= {};
2303731µs $meta->{types}{$name} = $type;
231
232218µs210µ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
no strict "refs";
# spent 7µs making 1 call to Type::Library::BEGIN@232 # spent 3µs making 1 call to strict::unimport
2332646µs234µ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
no warnings "redefine", "prototype";
# spent 18µs making 1 call to Type::Library::BEGIN@233 # spent 16µs making 1 call to warnings::unimport
234
2353798µs3727.1ms for my $exportable ( @{ $type->exportables } ) {
# spent 27.1ms making 37 calls to Type::Tiny::exportables, avg 732µs/call
23614844µs my $name = $exportable->{name};
23714819µs my $code = $exportable->{code};
23814822µs my $tags = $exportable->{tags};
239148407µs148795µs *{"$class\::$name"} = set_subname( "$class\::$name", $code );
# spent 795µs making 148 calls to Eval::TypeTiny::set_subname, avg 5µs/call
24014899µs push @{"$class\::EXPORT_OK"}, $name;
241148200µs push @{ ${"$class\::EXPORT_TAGS"}{$_} ||= [] }, $name for @$tags;
242148442µ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 )
2473755µs : ( $Type::Registry::DELAYED{$class}{$name} = $type );
248
24937145µ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
sub get_type {
2531125µ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 242µs (130+112) within Type::Library::has_type which was called 40 times, avg 6µs/call: # 37 times (120µs+105µs) by Type::Library::add_type at line 226, avg 6µs/call # 3 times (10µs+7µs) by Type::Library::add_coercion at line 278, avg 6µs/call
sub has_type {
2584026µs40112µs my $meta = shift->meta;
# spent 112µs making 40 calls to Type::Library::meta, avg 3µs/call
2594090µs exists $meta->{types}{ $_[0] };
260}
261
262sub 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
sub add_coercion {
26832µs38µs my $meta = shift->meta;
# spent 8µs making 3 calls to Type::Library::meta, avg 3µs/call
26937µs31µs my $class = blessed( $meta );
# spent 1µs making 3 calls to Scalar::Util::blessed, avg 333ns/call
270
27133µs _croak( 'Type library is immutable' ) if $meta->{immutable};
272
27332µs require Type::Coercion;
274314µs6308µ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
27533µs32µs my $name = $c->name;
# spent 2µs making 3 calls to Type::Coercion::name, avg 667ns/call
276
27736µs315µ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
27835µs317µ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
27933µ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
28131µs $meta->{coercions} ||= {};
28233µs $meta->{coercions}{$name} = $c;
283
284237µs227µ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
no strict "refs";
# spent 19µs making 1 call to Type::Library::BEGIN@284 # spent 8µs making 1 call to strict::unimport
2852208µs244µ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
no warnings "redefine", "prototype";
# spent 25µs making 1 call to Type::Library::BEGIN@285 # spent 19µs making 1 call to warnings::unimport
286
287311µs3711µs *{"$class\::$name"} = type_to_coderef( $c );
# spent 711µs making 3 calls to Eval::TypeTiny::type_to_coderef, avg 237µs/call
28834µs push @{"$class\::EXPORT_OK"}, $name;
28934µs push @{ ${"$class\::EXPORT_TAGS"}{'coercions'} ||= [] }, $name;
290320µs $meta->{'functions'}{$name} = { coercion => $c, tags => [ 'coercions' ] };
291
292311µs return $c;
293} #/ sub add_coercion
294
295sub get_coercion {
296 my $meta = shift->meta;
297 $meta->{coercions}{ $_[0] };
298}
299
300
# spent 186µs (106+80) within Type::Library::has_coercion which was called 40 times, avg 5µs/call: # 37 times (99µs+72µs) by Type::Library::add_type at line 227, avg 5µs/call # 3 times (7µs+8µs) by Type::Library::add_coercion at line 277, avg 5µs/call
sub has_coercion {
3014029µs4080µs my $meta = shift->meta;
# spent 80µs making 40 calls to Type::Library::meta, avg 2µs/call
3024072µs exists $meta->{coercions}{ $_[0] };
303}
304
305sub 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
sub make_immutable {
31111µs13µs my $meta = shift->meta;
# spent 3µs making 1 call to Type::Library::meta
31211µs my $class = ref( $meta );
313
314234µs215µ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
no strict "refs";
# spent 12µs making 1 call to Type::Library::BEGIN@314 # spent 3µs making 1 call to strict::unimport
3152166µs238µ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
no warnings "redefine", "prototype";
# spent 23µs making 1 call to Type::Library::BEGIN@315 # spent 15µs making 1 call to warnings::unimport
316
317115µs for my $type ( values %{ $meta->{types} } ) {
3183777µs742.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
3193744µs39292µ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
32014µs1628µs for my $e ( $type->exportables_by_tag( 'to' ) ) {
# spent 628µs making 1 call to Type::Tiny::exportables_by_tag
32111µs my $qualified_name = $class . '::' . $e->{name};
322114µs112µs *$qualified_name = set_subname( $qualified_name, $e->{code} );
# spent 12µs making 1 call to Eval::TypeTiny::set_subname
323 }
324 }
325
326118µs $meta->{immutable} = 1;
327}
328
32915µs1;
330
331__END__
 
# spent 29µs within Type::Library::CORE:match which was called 77 times, avg 377ns/call: # 40 times (15µs+0s) by Type::Library::_exporter_expand_sub at line 53, avg 375ns/call # 37 times (14µs+0s) by Type::Library::add_type at line 222, avg 378ns/call
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
sub Type::Library::CORE:subst; # opcode