← Index
NYTProf Performance Profile   « line view »
For ../prof.pl
  Run on Wed Dec 14 15:57:08 2022
Reported on Wed Dec 14 16:00:35 2022

Filename/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Type/Tiny/Duck.pm
StatementsExecuted 81 statements in 1.60ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
11148µs48µsType::Tiny::Duck::::BEGIN@3Type::Tiny::Duck::BEGIN@3
41136µs47µsType::Tiny::Duck::::__ANON__[:104]Type::Tiny::Duck::__ANON__[:104]
11129µs179µsType::Tiny::Duck::::newType::Tiny::Duck::new
11111µs23µsType::Tiny::Duck::::BEGIN@19Type::Tiny::Duck::BEGIN@19
41111µs11µsType::Tiny::Duck::::CORE:matchType::Tiny::Duck::CORE:match (opcode)
41111µs23µsType::Tiny::Duck::::inlinedType::Tiny::Duck::inlined
11110µs14µsType::Tiny::Duck::::BEGIN@4Type::Tiny::Duck::BEGIN@4
11110µs12µsType::Tiny::Duck::::_build_inlinedType::Tiny::Duck::_build_inlined
1119µs49µsType::Tiny::Duck::::BEGIN@14Type::Tiny::Duck::BEGIN@14
14318µs8µsType::Tiny::Duck::::_is_null_constraintType::Tiny::Duck::_is_null_constraint
1117µs59µsType::Tiny::Duck::::BEGIN@5Type::Tiny::Duck::BEGIN@5
9117µs7µsType::Tiny::Duck::::has_inlinedType::Tiny::Duck::has_inlined
1113µs3µsType::Tiny::Duck::::BEGIN@20Type::Tiny::Duck::BEGIN@20
1113µs3µsType::Tiny::Duck::::BEGIN@7Type::Tiny::Duck::BEGIN@7
1112µs2µsType::Tiny::Duck::::methodsType::Tiny::Duck::methods
0000s0sType::Tiny::Duck::::__ANON__[:166]Type::Tiny::Duck::__ANON__[:166]
0000s0sType::Tiny::Duck::::__ANON__[:74]Type::Tiny::Duck::__ANON__[:74]
0000s0sType::Tiny::Duck::::_build_constraintType::Tiny::Duck::_build_constraint
0000s0sType::Tiny::Duck::::_croakType::Tiny::Duck::_croak
0000s0sType::Tiny::Duck::::_exporter_failType::Tiny::Duck::_exporter_fail
0000s0sType::Tiny::Duck::::_instantiate_moose_typeType::Tiny::Duck::_instantiate_moose_type
0000s0sType::Tiny::Duck::::_short_nameType::Tiny::Duck::_short_name
0000s0sType::Tiny::Duck::::validate_explainType::Tiny::Duck::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::Duck;
2
3255µs148µs
# spent 48µs within Type::Tiny::Duck::BEGIN@3 which was called: # once (48µs+0s) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:1033] at line 3
use 5.008001;
# spent 48µs making 1 call to Type::Tiny::Duck::BEGIN@3
4230µs218µs
# spent 14µs (10+4) within Type::Tiny::Duck::BEGIN@4 which was called: # once (10µs+4µs) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:1033] at line 4
use strict;
# spent 14µs making 1 call to Type::Tiny::Duck::BEGIN@4 # spent 4µs making 1 call to strict::import
5255µs2111µs
# spent 59µs (7+52) within Type::Tiny::Duck::BEGIN@5 which was called: # once (7µs+52µs) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:1033] at line 5
use warnings;
# spent 59µs making 1 call to Type::Tiny::Duck::BEGIN@5 # spent 52µs making 1 call to warnings::import
6
7
# spent 3µs within Type::Tiny::Duck::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:1033] at line 10
BEGIN {
810s $Type::Tiny::Duck::AUTHORITY = 'cpan:TOBYINK';
914µs $Type::Tiny::Duck::VERSION = '2.000001';
10153µs13µs}
# spent 3µs making 1 call to Type::Tiny::Duck::BEGIN@7
11
1212µs$Type::Tiny::Duck::VERSION =~ tr/_//d;
13
14255µs289µs
# spent 49µs (9+40) within Type::Tiny::Duck::BEGIN@14 which was called: # once (9µs+40µs) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:1033] at line 14
use Scalar::Util qw< blessed >;
# spent 49µs making 1 call to Type::Tiny::Duck::BEGIN@14 # spent 40µs making 1 call to Exporter::import
15
16sub _croak ($;@) { require Error::TypeTiny; goto \&Error::TypeTiny::croak }
17
18
19342µs235µs
# spent 23µs (11+12) within Type::Tiny::Duck::BEGIN@19 which was called: # once (11µs+12µs) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:1033] at line 19
use Exporter::Tiny 1.004001 ();
# spent 23µs making 1 call to Type::Tiny::Duck::BEGIN@19 # spent 12µs making 1 call to UNIVERSAL::VERSION
2021.14ms13µs
# spent 3µs within Type::Tiny::Duck::BEGIN@20 which was called: # once (3µs+0s) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:1033] at line 20
use Type::Tiny::ConstrainedObject ();
# spent 3µs making 1 call to Type::Tiny::Duck::BEGIN@20
21118µsour @ISA = qw( Type::Tiny::ConstrainedObject Exporter::Tiny );
22
23sub _short_name { 'Duck' }
24
25sub _exporter_fail {
26 my ( $class, $type_name, $methods, $globals ) = @_;
27 my $caller = $globals->{into};
28 my $type = $class->new(
29 name => $type_name,
30 methods => [ @$methods ],
31 );
32 $INC{'Type/Registry.pm'}
33 ? 'Type::Registry'->for_class( $caller )->add_type( $type, $type_name )
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 179µs (29+150) within Type::Tiny::Duck::new which was called: # once (29µs+150µs) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:1033] at line 1028 of Types/Standard.pm
sub new {
4010s my $proto = shift;
41
4213µs my %opts = ( @_ == 1 ) ? %{ $_[0] } : @_;
4311µs _croak "Need to supply list of methods" unless exists $opts{methods};
44
4511µs $opts{methods} = [ $opts{methods} ] unless ref $opts{methods};
46
4713µs14µs if ( Type::Tiny::_USE_XS ) {
# spent 4µs making 1 call to Type::Tiny::__ANON__[Type/Tiny.pm:55]
48 my $methods = join ",", sort( @{ $opts{methods} } );
49 my $xsub = Type::Tiny::XS::get_coderef_for( "HasMethods[$methods]" );
50 $opts{compiled_type_constraint} = $xsub if $xsub;
51 }
52 elsif ( Type::Tiny::_USE_MOUSE ) {
53 require Mouse::Util::TypeConstraints;
54 my $maker = "Mouse::Util::TypeConstraints"->can( "generate_can_predicate_for" );
55 $opts{compiled_type_constraint} = $maker->( $opts{methods} ) if $maker;
56 }
57
58117µs1146µs return $proto->SUPER::new( %opts );
# spent 146µs making 1 call to Type::Tiny::ConstrainedObject::new
59} #/ sub new
60
6114µs
# spent 2µs within Type::Tiny::Duck::methods which was called: # once (2µs+0s) by Type::Tiny::Duck::_build_inlined at line 79
sub methods { $_[0]{methods} }
62415µs112µs
# spent 23µs (11+12) within Type::Tiny::Duck::inlined which was called 4 times, avg 6µs/call: # 4 times (11µs+12µs) by Type::Tiny::inline_check at line 895 of Type/Tiny.pm, avg 6µs/call
sub inlined { $_[0]{inlined} ||= $_[0]->_build_inlined }
# spent 12µs making 1 call to Type::Tiny::Duck::_build_inlined
63
64911µs
# spent 7µs within Type::Tiny::Duck::has_inlined which was called 9 times, avg 778ns/call: # 9 times (7µs+0s) by Type::Tiny::can_be_inlined at line 881 of Type/Tiny.pm, avg 778ns/call
sub has_inlined { !!1 }
65
661421µs
# spent 8µs within Type::Tiny::Duck::_is_null_constraint which was called 14 times, avg 571ns/call: # 9 times (5µs+0s) by Type::Tiny::can_be_inlined at line 877 of Type/Tiny.pm, avg 556ns/call # 4 times (1µs+0s) by Type::Tiny::inline_check at line 889 of Type/Tiny.pm, avg 250ns/call # once (2µs+0s) by Type::Tiny::_build_compiled_check at line 532 of Type/Tiny.pm
sub _is_null_constraint { 0 }
67
68sub _build_constraint {
69 my $self = shift;
70 my @methods = @{ $self->methods };
71 return sub {
72 blessed( $_[0] )
73 and not grep( !$_[0]->can( $_ ), @methods );
74 };
75}
76
77
# spent 12µs (10+2) within Type::Tiny::Duck::_build_inlined which was called: # once (10µs+2µs) by Type::Tiny::Duck::inlined at line 62
sub _build_inlined {
7810s my $self = shift;
7913µs12µs my @methods = @{ $self->methods };
# spent 2µs making 1 call to Type::Tiny::Duck::methods
80
8111µs my $xsub;
82 if ( Type::Tiny::_USE_XS ) {
83 my $methods = join ",", sort( @{ $self->methods } );
84 $xsub = Type::Tiny::XS::get_subname_for( "HasMethods[$methods]" );
85 }
86
87
# spent 47µs (36+11) within Type::Tiny::Duck::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Type/Tiny/Duck.pm:104] which was called 4 times, avg 12µs/call: # 4 times (36µs+11µs) by Type::Tiny::inline_check at line 895 of Type/Tiny.pm, avg 12µs/call
sub {
8842µs my $var = $_[1];
8941µs local $" = q{ };
90
91 # If $var is $_ or $_->{foo} or $foo{$_} or somesuch, then we
92 # can't use it within the grep expression, so we need to save
93 # it into a temporary variable ($tmp).
94434µs411µs my $code =
# spent 11µs making 4 calls to Type::Tiny::Duck::CORE:match, avg 3µs/call
95 ( $var =~ /\$_/ )
96 ? qq{ Scalar::Util::blessed($var) and not do { my \$tmp = $var; grep(!\$tmp->can(\$_), qw/@methods/) } }
97 : qq{ Scalar::Util::blessed($var) and not grep(!$var->can(\$_), qw/@methods/) };
98
9941µs return qq{do { $Type::Tiny::SafePackage use Scalar::Util (); $code }}
100 if $Type::Tiny::AvoidCallbacks;
10142µs return "$xsub\($var\)"
102 if $xsub;
103410µs $code;
10416µs };
105} #/ sub _build_inlined
106
107sub _instantiate_moose_type {
108 my $self = shift;
109 my %opts = @_;
110 delete $opts{parent};
111 delete $opts{constraint};
112 delete $opts{inlined};
113
114 require Moose::Meta::TypeConstraint::DuckType;
115 return "Moose::Meta::TypeConstraint::DuckType"
116 ->new( %opts, methods => $self->methods );
117} #/ sub _instantiate_moose_type
118
119sub validate_explain {
120 my $self = shift;
121 my ( $value, $varname ) = @_;
122 $varname = '$_' unless defined $varname;
123
124 return undef if $self->check( $value );
125 return ["Not a blessed reference"] unless blessed( $value );
126
127 require Type::Utils;
128 return [
129 sprintf(
130 '"%s" requires that the reference can %s',
131 $self,
132 Type::Utils::english_list( map qq["$_"], @{ $self->methods } ),
133 ),
134 map sprintf( 'The reference cannot "%s"', $_ ),
135 grep !$value->can( $_ ),
136 @{ $self->methods }
137 ];
138} #/ sub validate_explain
139
140push @Type::Tiny::CMP, sub {
141 my $A = shift->find_constraining_type;
142 my $B = shift->find_constraining_type;
143 return Type::Tiny::CMP_UNKNOWN
144 unless $A->isa( __PACKAGE__ ) && $B->isa( __PACKAGE__ );
145
146 my %seen;
147 for my $word ( @{ $A->methods } ) {
148 $seen{$word} += 1;
149 }
150 for my $word ( @{ $B->methods } ) {
151 $seen{$word} += 2;
152 }
153
154 my $values = join( '', CORE::values %seen );
155 if ( $values =~ /^3*$/ ) {
156 return Type::Tiny::CMP_EQUIVALENT;
157 }
158 elsif ( $values !~ /2/ ) {
159 return Type::Tiny::CMP_SUBTYPE;
160 }
161 elsif ( $values !~ /1/ ) {
162 return Type::Tiny::CMP_SUPERTYPE;
163 }
164
165 return Type::Tiny::CMP_UNKNOWN;
16614µs};
167
16818µs1;
169
170__END__
 
# spent 11µs within Type::Tiny::Duck::CORE:match which was called 4 times, avg 3µs/call: # 4 times (11µs+0s) by Type::Tiny::Duck::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Type/Tiny/Duck.pm:104] at line 94, avg 3µs/call
sub Type::Tiny::Duck::CORE:match; # opcode