← Index
NYTProf Performance Profile   « line view »
For ../prof.pl
  Run on Thu Dec 15 15:23:56 2022
Reported on Thu Dec 15 15:27:02 2022

Filename/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Type/Library.pm
StatementsExecuted 3557 statements in 7.18ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1117.44ms13.0msType::Library::::BEGIN@16Type::Library::BEGIN@16
1112.65ms3.00msType::Library::::BEGIN@14Type::Library::BEGIN@14
371811.54ms26.3msType::Library::::add_typeType::Library::add_type
4011545µs1.33msType::Library::::_exporter_expand_subType::Library::_exporter_expand_sub
295123518µs638µsType::Library::::metaType::Library::meta
4011391µs918µsType::Library::::_exporter_install_subType::Library::_exporter_install_sub
111278µs2.11msType::Library::::make_immutableType::Library::make_immutable
402179µs153µsType::Library::::has_typeType::Library::has_type
402167µs128µsType::Library::::has_coercionType::Library::has_coercion
33165µs616µsType::Library::::add_coercionType::Library::add_coercion
81158µs79µsType::Library::::_exporter_validate_optsType::Library::_exporter_validate_opts
112154µs96µsType::Library::::get_typeType::Library::get_type
11121µs21µsType::Library::::BEGIN@3Type::Library::BEGIN@3
772116µs16µsType::Library::::CORE:matchType::Library::CORE:match (opcode)
11113µs21µsType::Library::::BEGIN@188Type::Library::BEGIN@188
11111µs13µsType::Library::::setup_type_libraryType::Library::setup_type_library
1117µs12µsType::Library::::BEGIN@284Type::Library::BEGIN@284
1116µs36µsType::Library::::BEGIN@15Type::Library::BEGIN@15
1116µs28µsType::Library::::BEGIN@208Type::Library::BEGIN@208
1116µs9µsType::Library::::BEGIN@314Type::Library::BEGIN@314
1115µs8µsType::Library::::BEGIN@207Type::Library::BEGIN@207
1115µs12µsType::Library::::BEGIN@315Type::Library::BEGIN@315
1115µs9µsType::Library::::BEGIN@4Type::Library::BEGIN@4
1115µs41µsType::Library::::BEGIN@5Type::Library::BEGIN@5
1114µs8µsType::Library::::BEGIN@232Type::Library::BEGIN@232
1114µs18µsType::Library::::BEGIN@285Type::Library::BEGIN@285
1113µs3µsType::Library::::BEGIN@17Type::Library::BEGIN@17
1113µs13µsType::Library::::BEGIN@233Type::Library::BEGIN@233
1112µs2µsType::Library::::CORE:substType::Library::CORE:subst (opcode)
1111µs1µ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
3234µs121µs
# spent 21µs within Type::Library::BEGIN@3 which was called: # once (21µs+0s) by Types::Standard::BEGIN@19 at line 3
use 5.008001;
# spent 21µs making 1 call to Type::Library::BEGIN@3
4225µs213µs
# spent 9µs (5+4) within Type::Library::BEGIN@4 which was called: # once (5µs+4µs) by Types::Standard::BEGIN@19 at line 4
use strict;
# spent 9µs making 1 call to Type::Library::BEGIN@4 # spent 4µs making 1 call to strict::import
5229µs277µs
# spent 41µs (5+36) within Type::Library::BEGIN@5 which was called: # once (5µs+36µs) by Types::Standard::BEGIN@19 at line 5
use warnings;
# spent 41µs making 1 call to Type::Library::BEGIN@5 # spent 36µs making 1 call to warnings::import
6
7
# spent 1µs within Type::Library::BEGIN@7 which was called: # once (1µs+0s) by Types::Standard::BEGIN@19 at line 10
BEGIN {
810s $Type::Library::AUTHORITY = 'cpan:TOBYINK';
912µs $Type::Library::VERSION = '2.000001';
10126µs11µs}
# spent 1µs making 1 call to Type::Library::BEGIN@7
11
1211µs$Type::Library::VERSION =~ tr/_//d;
13
1421.01ms23.29ms
# spent 3.00ms (2.65+352µs) within Type::Library::BEGIN@14 which was called: # once (2.65ms+352µs) by Types::Standard::BEGIN@19 at line 14
use Eval::TypeTiny qw< eval_closure set_subname type_to_coderef NICE_PROTOTYPES >;
# spent 3.00ms making 1 call to Type::Library::BEGIN@14 # spent 286µs making 1 call to Eval::TypeTiny::import
15218µs266µs
# spent 36µs (6+30) within Type::Library::BEGIN@15 which was called: # once (6µs+30µs) by Types::Standard::BEGIN@19 at line 15
use Scalar::Util qw< blessed refaddr >;
# spent 36µs making 1 call to Type::Library::BEGIN@15 # spent 30µs making 1 call to Exporter::import
162589µs113.0ms
# spent 13.0ms (7.44+5.55) within Type::Library::BEGIN@16 which was called: # once (7.44ms+5.55ms) by Types::Standard::BEGIN@19 at line 16
use Type::Tiny ();
# spent 13.0ms making 1 call to Type::Library::BEGIN@16
172593µs13µs
# spent 3µs within Type::Library::BEGIN@17 which was called: # once (3µs+0s) by Types::Standard::BEGIN@19 at line 17
use Types::TypeTiny ();
# spent 3µs making 1 call to Type::Library::BEGIN@17
18
1911µsrequire Exporter::Tiny;
2018µ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 79µs (58+21) within Type::Library::_exporter_validate_opts which was called 8 times, avg 10µs/call: # 8 times (58µs+21µs) by Exporter::Tiny::import at line 77 of Exporter/Tiny.pm, avg 10µs/call
sub _exporter_validate_opts {
3185µs my ( $class, $opts ) = ( shift, @_ );
32
33 $class->setup_type_library( @{$opts}{qw/ into utils extends /} )
34811µs113µs if $_[0]{base} || $_[0]{extends};
# spent 13µs making 1 call to Type::Library::setup_type_library
35
36831µs88µs return $class->SUPER::_exporter_validate_opts( @_ );
# spent 8µ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.33ms (545µs+785µs) within Type::Library::_exporter_expand_sub which was called 40 times, avg 33µs/call: # 40 times (545µs+785µs) by Exporter::Tiny::import at line 82 of Exporter/Tiny.pm, avg 33µs/call
sub _exporter_expand_sub {
45409µs my $class = shift;
464010µ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 #
534054µs4010µs if ( $name =~ /^\+(.+)/ and $class->has_type( "$1" ) ) {
# spent 10µs making 40 calls to Type::Library::CORE:match, avg 250ns/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 #
6740101µs80154µs if ( my $f = $class->meta->{'functions'}{$name}
# spent 154µs making 80 calls to Type::Library::meta, avg 2µs/call
68 and defined $class->meta->{'functions'}{$name}{'type'} ) {
69
70407µs my $type = $f->{type};
714020µs my $tag = $f->{tags}[0];
724041µs4043µs my $typename = $type->name;
# spent 43µ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 #
77401µs my $custom_type = 0;
784021µs for my $param ( qw/ of where / ) {
798013µ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 #
904015µs if ( $tag eq 'types' ) {
91409µs my $post_method = q();
92407µs $post_method = '->mouse_type' if $globals->{mouse};
93405µs $post_method = '->moose_type' if $globals->{moose};
944013µ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 #
1054013µ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 #
1134081µs40578µs return $class->SUPER::_exporter_expand_sub( @_ );
# spent 578µs making 40 calls to Exporter::Tiny::_exporter_expand_sub, avg 14µ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 918µs (391+527) within Type::Library::_exporter_install_sub which was called 40 times, avg 23µs/call: # 40 times (391µs+527µs) by Exporter::Tiny::import at line 84 of Exporter/Tiny.pm, avg 23µs/call
sub _exporter_install_sub {
120407µs my $class = shift;
1214011µs my ( $name, $value, $globals, $sym ) = @_;
122
1234015µs my $into = $globals->{into};
1244026µs4093µs my $type = $class->meta->{'functions'}{$name}{'type'};
# spent 93µs making 40 calls to Type::Library::meta, avg 2µs/call
1254028µs4061µs my $tags = $class->meta->{'functions'}{$name}{'tags'};
# spent 61µ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",
1334031µs4036µs ) if ( defined $type and $type->deprecated and not $globals->{allow_deprecated} );
# spent 36µs making 40 calls to Type::Tiny::deprecated, avg 900ns/call
134
135 # If exporting a type constraint into a real package, then
136 # add it to the package's type registry.
137 #
1384031µ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.
1454031µs my ( $prefix ) = grep defined, $value->{-prefix}, $globals->{prefix}, q();
1464018µs my ( $suffix ) = grep defined, $value->{-suffix}, $globals->{suffix}, q();
1474012µs my $as = $prefix . ( $value->{-as} || $name ) . $suffix;
148
149 $INC{'Type/Registry.pm'}
150 ? 'Type::Registry'->for_class( $into )->add_type( $type, $as )
1514029µs : ( $Type::Registry::DELAYED{$into}{$as} = $type );
152 }
153
1544080µs40337µs $class->SUPER::_exporter_install_sub( @_ );
# spent 337µs making 40 calls to Exporter::Tiny::_exporter_install_sub, avg 8µ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 13µs (11+2) within Type::Library::setup_type_library which was called: # once (11µs+2µ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 : ();
18510s unshift @extends, $class if $class ne __PACKAGE__;
186
18710s if ( not ref $type_library ) {
1882116µs229µs
# spent 21µs (13+8) within Type::Library::BEGIN@188 which was called: # once (13µs+8µs) by Types::Standard::BEGIN@19 at line 188
no strict "refs";
# spent 21µs making 1 call to Type::Library::BEGIN@188 # spent 8µs making 1 call to strict::unimport
18916µs push @{"$type_library\::ISA"}, $class;
19015µ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
19912µ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 638µs (518+120) within Type::Library::meta which was called 295 times, avg 2µs/call: # 80 times (135µs+19µs) by Type::Library::_exporter_expand_sub at line 67, avg 2µs/call # 40 times (84µs+9µs) by Type::Library::_exporter_install_sub at line 124, avg 2µs/call # 40 times (57µs+17µs) by Type::Library::has_type at line 258, avg 2µs/call # 40 times (55µs+6µs) by Type::Library::_exporter_install_sub at line 125, avg 2µs/call # 40 times (48µs+13µs) by Type::Library::has_coercion at line 301, avg 2µs/call # 37 times (69µs+38µs) by Type::Library::add_type at line 214, avg 3µs/call # 11 times (33µs+9µs) by Type::Library::get_type at line 253, avg 4µs/call # 3 times (4µs+1µs) by Type::Library::add_coercion at line 268, avg 2µs/call # once (13µs+6µs) by JSON::Schema::Modern::BEGIN@31 at line 144 of Types/Standard.pm # once (15µ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 (3µs+0s) by JSON::Schema::Modern::BEGIN@31 at line 1107 of Types/Standard.pm # once (2µs+0s) by Type::Library::make_immutable at line 311
sub meta {
207220µs211µs
# spent 8µs (5+3) within Type::Library::BEGIN@207 which was called: # once (5µs+3µs) by Types::Standard::BEGIN@19 at line 207
no strict "refs";
# spent 8µs making 1 call to Type::Library::BEGIN@207 # spent 3µs making 1 call to strict::unimport
2082131µs250µs
# spent 28µs (6+22) within Type::Library::BEGIN@208 which was called: # once (6µs+22µs) by Types::Standard::BEGIN@19 at line 208
no warnings "once";
# spent 28µs making 1 call to Type::Library::BEGIN@208 # spent 22µs making 1 call to warnings::unimport
209295578µs295120µs return $_[0] if blessed $_[0];
# spent 120µs making 295 calls to Scalar::Util::blessed, avg 407ns/call
210163284µs ${"$_[0]\::META"} ||= bless {}, $_[0];
211}
212
213
# spent 26.3ms (1.54+24.8) within Type::Library::add_type which was called 37 times, avg 711µs/call: # 20 times (828µs+16.3ms) 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 856µs/call # once (43µs+908µs) by JSON::Schema::Modern::BEGIN@31 at line 924 of Types/Standard.pm # once (55µs+774µs) by JSON::Schema::Modern::BEGIN@31 at line 957 of Types/Standard.pm # once (34µs+625µs) by JSON::Schema::Modern::BEGIN@31 at line 332 of Types/Standard.pm # once (38µs+533µs) by JSON::Schema::Modern::BEGIN@31 at line 1035 of Types/Standard.pm # once (36µs+522µs) by JSON::Schema::Modern::BEGIN@31 at line 1060 of Types/Standard.pm # once (93µs+447µs) by JSON::Schema::Modern::BEGIN@31 at line 887 of Types/Standard.pm # once (42µs+483µs) by JSON::Schema::Modern::BEGIN@31 at line 299 of Types/Standard.pm # once (37µs+472µs) by JSON::Schema::Modern::BEGIN@31 at line 883 of Types/Standard.pm # once (42µs+442µs) by JSON::Schema::Modern::BEGIN@31 at line 989 of Types/Standard.pm # once (35µs+440µs) by JSON::Schema::Modern::BEGIN@31 at line 364 of Types/Standard.pm # once (43µs+422µs) by JSON::Schema::Modern::BEGIN@31 at line 377 of Types/Standard.pm # once (46µs+414µs) by JSON::Schema::Modern::BEGIN@31 at line 706 of Types/Standard.pm # once (33µs+416µs) by JSON::Schema::Modern::BEGIN@31 at line 770 of Types/Standard.pm # once (36µs+400µs) by JSON::Schema::Modern::BEGIN@31 at line 1018 of Types/Standard.pm # once (33µs+400µs) by JSON::Schema::Modern::BEGIN@31 at line 827 of Types/Standard.pm # once (36µs+392µs) by JSON::Schema::Modern::BEGIN@31 at line 334 of Types/Standard.pm # once (33µs+392µs) by JSON::Schema::Modern::BEGIN@31 at line 802 of Types/Standard.pm
sub add_type {
2143728µs37107µs my $meta = shift->meta;
# spent 107µs making 37 calls to Type::Library::meta, avg 3µs/call
2153757µs3714µs my $class = blessed( $meta ) ;
# spent 14µs making 37 calls to Scalar::Util::blessed, avg 378ns/call
216
2173711µ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] ) :
22237179µs1111.38ms ref( $_[0] ) eq q(HASH) ? 'Type::Tiny'->new( library => $class, %{ $_[0] } ) :
# spent 1.37ms making 37 calls to Type::Tiny::new, avg 37µs/call # spent 6µs making 37 calls to Type::Library::CORE:match, avg 162ns/call # spent 5µs making 37 calls to Scalar::Util::blessed, avg 135ns/call
223 "Type::Tiny"->new( library => $class, @_ );
2243721µs my $name = $type->{name};
225
2263728µs37143µs _croak( 'Type %s already exists in this library', $name ) if $meta->has_type( $name );
# spent 143µs making 37 calls to Type::Library::has_type, avg 4µs/call
2273720µs37116µs _croak( 'Type %s conflicts with coercion of same name', $name ) if $meta->has_coercion( $name );
# spent 116µs making 37 calls to Type::Library::has_coercion, avg 3µs/call
2283727µs3790µs _croak( 'Cannot add anonymous type to a library' ) if $type->is_anon;
# spent 90µs making 37 calls to Type::Tiny::is_anon, avg 2µs/call
229379µs $meta->{types} ||= {};
2303721µs $meta->{types}{$name} = $type;
231
232222µs212µs
# spent 8µs (4+4) within Type::Library::BEGIN@232 which was called: # once (4µs+4µs) by Types::Standard::BEGIN@19 at line 232
no strict "refs";
# spent 8µs making 1 call to Type::Library::BEGIN@232 # spent 4µs making 1 call to strict::unimport
2332665µs223µs
# spent 13µs (3+10) within Type::Library::BEGIN@233 which was called: # once (3µs+10µs) by Types::Standard::BEGIN@19 at line 233
no warnings "redefine", "prototype";
# spent 13µs making 1 call to Type::Library::BEGIN@233 # spent 10µs making 1 call to warnings::unimport
234
2353777µs3722.4ms for my $exportable ( @{ $type->exportables } ) {
# spent 22.4ms making 37 calls to Type::Tiny::exportables, avg 605µs/call
23614832µs my $name = $exportable->{name};
23714821µs my $code = $exportable->{code};
23814818µs my $tags = $exportable->{tags};
239148289µs148560µs *{"$class\::$name"} = set_subname( "$class\::$name", $code );
# spent 560µs making 148 calls to Eval::TypeTiny::set_subname, avg 4µs/call
24014871µs push @{"$class\::EXPORT_OK"}, $name;
241148150µs push @{ ${"$class\::EXPORT_TAGS"}{$_} ||= [] }, $name for @$tags;
242148279µ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 )
2473724µs : ( $Type::Registry::DELAYED{$class}{$name} = $type );
248
2493773µs return $type;
250} #/ sub add_type
251
252
# spent 96µs (54+42) within Type::Library::get_type which was called 11 times, avg 9µs/call: # 10 times (51µs+39µ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 9µs/call # once (3µs+3µs) by JSON::Schema::Modern::BEGIN@31 at line 1064 of Types/Standard.pm
sub get_type {
2531118µs1142µs my $meta = shift->meta;
# spent 42µs making 11 calls to Type::Library::meta, avg 4µs/call
2541128µs $meta->{types}{ $_[0] };
255}
256
257
# spent 153µs (79+74) within Type::Library::has_type which was called 40 times, avg 4µs/call: # 37 times (74µs+69µs) by Type::Library::add_type at line 226, avg 4µs/call # 3 times (5µs+5µs) by Type::Library::add_coercion at line 278, avg 3µs/call
sub has_type {
2584022µs4074µs my $meta = shift->meta;
# spent 74µs making 40 calls to Type::Library::meta, avg 2µs/call
2594057µs exists $meta->{types}{ $_[0] };
260}
261
262sub type_names {
263 my $meta = shift->meta;
264 keys %{ $meta->{types} };
265}
266
267
# spent 616µs (65+551) within Type::Library::add_coercion which was called 3 times, avg 205µs/call: # once (33µs+270µs) by JSON::Schema::Modern::BEGIN@31 at line 1064 of Types/Standard.pm # once (16µs+151µs) by JSON::Schema::Modern::BEGIN@31 at line 1089 of Types/Standard.pm # once (16µs+130µs) by JSON::Schema::Modern::BEGIN@31 at line 1105 of Types/Standard.pm
sub add_coercion {
26831µs35µs my $meta = shift->meta;
# spent 5µs making 3 calls to Type::Library::meta, avg 2µs/call
26934µs30s my $class = blessed( $meta );
# spent 0s making 3 calls to Scalar::Util::blessed, avg 0s/call
270
27131µs _croak( 'Type library is immutable' ) if $meta->{immutable};
272
27333µs require Type::Coercion;
274310µs6195µs my $c = blessed( $_[0] ) ? $_[0] : "Type::Coercion"->new( @_ );
# spent 194µs making 3 calls to Type::Coercion::new, avg 65µs/call # spent 1µs making 3 calls to Scalar::Util::blessed, avg 333ns/call
27532µs31µs my $name = $c->name;
# spent 1µs making 3 calls to Type::Coercion::name, avg 333ns/call
276
27733µs312µs _croak( 'Coercion %s already exists in this library', $name ) if $meta->has_coercion( $name );
# spent 12µs making 3 calls to Type::Library::has_coercion, avg 4µs/call
27831µs310µs _croak( 'Coercion %s conflicts with type of same name', $name ) if $meta->has_type( $name );
# spent 10µs making 3 calls to Type::Library::has_type, avg 3µs/call
27932µ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} ||= {};
28231µs $meta->{coercions}{$name} = $c;
283
284225µs217µs
# spent 12µs (7+5) within Type::Library::BEGIN@284 which was called: # once (7µs+5µs) by Types::Standard::BEGIN@19 at line 284
no strict "refs";
# spent 12µs making 1 call to Type::Library::BEGIN@284 # spent 5µs making 1 call to strict::unimport
2852146µs232µs
# spent 18µs (4+14) within Type::Library::BEGIN@285 which was called: # once (4µs+14µs) by Types::Standard::BEGIN@19 at line 285
no warnings "redefine", "prototype";
# spent 18µs making 1 call to Type::Library::BEGIN@285 # spent 14µs making 1 call to warnings::unimport
286
28736µs3322µs *{"$class\::$name"} = type_to_coderef( $c );
# spent 322µs making 3 calls to Eval::TypeTiny::type_to_coderef, avg 107µs/call
28832µs push @{"$class\::EXPORT_OK"}, $name;
28934µs push @{ ${"$class\::EXPORT_TAGS"}{'coercions'} ||= [] }, $name;
29037µ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 128µs (67+61) within Type::Library::has_coercion which was called 40 times, avg 3µs/call: # 37 times (61µs+55µs) by Type::Library::add_type at line 227, avg 3µs/call # 3 times (6µs+6µs) by Type::Library::add_coercion at line 277, avg 4µs/call
sub has_coercion {
3014019µs4061µs my $meta = shift->meta;
# spent 61µs making 40 calls to Type::Library::meta, avg 2µs/call
3024052µs exists $meta->{coercions}{ $_[0] };
303}
304
305sub coercion_names {
306 my $meta = shift->meta;
307 keys %{ $meta->{coercions} };
308}
309
310
# spent 2.11ms (278µs+1.83) within Type::Library::make_immutable which was called: # once (278µs+1.83ms) by JSON::Schema::Modern::BEGIN@31 at line 1107 of Types/Standard.pm
sub make_immutable {
31111µs12µs my $meta = shift->meta;
# spent 2µs making 1 call to Type::Library::meta
31211µs my $class = ref( $meta );
313
314223µs212µs
# spent 9µs (6+3) within Type::Library::BEGIN@314 which was called: # once (6µs+3µs) by Types::Standard::BEGIN@19 at line 314
no strict "refs";
# spent 9µs making 1 call to Type::Library::BEGIN@314 # spent 3µs making 1 call to strict::unimport
3152132µs219µs
# spent 12µs (5+7) within Type::Library::BEGIN@315 which was called: # once (5µs+7µs) by Types::Standard::BEGIN@19 at line 315
no warnings "redefine", "prototype";
# spent 12µs making 1 call to Type::Library::BEGIN@315 # spent 7µs making 1 call to warnings::unimport
316
3171105µs for my $type ( values %{ $meta->{types} } ) {
3183743µs741.13ms $type->coercion->freeze;
# spent 1.08ms making 37 calls to Type::Tiny::coercion, avg 29µs/call # spent 58µs making 37 calls to Type::Coercion::freeze, avg 2µs/call
3193722µs39147µs next unless $type->has_coercion && $type->coercion->frozen;
# spent 139µs making 37 calls to Type::Tiny::has_coercion, avg 4µs/call # spent 6µs making 1 call to Type::Tiny::coercion # spent 2µs making 1 call to Type::Coercion::frozen
320129µs1537µs for my $e ( $type->exportables_by_tag( 'to' ) ) {
# spent 537µs making 1 call to Type::Tiny::exportables_by_tag
32111µs my $qualified_name = $class . '::' . $e->{name};
32216µs18µs *$qualified_name = set_subname( $qualified_name, $e->{code} );
# spent 8µs making 1 call to Eval::TypeTiny::set_subname
323 }
324 }
325
32617µs $meta->{immutable} = 1;
327}
328
32915µs1;
330
331__END__
 
# spent 16µs within Type::Library::CORE:match which was called 77 times, avg 208ns/call: # 40 times (10µs+0s) by Type::Library::_exporter_expand_sub at line 53, avg 250ns/call # 37 times (6µs+0s) by Type::Library::add_type at line 222, avg 162ns/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