| Filename | /Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Type/Library.pm |
| Statements | Executed 3557 statements in 7.18ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 7.44ms | 13.0ms | Type::Library::BEGIN@16 |
| 1 | 1 | 1 | 2.65ms | 3.00ms | Type::Library::BEGIN@14 |
| 37 | 18 | 1 | 1.54ms | 26.3ms | Type::Library::add_type |
| 40 | 1 | 1 | 545µs | 1.33ms | Type::Library::_exporter_expand_sub |
| 295 | 12 | 3 | 518µs | 638µs | Type::Library::meta |
| 40 | 1 | 1 | 391µs | 918µs | Type::Library::_exporter_install_sub |
| 1 | 1 | 1 | 278µs | 2.11ms | Type::Library::make_immutable |
| 40 | 2 | 1 | 79µs | 153µs | Type::Library::has_type |
| 40 | 2 | 1 | 67µs | 128µs | Type::Library::has_coercion |
| 3 | 3 | 1 | 65µs | 616µs | Type::Library::add_coercion |
| 8 | 1 | 1 | 58µs | 79µs | Type::Library::_exporter_validate_opts |
| 11 | 2 | 1 | 54µs | 96µs | Type::Library::get_type |
| 1 | 1 | 1 | 21µs | 21µs | Type::Library::BEGIN@3 |
| 77 | 2 | 1 | 16µs | 16µs | Type::Library::CORE:match (opcode) |
| 1 | 1 | 1 | 13µs | 21µs | Type::Library::BEGIN@188 |
| 1 | 1 | 1 | 11µs | 13µs | Type::Library::setup_type_library |
| 1 | 1 | 1 | 7µs | 12µs | Type::Library::BEGIN@284 |
| 1 | 1 | 1 | 6µs | 36µs | Type::Library::BEGIN@15 |
| 1 | 1 | 1 | 6µs | 28µs | Type::Library::BEGIN@208 |
| 1 | 1 | 1 | 6µs | 9µs | Type::Library::BEGIN@314 |
| 1 | 1 | 1 | 5µs | 8µs | Type::Library::BEGIN@207 |
| 1 | 1 | 1 | 5µs | 12µs | Type::Library::BEGIN@315 |
| 1 | 1 | 1 | 5µs | 9µs | Type::Library::BEGIN@4 |
| 1 | 1 | 1 | 5µs | 41µs | Type::Library::BEGIN@5 |
| 1 | 1 | 1 | 4µs | 8µs | Type::Library::BEGIN@232 |
| 1 | 1 | 1 | 4µs | 18µs | Type::Library::BEGIN@285 |
| 1 | 1 | 1 | 3µs | 3µs | Type::Library::BEGIN@17 |
| 1 | 1 | 1 | 3µs | 13µs | Type::Library::BEGIN@233 |
| 1 | 1 | 1 | 2µs | 2µs | Type::Library::CORE:subst (opcode) |
| 1 | 1 | 1 | 1µs | 1µs | Type::Library::BEGIN@7 |
| 0 | 0 | 0 | 0s | 0s | Type::Library::_croak |
| 0 | 0 | 0 | 0s | 0s | Type::Library::_exporter_fail |
| 0 | 0 | 0 | 0s | 0s | Type::Library::coercion_names |
| 0 | 0 | 0 | 0s | 0s | Type::Library::get_coercion |
| 0 | 0 | 0 | 0s | 0s | Type::Library::type_names |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Type::Library; | ||||
| 2 | |||||
| 3 | 2 | 34µs | 1 | 21µs | # spent 21µs within Type::Library::BEGIN@3 which was called:
# once (21µs+0s) by Types::Standard::BEGIN@19 at line 3 # spent 21µs making 1 call to Type::Library::BEGIN@3 |
| 4 | 2 | 25µs | 2 | 13µ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 # spent 9µs making 1 call to Type::Library::BEGIN@4
# spent 4µs making 1 call to strict::import |
| 5 | 2 | 29µs | 2 | 77µ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 # 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 | ||||
| 8 | 1 | 0s | $Type::Library::AUTHORITY = 'cpan:TOBYINK'; | ||
| 9 | 1 | 2µs | $Type::Library::VERSION = '2.000001'; | ||
| 10 | 1 | 26µs | 1 | 1µs | } # spent 1µs making 1 call to Type::Library::BEGIN@7 |
| 11 | |||||
| 12 | 1 | 1µs | $Type::Library::VERSION =~ tr/_//d; | ||
| 13 | |||||
| 14 | 2 | 1.01ms | 2 | 3.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 # spent 3.00ms making 1 call to Type::Library::BEGIN@14
# spent 286µs making 1 call to Eval::TypeTiny::import |
| 15 | 2 | 18µs | 2 | 66µ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 # spent 36µs making 1 call to Type::Library::BEGIN@15
# spent 30µs making 1 call to Exporter::import |
| 16 | 2 | 589µs | 1 | 13.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 # spent 13.0ms making 1 call to Type::Library::BEGIN@16 |
| 17 | 2 | 593µs | 1 | 3µs | # spent 3µs within Type::Library::BEGIN@17 which was called:
# once (3µs+0s) by Types::Standard::BEGIN@19 at line 17 # spent 3µs making 1 call to Type::Library::BEGIN@17 |
| 18 | |||||
| 19 | 1 | 1µs | require Exporter::Tiny; | ||
| 20 | 1 | 8µ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 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 | ||||
| 31 | 8 | 5µs | my ( $class, $opts ) = ( shift, @_ ); | ||
| 32 | |||||
| 33 | $class->setup_type_library( @{$opts}{qw/ into utils extends /} ) | ||||
| 34 | 8 | 11µs | 1 | 13µs | if $_[0]{base} || $_[0]{extends}; # spent 13µs making 1 call to Type::Library::setup_type_library |
| 35 | |||||
| 36 | 8 | 31µs | 8 | 8µ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 | ||||
| 45 | 40 | 9µs | my $class = shift; | ||
| 46 | 40 | 10µ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 | 54µs | 40 | 10µ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 | # | ||||
| 67 | 40 | 101µs | 80 | 154µ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 | |||||
| 70 | 40 | 7µs | my $type = $f->{type}; | ||
| 71 | 40 | 20µs | my $tag = $f->{tags}[0]; | ||
| 72 | 40 | 41µs | 40 | 43µ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 | # | ||||
| 77 | 40 | 1µs | my $custom_type = 0; | ||
| 78 | 40 | 21µs | for my $param ( qw/ of where / ) { | ||
| 79 | 80 | 13µ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 | 15µs | if ( $tag eq 'types' ) { | ||
| 91 | 40 | 9µs | my $post_method = q(); | ||
| 92 | 40 | 7µs | $post_method = '->mouse_type' if $globals->{mouse}; | ||
| 93 | 40 | 5µs | $post_method = '->moose_type' if $globals->{moose}; | ||
| 94 | 40 | 13µ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 | 13µ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 | 81µs | 40 | 578µ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 | ||||
| 120 | 40 | 7µs | my $class = shift; | ||
| 121 | 40 | 11µs | my ( $name, $value, $globals, $sym ) = @_; | ||
| 122 | |||||
| 123 | 40 | 15µs | my $into = $globals->{into}; | ||
| 124 | 40 | 26µs | 40 | 93µs | my $type = $class->meta->{'functions'}{$name}{'type'}; # spent 93µs making 40 calls to Type::Library::meta, avg 2µs/call |
| 125 | 40 | 28µs | 40 | 61µ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", | ||||
| 133 | 40 | 31µs | 40 | 36µ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 | # | ||||
| 138 | 40 | 31µ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 | 31µs | my ( $prefix ) = grep defined, $value->{-prefix}, $globals->{prefix}, q(); | ||
| 146 | 40 | 18µs | my ( $suffix ) = grep defined, $value->{-suffix}, $globals->{suffix}, q(); | ||
| 147 | 40 | 12µ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 | 29µs | : ( $Type::Registry::DELAYED{$into}{$as} = $type ); | ||
| 152 | } | ||||
| 153 | |||||
| 154 | 40 | 80µs | 40 | 337µ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 | |||||
| 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 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 | ||||
| 182 | 1 | 0s | my ( $class, $type_library, $install_utils, $extends ) = @_; | ||
| 183 | |||||
| 184 | 1 | 0s | my @extends = ref( $extends ) ? @$extends : $extends ? $extends : (); | ||
| 185 | 1 | 0s | unshift @extends, $class if $class ne __PACKAGE__; | ||
| 186 | |||||
| 187 | 1 | 0s | if ( not ref $type_library ) { | ||
| 188 | 2 | 116µs | 2 | 29µ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 # spent 21µs making 1 call to Type::Library::BEGIN@188
# spent 8µs making 1 call to strict::unimport |
| 189 | 1 | 6µs | push @{"$type_library\::ISA"}, $class; | ||
| 190 | 1 | 5µs | 1 | 2µs | ( my $file = $type_library ) =~ s{::}{/}g; # spent 2µ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 | 2µ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 | ||||
| 207 | 2 | 20µs | 2 | 11µ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 # spent 8µs making 1 call to Type::Library::BEGIN@207
# spent 3µs making 1 call to strict::unimport |
| 208 | 2 | 131µs | 2 | 50µ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 # spent 28µs making 1 call to Type::Library::BEGIN@208
# spent 22µs making 1 call to warnings::unimport |
| 209 | 295 | 578µs | 295 | 120µs | return $_[0] if blessed $_[0]; # spent 120µs making 295 calls to Scalar::Util::blessed, avg 407ns/call |
| 210 | 163 | 284µ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 | ||||
| 214 | 37 | 28µs | 37 | 107µs | my $meta = shift->meta; # spent 107µs making 37 calls to Type::Library::meta, avg 3µs/call |
| 215 | 37 | 57µs | 37 | 14µs | my $class = blessed( $meta ) ; # spent 14µs making 37 calls to Scalar::Util::blessed, avg 378ns/call |
| 216 | |||||
| 217 | 37 | 11µ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 | 179µs | 111 | 1.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, @_ ); | ||||
| 224 | 37 | 21µs | my $name = $type->{name}; | ||
| 225 | |||||
| 226 | 37 | 28µs | 37 | 143µ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 |
| 227 | 37 | 20µs | 37 | 116µ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 |
| 228 | 37 | 27µs | 37 | 90µ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 |
| 229 | 37 | 9µs | $meta->{types} ||= {}; | ||
| 230 | 37 | 21µs | $meta->{types}{$name} = $type; | ||
| 231 | |||||
| 232 | 2 | 22µs | 2 | 12µ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 # spent 8µs making 1 call to Type::Library::BEGIN@232
# spent 4µs making 1 call to strict::unimport |
| 233 | 2 | 665µs | 2 | 23µ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 # spent 13µs making 1 call to Type::Library::BEGIN@233
# spent 10µs making 1 call to warnings::unimport |
| 234 | |||||
| 235 | 37 | 77µs | 37 | 22.4ms | for my $exportable ( @{ $type->exportables } ) { # spent 22.4ms making 37 calls to Type::Tiny::exportables, avg 605µs/call |
| 236 | 148 | 32µs | my $name = $exportable->{name}; | ||
| 237 | 148 | 21µs | my $code = $exportable->{code}; | ||
| 238 | 148 | 18µs | my $tags = $exportable->{tags}; | ||
| 239 | 148 | 289µs | 148 | 560µs | *{"$class\::$name"} = set_subname( "$class\::$name", $code ); # spent 560µs making 148 calls to Eval::TypeTiny::set_subname, avg 4µs/call |
| 240 | 148 | 71µs | push @{"$class\::EXPORT_OK"}, $name; | ||
| 241 | 148 | 150µs | push @{ ${"$class\::EXPORT_TAGS"}{$_} ||= [] }, $name for @$tags; | ||
| 242 | 148 | 279µ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 | 24µs | : ( $Type::Registry::DELAYED{$class}{$name} = $type ); | ||
| 248 | |||||
| 249 | 37 | 73µ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 | ||||
| 253 | 11 | 18µs | 11 | 42µs | my $meta = shift->meta; # spent 42µs making 11 calls to Type::Library::meta, avg 4µs/call |
| 254 | 11 | 28µs | $meta->{types}{ $_[0] }; | ||
| 255 | } | ||||
| 256 | |||||
| 257 | sub has_type { | ||||
| 258 | 40 | 22µs | 40 | 74µs | my $meta = shift->meta; # spent 74µs making 40 calls to Type::Library::meta, avg 2µs/call |
| 259 | 40 | 57µs | exists $meta->{types}{ $_[0] }; | ||
| 260 | } | ||||
| 261 | |||||
| 262 | sub 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 | ||||
| 268 | 3 | 1µs | 3 | 5µs | my $meta = shift->meta; # spent 5µs making 3 calls to Type::Library::meta, avg 2µs/call |
| 269 | 3 | 4µs | 3 | 0s | my $class = blessed( $meta ); # spent 0s making 3 calls to Scalar::Util::blessed, avg 0s/call |
| 270 | |||||
| 271 | 3 | 1µs | _croak( 'Type library is immutable' ) if $meta->{immutable}; | ||
| 272 | |||||
| 273 | 3 | 3µs | require Type::Coercion; | ||
| 274 | 3 | 10µs | 6 | 195µ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 |
| 275 | 3 | 2µs | 3 | 1µs | my $name = $c->name; # spent 1µs making 3 calls to Type::Coercion::name, avg 333ns/call |
| 276 | |||||
| 277 | 3 | 3µs | 3 | 12µ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 |
| 278 | 3 | 1µs | 3 | 10µ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 |
| 279 | 3 | 2µs | 3 | 6µs | _croak( 'Cannot add anonymous type to a library' ) if $c->is_anon; # spent 6µs making 3 calls to Type::Coercion::is_anon, avg 2µs/call |
| 280 | |||||
| 281 | 3 | 1µs | $meta->{coercions} ||= {}; | ||
| 282 | 3 | 1µs | $meta->{coercions}{$name} = $c; | ||
| 283 | |||||
| 284 | 2 | 25µs | 2 | 17µ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 # spent 12µs making 1 call to Type::Library::BEGIN@284
# spent 5µs making 1 call to strict::unimport |
| 285 | 2 | 146µs | 2 | 32µ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 # spent 18µs making 1 call to Type::Library::BEGIN@285
# spent 14µs making 1 call to warnings::unimport |
| 286 | |||||
| 287 | 3 | 6µs | 3 | 322µs | *{"$class\::$name"} = type_to_coderef( $c ); # spent 322µs making 3 calls to Eval::TypeTiny::type_to_coderef, avg 107µs/call |
| 288 | 3 | 2µs | push @{"$class\::EXPORT_OK"}, $name; | ||
| 289 | 3 | 4µs | push @{ ${"$class\::EXPORT_TAGS"}{'coercions'} ||= [] }, $name; | ||
| 290 | 3 | 7µs | $meta->{'functions'}{$name} = { coercion => $c, tags => [ 'coercions' ] }; | ||
| 291 | |||||
| 292 | 3 | 6µ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 | 19µs | 40 | 61µs | my $meta = shift->meta; # spent 61µs making 40 calls to Type::Library::meta, avg 2µs/call |
| 302 | 40 | 52µs | exists $meta->{coercions}{ $_[0] }; | ||
| 303 | } | ||||
| 304 | |||||
| 305 | sub 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 | ||||
| 311 | 1 | 1µs | 1 | 2µs | my $meta = shift->meta; # spent 2µs making 1 call to Type::Library::meta |
| 312 | 1 | 1µs | my $class = ref( $meta ); | ||
| 313 | |||||
| 314 | 2 | 23µs | 2 | 12µ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 # spent 9µs making 1 call to Type::Library::BEGIN@314
# spent 3µs making 1 call to strict::unimport |
| 315 | 2 | 132µs | 2 | 19µ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 # spent 12µs making 1 call to Type::Library::BEGIN@315
# spent 7µs making 1 call to warnings::unimport |
| 316 | |||||
| 317 | 1 | 105µs | for my $type ( values %{ $meta->{types} } ) { | ||
| 318 | 37 | 43µs | 74 | 1.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 |
| 319 | 37 | 22µs | 39 | 147µ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 |
| 320 | 1 | 29µs | 1 | 537µs | for my $e ( $type->exportables_by_tag( 'to' ) ) { # spent 537µs making 1 call to Type::Tiny::exportables_by_tag |
| 321 | 1 | 1µs | my $qualified_name = $class . '::' . $e->{name}; | ||
| 322 | 1 | 6µs | 1 | 8µs | *$qualified_name = set_subname( $qualified_name, $e->{code} ); # spent 8µs making 1 call to Eval::TypeTiny::set_subname |
| 323 | } | ||||
| 324 | } | ||||
| 325 | |||||
| 326 | 1 | 7µs | $meta->{immutable} = 1; | ||
| 327 | } | ||||
| 328 | |||||
| 329 | 1 | 5µs | 1; | ||
| 330 | |||||
| 331 | __END__ | ||||
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 |