Filename | /Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Type/Tiny/Class.pm |
Statements | Executed 801 statements in 3.42ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 1.23ms | 1.31ms | BEGIN@19 | Type::Tiny::Class::
59 | 1 | 1 | 237µs | 285µs | inlined | Type::Tiny::Class::
59 | 1 | 1 | 228µs | 228µs | __ANON__[:89] | Type::Tiny::Class::
84 | 1 | 1 | 220µs | 505µs | parent | Type::Tiny::Class::
10 | 2 | 2 | 125µs | 685µs | new | Type::Tiny::Class::
164 | 3 | 1 | 91µs | 91µs | _is_null_constraint | Type::Tiny::Class::
5 | 1 | 1 | 83µs | 232µs | _build_parent | Type::Tiny::Class::
98 | 1 | 1 | 58µs | 58µs | has_inlined | Type::Tiny::Class::
7 | 1 | 1 | 43µs | 48µs | _build_inlined | Type::Tiny::Class::
1 | 1 | 1 | 37µs | 37µs | BEGIN@3 | Type::Tiny::Class::
1 | 1 | 1 | 19µs | 26µs | BEGIN@18 | Type::Tiny::Class::
1 | 1 | 1 | 16µs | 19µs | BEGIN@185 | Type::Tiny::Class::
1 | 1 | 1 | 12µs | 39µs | BEGIN@14 | Type::Tiny::Class::
12 | 2 | 1 | 10µs | 10µs | class | Type::Tiny::Class::
1 | 1 | 1 | 9µs | 32µs | BEGIN@93 | Type::Tiny::Class::
1 | 1 | 1 | 8µs | 11µs | BEGIN@4 | Type::Tiny::Class::
1 | 1 | 1 | 7µs | 14µs | BEGIN@164 | Type::Tiny::Class::
1 | 1 | 1 | 6µs | 20µs | BEGIN@164.74 | Type::Tiny::Class::
1 | 1 | 1 | 5µs | 36µs | BEGIN@5 | Type::Tiny::Class::
1 | 1 | 1 | 2µs | 2µs | BEGIN@7 | Type::Tiny::Class::
0 | 0 | 0 | 0s | 0s | __ANON__[:105] | Type::Tiny::Class::
0 | 0 | 0 | 0s | 0s | __ANON__[:201] | Type::Tiny::Class::
0 | 0 | 0 | 0s | 0s | __ANON__[:70] | Type::Tiny::Class::
0 | 0 | 0 | 0s | 0s | __ANON__[:99] | Type::Tiny::Class::
0 | 0 | 0 | 0s | 0s | _build_constraint | Type::Tiny::Class::
0 | 0 | 0 | 0s | 0s | _build_default_message | Type::Tiny::Class::
0 | 0 | 0 | 0s | 0s | _croak | Type::Tiny::Class::
0 | 0 | 0 | 0s | 0s | _exporter_fail | Type::Tiny::Class::
0 | 0 | 0 | 0s | 0s | _instantiate_moose_type | Type::Tiny::Class::
0 | 0 | 0 | 0s | 0s | _short_name | Type::Tiny::Class::
0 | 0 | 0 | 0s | 0s | plus_constructors | Type::Tiny::Class::
0 | 0 | 0 | 0s | 0s | validate_explain | Type::Tiny::Class::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Type::Tiny::Class; | ||||
2 | |||||
3 | 2 | 55µs | 1 | 37µs | # spent 37µs within Type::Tiny::Class::BEGIN@3 which was called:
# once (37µs+0s) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:987] at line 3 # spent 37µs making 1 call to Type::Tiny::Class::BEGIN@3 |
4 | 2 | 26µs | 2 | 14µs | # spent 11µs (8+3) within Type::Tiny::Class::BEGIN@4 which was called:
# once (8µs+3µs) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:987] at line 4 # spent 11µs making 1 call to Type::Tiny::Class::BEGIN@4
# spent 3µs making 1 call to strict::import |
5 | 2 | 35µs | 2 | 67µs | # spent 36µs (5+31) within Type::Tiny::Class::BEGIN@5 which was called:
# once (5µs+31µs) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:987] at line 5 # spent 36µs making 1 call to Type::Tiny::Class::BEGIN@5
# spent 31µs making 1 call to warnings::import |
6 | |||||
7 | # spent 2µs within Type::Tiny::Class::BEGIN@7 which was called:
# once (2µs+0s) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:987] at line 10 | ||||
8 | 1 | 0s | $Type::Tiny::Class::AUTHORITY = 'cpan:TOBYINK'; | ||
9 | 1 | 4µs | $Type::Tiny::Class::VERSION = '2.000001'; | ||
10 | 1 | 45µs | 1 | 2µs | } # spent 2µs making 1 call to Type::Tiny::Class::BEGIN@7 |
11 | |||||
12 | 1 | 0s | $Type::Tiny::Class::VERSION =~ tr/_//d; | ||
13 | |||||
14 | 2 | 54µs | 2 | 66µs | # spent 39µs (12+27) within Type::Tiny::Class::BEGIN@14 which was called:
# once (12µs+27µs) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:987] at line 14 # spent 39µs making 1 call to Type::Tiny::Class::BEGIN@14
# spent 27µs making 1 call to Exporter::import |
15 | |||||
16 | sub _croak ($;@) { require Error::TypeTiny; goto \&Error::TypeTiny::croak } | ||||
17 | |||||
18 | 3 | 39µs | 2 | 33µs | # spent 26µs (19+7) within Type::Tiny::Class::BEGIN@18 which was called:
# once (19µs+7µs) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:987] at line 18 # spent 26µs making 1 call to Type::Tiny::Class::BEGIN@18
# spent 7µs making 1 call to UNIVERSAL::VERSION |
19 | 2 | 1.07ms | 1 | 1.31ms | # spent 1.31ms (1.23+84µs) within Type::Tiny::Class::BEGIN@19 which was called:
# once (1.23ms+84µs) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:987] at line 19 # spent 1.31ms making 1 call to Type::Tiny::Class::BEGIN@19 |
20 | 1 | 9µs | our @ISA = qw( Type::Tiny::ConstrainedObject Exporter::Tiny ); | ||
21 | |||||
22 | sub _short_name { 'Class' } | ||||
23 | |||||
24 | sub _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 685µs (125+560) within Type::Tiny::Class::new which was called 10 times, avg 68µs/call:
# 7 times (98µs+449µ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 78µs/call
# 3 times (27µs+111µs) by Type::Tiny::Class::_build_parent at line 171, avg 46µs/call | ||||
40 | 10 | 6µs | my $proto = shift; | ||
41 | 10 | 24µs | 10 | 5µs | return $proto->class->new( @_ ) if blessed $proto; # DWIM # spent 5µs making 10 calls to Scalar::Util::blessed, avg 500ns/call |
42 | |||||
43 | 10 | 20µs | my %opts = ( @_ == 1 ) ? %{ $_[0] } : @_; | ||
44 | 10 | 5µs | _croak "Need to supply class name" unless exists $opts{class}; | ||
45 | |||||
46 | 10 | 23µs | 10 | 16µs | if ( Type::Tiny::_USE_XS ) { # spent 16µ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 | |||||
57 | 10 | 48µs | 10 | 539µs | return $proto->SUPER::new( %opts ); # spent 539µs making 10 calls to Type::Tiny::ConstrainedObject::new, avg 54µs/call |
58 | } #/ sub new | ||||
59 | |||||
60 | 12 | 23µs | sub class { $_[0]{class} } | ||
61 | 59 | 262µs | 7 | 48µs | # spent 285µs (237+48) within Type::Tiny::Class::inlined which was called 59 times, avg 5µs/call:
# 59 times (237µs+48µs) by Type::Tiny::inline_check at line 895 of Type/Tiny.pm, avg 5µs/call # spent 48µs making 7 calls to Type::Tiny::Class::_build_inlined, avg 7µs/call |
62 | |||||
63 | 98 | 118µs | # spent 58µs within Type::Tiny::Class::has_inlined which was called 98 times, avg 592ns/call:
# 98 times (58µs+0s) by Type::Tiny::can_be_inlined at line 881 of Type/Tiny.pm, avg 592ns/call | ||
64 | |||||
65 | 164 | 222µs | # spent 91µs within Type::Tiny::Class::_is_null_constraint which was called 164 times, avg 555ns/call:
# 98 times (69µs+0s) by Type::Tiny::can_be_inlined at line 877 of Type/Tiny.pm, avg 704ns/call
# 59 times (19µs+0s) by Type::Tiny::inline_check at line 889 of Type/Tiny.pm, avg 322ns/call
# 7 times (3µs+0s) by Type::Tiny::_build_compiled_check at line 532 of Type/Tiny.pm, avg 429ns/call | ||
66 | |||||
67 | sub _build_constraint { | ||||
68 | my $self = shift; | ||||
69 | my $class = $self->class; | ||||
70 | return sub { blessed( $_ ) and $_->isa( $class ) }; | ||||
71 | } | ||||
72 | |||||
73 | # spent 48µs (43+5) within Type::Tiny::Class::_build_inlined which was called 7 times, avg 7µs/call:
# 7 times (43µs+5µs) by Type::Tiny::Class::inlined at line 61, avg 7µs/call | ||||
74 | 7 | 1µs | my $self = shift; | ||
75 | 7 | 11µs | 7 | 5µs | my $class = $self->class; # spent 5µs making 7 calls to Type::Tiny::Class::class, avg 714ns/call |
76 | |||||
77 | 7 | 1µs | my $xsub; | ||
78 | $xsub = Type::Tiny::XS::get_subname_for( "InstanceOf[$class]" ) | ||||
79 | if Type::Tiny::_USE_XS; | ||||
80 | |||||
81 | # spent 228µs within Type::Tiny::Class::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Type/Tiny/Class.pm:89] which was called 59 times, avg 4µs/call:
# 59 times (228µs+0s) by Type::Tiny::inline_check at line 895 of Type/Tiny.pm, avg 4µs/call | ||||
82 | 59 | 30µs | my $var = $_[1]; | ||
83 | return | ||||
84 | 59 | 14µs | qq{do { use Scalar::Util (); Scalar::Util::blessed($var) and $var->isa(q[$class]) }} | ||
85 | if $Type::Tiny::AvoidCallbacks; | ||||
86 | 59 | 34µs | return "$xsub\($var\)" | ||
87 | if $xsub; | ||||
88 | 59 | 189µs | qq{Scalar::Util::blessed($var) and $var->isa(q[$class])}; | ||
89 | 7 | 31µs | }; | ||
90 | } #/ sub _build_inlined | ||||
91 | |||||
92 | sub _build_default_message { | ||||
93 | 2 | 321µs | 2 | 55µs | # spent 32µs (9+23) within Type::Tiny::Class::BEGIN@93 which was called:
# once (9µs+23µs) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:987] at line 93 # spent 32µs making 1 call to Type::Tiny::Class::BEGIN@93
# spent 23µ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 | |||||
108 | sub _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 | |||||
119 | sub 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 505µs (220+285) within Type::Tiny::Class::parent which was called 84 times, avg 6µs/call:
# 84 times (220µs+285µs) by Type::Tiny::is_strictly_subtype_of at line 698 of Type/Tiny.pm, avg 6µs/call | ||||
149 | 84 | 215µs | 84 | 285µs | $_[0]{parent} ||= $_[0]->_build_parent; # spent 232µs making 5 calls to Type::Tiny::Class::_build_parent, avg 46µs/call
# spent 53µs making 79 calls to Type::Tiny::__ANON__[Type/Tiny.pm:101], avg 671ns/call |
150 | } | ||||
151 | |||||
152 | # spent 232µs (83+149) within Type::Tiny::Class::_build_parent which was called 5 times, avg 46µs/call:
# 5 times (83µs+149µs) by Type::Tiny::Class::parent at line 149, avg 46µs/call | ||||
153 | 5 | 1µs | my $self = shift; | ||
154 | 5 | 7µs | 5 | 5µs | my $class = $self->class; # spent 5µs making 5 calls to Type::Tiny::Class::class, avg 1µs/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( $_ ), | ||||
164 | 14 | 189µs | 7 | 57µs | # spent 20µs (6+14) within Type::Tiny::Class::BEGIN@164.74 which was called:
# once (6µs+14µs) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:987] at line 164
# spent 14µs (7+7) within Type::Tiny::Class::BEGIN@164 which was called:
# once (7µs+7µs) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:987] at line 164 # spent 20µs making 1 call to Type::Tiny::Class::BEGIN@164.74
# spent 14µs making 1 call to Type::Tiny::Class::BEGIN@164
# spent 14µs making 1 call to warnings::unimport
# spent 7µs making 1 call to strict::unimport
# spent 2µs making 3 calls to UNIVERSAL::isa, avg 667ns/call |
165 | |||||
166 | 5 | 2µs | if ( @isa == 0 ) { | ||
167 | 2 | 2µs | require Types::Standard; | ||
168 | 2 | 7µs | 2 | 4µs | return Types::Standard::Object(); # spent 4µs making 2 calls to Types::Standard::Object, avg 2µs/call |
169 | } | ||||
170 | |||||
171 | 3 | 13µs | 3 | 138µs | if ( @isa == 1 ) { # spent 138µs making 3 calls to Type::Tiny::Class::new, avg 46µ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 = | ||||
182 | 1 | 2µs | eval { require mro } | ||
183 | ? \&mro::get_linear_isa | ||||
184 | : sub { | ||||
185 | 2 | 252µs | 2 | 22µs | # spent 19µs (16+3) within Type::Tiny::Class::BEGIN@185 which was called:
# once (16µs+3µs) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:987] at line 185 # spent 19µ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; | ||||
201 | 1 | 1µs | }; | ||
202 | |||||
203 | sub 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 | |||||
224 | 1 | 5µs | 1; | ||
225 | |||||
226 | __END__ |