← 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:03 2022

Filename/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Type/Tiny/Class.pm
StatementsExecuted 791 statements in 2.77ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
111988µs1.05msType::Tiny::Class::::BEGIN@19Type::Tiny::Class::BEGIN@19
8411157µs440µsType::Tiny::Class::::parentType::Tiny::Class::parent
5811155µs155µsType::Tiny::Class::::__ANON__[:89]Type::Tiny::Class::__ANON__[:89]
5811130µs192µsType::Tiny::Class::::inlinedType::Tiny::Class::inlined
102290µs537µsType::Tiny::Class::::newType::Tiny::Class::new
1613181µs81µsType::Tiny::Class::::_is_null_constraintType::Tiny::Class::_is_null_constraint
51176µs217µsType::Tiny::Class::::_build_parentType::Tiny::Class::_build_parent
71158µs62µsType::Tiny::Class::::_build_inlinedType::Tiny::Class::_build_inlined
961146µs46µsType::Tiny::Class::::has_inlinedType::Tiny::Class::has_inlined
11140µs40µsType::Tiny::Class::::BEGIN@3Type::Tiny::Class::BEGIN@3
11123µs49µsType::Tiny::Class::::BEGIN@5Type::Tiny::Class::BEGIN@5
11113µs21µsType::Tiny::Class::::BEGIN@18Type::Tiny::Class::BEGIN@18
11111µs14µsType::Tiny::Class::::BEGIN@4Type::Tiny::Class::BEGIN@4
1118µs22µsType::Tiny::Class::::BEGIN@93Type::Tiny::Class::BEGIN@93
1117µs32µsType::Tiny::Class::::BEGIN@14Type::Tiny::Class::BEGIN@14
12217µs7µsType::Tiny::Class::::classType::Tiny::Class::class
1116µs15µsType::Tiny::Class::::BEGIN@164Type::Tiny::Class::BEGIN@164
1115µs17µsType::Tiny::Class::::BEGIN@164.74Type::Tiny::Class::BEGIN@164.74
1113µs6µsType::Tiny::Class::::BEGIN@185Type::Tiny::Class::BEGIN@185
1113µs3µsType::Tiny::Class::::BEGIN@7Type::Tiny::Class::BEGIN@7
0000s0sType::Tiny::Class::::__ANON__[:105]Type::Tiny::Class::__ANON__[:105]
0000s0sType::Tiny::Class::::__ANON__[:201]Type::Tiny::Class::__ANON__[:201]
0000s0sType::Tiny::Class::::__ANON__[:70]Type::Tiny::Class::__ANON__[:70]
0000s0sType::Tiny::Class::::__ANON__[:99]Type::Tiny::Class::__ANON__[:99]
0000s0sType::Tiny::Class::::_build_constraintType::Tiny::Class::_build_constraint
0000s0sType::Tiny::Class::::_build_default_messageType::Tiny::Class::_build_default_message
0000s0sType::Tiny::Class::::_croakType::Tiny::Class::_croak
0000s0sType::Tiny::Class::::_exporter_failType::Tiny::Class::_exporter_fail
0000s0sType::Tiny::Class::::_instantiate_moose_typeType::Tiny::Class::_instantiate_moose_type
0000s0sType::Tiny::Class::::_short_nameType::Tiny::Class::_short_name
0000s0sType::Tiny::Class::::plus_constructorsType::Tiny::Class::plus_constructors
0000s0sType::Tiny::Class::::validate_explainType::Tiny::Class::validate_explain
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package Type::Tiny::Class;
2
3267µs140µs
# spent 40µs within Type::Tiny::Class::BEGIN@3 which was called: # once (40µs+0s) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:987] at line 3
use 5.008001;
# spent 40µs making 1 call to Type::Tiny::Class::BEGIN@3
4249µs217µs
# spent 14µs (11+3) within Type::Tiny::Class::BEGIN@4 which was called: # once (11µs+3µs) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:987] at line 4
use strict;
# spent 14µs making 1 call to Type::Tiny::Class::BEGIN@4 # spent 3µs making 1 call to strict::import
5243µs275µs
# spent 49µs (23+26) within Type::Tiny::Class::BEGIN@5 which was called: # once (23µs+26µs) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:987] at line 5
use warnings;
# spent 49µs making 1 call to Type::Tiny::Class::BEGIN@5 # spent 26µs making 1 call to warnings::import
6
7
# spent 3µs within Type::Tiny::Class::BEGIN@7 which was called: # once (3µs+0s) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:987] at line 10
BEGIN {
810s $Type::Tiny::Class::AUTHORITY = 'cpan:TOBYINK';
912µs $Type::Tiny::Class::VERSION = '2.000001';
10129µs13µs}
# spent 3µs making 1 call to Type::Tiny::Class::BEGIN@7
11
1210s$Type::Tiny::Class::VERSION =~ tr/_//d;
13
14241µs257µs
# spent 32µs (7+25) within Type::Tiny::Class::BEGIN@14 which was called: # once (7µs+25µs) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:987] at line 14
use Scalar::Util qw< blessed >;
# spent 32µs making 1 call to Type::Tiny::Class::BEGIN@14 # spent 25µs making 1 call to Exporter::import
15
16sub _croak ($;@) { require Error::TypeTiny; goto \&Error::TypeTiny::croak }
17
18330µs229µs
# spent 21µs (13+8) within Type::Tiny::Class::BEGIN@18 which was called: # once (13µs+8µs) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:987] at line 18
use Exporter::Tiny 1.004001 ();
# spent 21µs making 1 call to Type::Tiny::Class::BEGIN@18 # spent 8µs making 1 call to UNIVERSAL::VERSION
192861µs11.05ms
# spent 1.05ms (988µs+60µs) within Type::Tiny::Class::BEGIN@19 which was called: # once (988µs+60µs) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:987] at line 19
use Type::Tiny::ConstrainedObject ();
# spent 1.05ms making 1 call to Type::Tiny::Class::BEGIN@19
2019µsour @ISA = qw( Type::Tiny::ConstrainedObject Exporter::Tiny );
21
22sub _short_name { 'Class' }
23
24sub _exporter_fail {
25 my ( $class, $name, $opts, $globals ) = @_;
26 my $caller = $globals->{into};
27
28 $opts->{name} = $name unless exists $opts->{name}; $opts->{name} =~ s/:://g;
29 $opts->{class} = $name unless exists $opts->{class};
30 my $type = $class->new($opts);
31
32 $INC{'Type/Registry.pm'}
33 ? 'Type::Registry'->for_class( $caller )->add_type( $type )
34 : ( $Type::Registry::DELAYED{$caller}{$type->name} = $type )
35 unless( ref($caller) or $caller eq '-lexical' or $globals->{'lexical'} );
36 return map +( $_->{name} => $_->{code} ), @{ $type->exportables };
37}
38
39
# spent 537µs (90+447) within Type::Tiny::Class::new which was called 10 times, avg 54µs/call: # 7 times (68µs+337µs) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:987] at line 970 of Types/Standard.pm, avg 58µs/call # 3 times (22µs+110µs) by Type::Tiny::Class::_build_parent at line 171, avg 44µs/call
sub new {
40102µs my $proto = shift;
411018µs103µs return $proto->class->new( @_ ) if blessed $proto; # DWIM
# spent 3µs making 10 calls to Scalar::Util::blessed, avg 300ns/call
42
431014µs my %opts = ( @_ == 1 ) ? %{ $_[0] } : @_;
44104µs _croak "Need to supply class name" unless exists $opts{class};
45
461016µs1020µs if ( Type::Tiny::_USE_XS ) {
# spent 20µs making 10 calls to Type::Tiny::__ANON__[Type/Tiny.pm:55], avg 2µs/call
47 my $xsub =
48 Type::Tiny::XS::get_coderef_for( "InstanceOf[" . $opts{class} . "]" );
49 $opts{compiled_type_constraint} = $xsub if $xsub;
50 }
51 elsif ( Type::Tiny::_USE_MOUSE ) {
52 require Mouse::Util::TypeConstraints;
53 my $maker = "Mouse::Util::TypeConstraints"->can( "generate_isa_predicate_for" );
54 $opts{compiled_type_constraint} = $maker->( $opts{class} ) if $maker;
55 }
56
571036µs10424µs return $proto->SUPER::new( %opts );
# spent 424µs making 10 calls to Type::Tiny::ConstrainedObject::new, avg 42µs/call
58} #/ sub new
59
601219µs
# spent 7µs within Type::Tiny::Class::class which was called 12 times, avg 583ns/call: # 7 times (4µs+0s) by Type::Tiny::Class::_build_inlined at line 75, avg 571ns/call # 5 times (3µs+0s) by Type::Tiny::Class::_build_parent at line 154, avg 600ns/call
sub class { $_[0]{class} }
6158133µs762µs
# spent 192µs (130+62) within Type::Tiny::Class::inlined which was called 58 times, avg 3µs/call: # 58 times (130µs+62µs) by Type::Tiny::inline_check at line 895 of Type/Tiny.pm, avg 3µs/call
sub inlined { $_[0]{inlined} ||= $_[0]->_build_inlined }
# spent 62µs making 7 calls to Type::Tiny::Class::_build_inlined, avg 9µs/call
62
6396175µs
# spent 46µs within Type::Tiny::Class::has_inlined which was called 96 times, avg 479ns/call: # 96 times (46µs+0s) by Type::Tiny::can_be_inlined at line 881 of Type/Tiny.pm, avg 479ns/call
sub has_inlined { !!1 }
64
65161158µs
# spent 81µs within Type::Tiny::Class::_is_null_constraint which was called 161 times, avg 503ns/call: # 96 times (58µs+0s) by Type::Tiny::can_be_inlined at line 877 of Type/Tiny.pm, avg 604ns/call # 58 times (17µs+0s) by Type::Tiny::inline_check at line 889 of Type/Tiny.pm, avg 293ns/call # 7 times (6µs+0s) by Type::Tiny::_build_compiled_check at line 532 of Type/Tiny.pm, avg 857ns/call
sub _is_null_constraint { 0 }
66
67sub _build_constraint {
68 my $self = shift;
69 my $class = $self->class;
70 return sub { blessed( $_ ) and $_->isa( $class ) };
71}
72
73
# spent 62µs (58+4) within Type::Tiny::Class::_build_inlined which was called 7 times, avg 9µs/call: # 7 times (58µs+4µs) by Type::Tiny::Class::inlined at line 61, avg 9µs/call
sub _build_inlined {
7472µs my $self = shift;
7578µs74µs my $class = $self->class;
# spent 4µs making 7 calls to Type::Tiny::Class::class, avg 571ns/call
76
7772µs my $xsub;
78 $xsub = Type::Tiny::XS::get_subname_for( "InstanceOf[$class]" )
79 if Type::Tiny::_USE_XS;
80
81
# spent 155µs within Type::Tiny::Class::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Type/Tiny/Class.pm:89] which was called 58 times, avg 3µs/call: # 58 times (155µs+0s) by Type::Tiny::inline_check at line 895 of Type/Tiny.pm, avg 3µs/call
sub {
825832µs my $var = $_[1];
83 return
845811µs qq{do { use Scalar::Util (); Scalar::Util::blessed($var) and $var->isa(q[$class]) }}
85 if $Type::Tiny::AvoidCallbacks;
865816µs return "$xsub\($var\)"
87 if $xsub;
8858148µs qq{Scalar::Util::blessed($var) and $var->isa(q[$class])};
89743µs };
90} #/ sub _build_inlined
91
92sub _build_default_message {
932253µs236µs
# spent 22µs (8+14) within Type::Tiny::Class::BEGIN@93 which was called: # once (8µs+14µs) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:987] at line 93
no warnings 'uninitialized';
# spent 22µs making 1 call to Type::Tiny::Class::BEGIN@93 # spent 14µs making 1 call to warnings::unimport
94 my $self = shift;
95 my $c = $self->class;
96 return sub {
97 sprintf '%s did not pass type constraint (not isa %s)',
98 Type::Tiny::_dd( $_[0] ), $c;
99 }
100 if $self->is_anon;
101 my $name = "$self";
102 return sub {
103 sprintf '%s did not pass type constraint "%s" (not isa %s)',
104 Type::Tiny::_dd( $_[0] ), $name, $c;
105 };
106} #/ sub _build_default_message
107
108sub _instantiate_moose_type {
109 my $self = shift;
110 my %opts = @_;
111 delete $opts{parent};
112 delete $opts{constraint};
113 delete $opts{inlined};
114 require Moose::Meta::TypeConstraint::Class;
115 return "Moose::Meta::TypeConstraint::Class"
116 ->new( %opts, class => $self->class );
117} #/ sub _instantiate_moose_type
118
119sub plus_constructors {
120 my $self = shift;
121
122 unless ( @_ ) {
123 require Types::Standard;
124 push @_, Types::Standard::HashRef(), "new";
125 }
126
127 require B;
128 require Types::TypeTiny;
129
130 my $class = B::perlstring( $self->class );
131
132 my @r;
133 while ( @_ ) {
134 my $source = shift;
135 Types::TypeTiny::is_TypeTiny( $source )
136 or _croak "Expected type constraint; got $source";
137
138 my $constructor = shift;
139 Types::TypeTiny::is_StringLike( $constructor )
140 or _croak "Expected string; got $constructor";
141
142 push @r, $source, sprintf( '%s->%s($_)', $class, $constructor );
143 } #/ while ( @_ )
144
145 return $self->plus_coercions( \@r );
146} #/ sub plus_constructors
147
148
# spent 440µs (157+283) within Type::Tiny::Class::parent which was called 84 times, avg 5µs/call: # 84 times (157µs+283µs) by Type::Tiny::is_strictly_subtype_of at line 698 of Type/Tiny.pm, avg 5µs/call
sub parent {
14984188µs84283µs $_[0]{parent} ||= $_[0]->_build_parent;
# spent 217µs making 5 calls to Type::Tiny::Class::_build_parent, avg 43µs/call # spent 66µs making 79 calls to Type::Tiny::__ANON__[Type/Tiny.pm:101], avg 835ns/call
150}
151
152
# spent 217µs (76+141) within Type::Tiny::Class::_build_parent which was called 5 times, avg 43µs/call: # 5 times (76µs+141µs) by Type::Tiny::Class::parent at line 149, avg 43µs/call
sub _build_parent {
15351µs my $self = shift;
15455µs53µs my $class = $self->class;
# spent 3µs making 5 calls to Type::Tiny::Class::class, avg 600ns/call
155
156 # Some classes (I'm looking at you, Math::BigFloat) include a class in
157 # their @ISA to inherit methods, but then override isa() to return false,
158 # so that they don't appear to be a subclass.
159 #
160 # In these cases, we don't want to list the parent class as a parent
161 # type constraint.
162 #
163 my @isa = grep $class->isa( $_ ),
16414143µs754µs
# spent 15µs (6+9) within Type::Tiny::Class::BEGIN@164 which was called: # once (6µs+9µs) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:987] at line 164 # spent 17µs (5+12) within Type::Tiny::Class::BEGIN@164.74 which was called: # once (5µs+12µs) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:987] at line 164
do { no strict "refs"; no warnings; @{"$class\::ISA"} };
# spent 17µs making 1 call to Type::Tiny::Class::BEGIN@164.74 # spent 15µs making 1 call to Type::Tiny::Class::BEGIN@164 # spent 12µs making 1 call to warnings::unimport # spent 9µs making 1 call to strict::unimport # spent 1µs making 3 calls to UNIVERSAL::isa, avg 333ns/call
165
16652µs if ( @isa == 0 ) {
16723µs require Types::Standard;
168210µs25µs return Types::Standard::Object();
# spent 5µs making 2 calls to Types::Standard::Object, avg 2µs/call
169 }
170
171312µs3132µs if ( @isa == 1 ) {
# spent 132µs making 3 calls to Type::Tiny::Class::new, avg 44µs/call
172 return ref( $self )->new( class => $isa[0] );
173 }
174
175 require Type::Tiny::Intersection;
176 "Type::Tiny::Intersection"->new(
177 type_constraints => [ map ref( $self )->new( class => $_ ), @isa ],
178 );
179} #/ sub _build_parent
180
181*__get_linear_isa_dfs =
18211µs eval { require mro }
183 ? \&mro::get_linear_isa
184 : sub {
1852175µs29µs
# spent 6µs (3+3) within Type::Tiny::Class::BEGIN@185 which was called: # once (3µs+3µs) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:987] at line 185
no strict 'refs';
# spent 6µs making 1 call to Type::Tiny::Class::BEGIN@185 # spent 3µs making 1 call to strict::unimport
186
187 my $classname = shift;
188 my @lin = ( $classname );
189 my %stored;
190
191 foreach my $parent ( @{"$classname\::ISA"} ) {
192 my $plin = __get_linear_isa_dfs( $parent );
193 foreach ( @$plin ) {
194 next if exists $stored{$_};
195 push( @lin, $_ );
196 $stored{$_} = 1;
197 }
198 }
199
200 return \@lin;
20111µs };
202
203sub validate_explain {
204 my $self = shift;
205 my ( $value, $varname ) = @_;
206 $varname = '$_' unless defined $varname;
207
208 return undef if $self->check( $value );
209 return ["Not a blessed reference"] unless blessed( $value );
210
211 my @isa = @{ __get_linear_isa_dfs( ref $value ) };
212
213 my $display_var = $varname eq q{$_} ? '' : sprintf( ' (in %s)', $varname );
214
215 require Type::Utils;
216 return [
217 sprintf( '"%s" requires that the reference isa %s', $self, $self->class ),
218 sprintf(
219 'The reference%s isa %s', $display_var, Type::Utils::english_list( @isa )
220 ),
221 ];
222} #/ sub validate_explain
223
22415µs1;
225
226__END__