Filename | /Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Type/Tiny/Duck.pm |
Statements | Executed 81 statements in 1.26ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 30µs | 30µs | BEGIN@3 | Type::Tiny::Duck::
4 | 1 | 1 | 20µs | 34µs | __ANON__[:104] | Type::Tiny::Duck::
1 | 1 | 1 | 16µs | 108µs | new | Type::Tiny::Duck::
4 | 1 | 1 | 14µs | 14µs | CORE:match (opcode) | Type::Tiny::Duck::
1 | 1 | 1 | 12µs | 19µs | BEGIN@19 | Type::Tiny::Duck::
1 | 1 | 1 | 10µs | 40µs | BEGIN@14 | Type::Tiny::Duck::
14 | 3 | 1 | 7µs | 7µs | _is_null_constraint | Type::Tiny::Duck::
1 | 1 | 1 | 6µs | 8µs | BEGIN@4 | Type::Tiny::Duck::
1 | 1 | 1 | 6µs | 36µs | BEGIN@5 | Type::Tiny::Duck::
1 | 1 | 1 | 5µs | 7µs | _build_inlined | Type::Tiny::Duck::
4 | 1 | 1 | 5µs | 12µs | inlined | Type::Tiny::Duck::
1 | 1 | 1 | 4µs | 4µs | BEGIN@20 | Type::Tiny::Duck::
1 | 1 | 1 | 3µs | 3µs | BEGIN@7 | Type::Tiny::Duck::
9 | 1 | 1 | 3µs | 3µs | has_inlined | Type::Tiny::Duck::
1 | 1 | 1 | 2µs | 2µs | methods | Type::Tiny::Duck::
0 | 0 | 0 | 0s | 0s | __ANON__[:166] | Type::Tiny::Duck::
0 | 0 | 0 | 0s | 0s | __ANON__[:74] | Type::Tiny::Duck::
0 | 0 | 0 | 0s | 0s | _build_constraint | Type::Tiny::Duck::
0 | 0 | 0 | 0s | 0s | _croak | Type::Tiny::Duck::
0 | 0 | 0 | 0s | 0s | _exporter_fail | Type::Tiny::Duck::
0 | 0 | 0 | 0s | 0s | _instantiate_moose_type | Type::Tiny::Duck::
0 | 0 | 0 | 0s | 0s | _short_name | Type::Tiny::Duck::
0 | 0 | 0 | 0s | 0s | validate_explain | Type::Tiny::Duck::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | package Type::Tiny::Duck; | ||||
2 | |||||
3 | 2 | 47µs | 1 | 30µs | # spent 30µs within Type::Tiny::Duck::BEGIN@3 which was called:
# once (30µs+0s) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:1033] at line 3 # spent 30µs making 1 call to Type::Tiny::Duck::BEGIN@3 |
4 | 2 | 22µs | 2 | 10µs | # spent 8µs (6+2) within Type::Tiny::Duck::BEGIN@4 which was called:
# once (6µs+2µs) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:1033] at line 4 # spent 8µs making 1 call to Type::Tiny::Duck::BEGIN@4
# spent 2µs making 1 call to strict::import |
5 | 2 | 41µs | 2 | 66µs | # spent 36µs (6+30) within Type::Tiny::Duck::BEGIN@5 which was called:
# once (6µs+30µs) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:1033] at line 5 # spent 36µs making 1 call to Type::Tiny::Duck::BEGIN@5
# spent 30µ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 | ||||
8 | 1 | 1µs | $Type::Tiny::Duck::AUTHORITY = 'cpan:TOBYINK'; | ||
9 | 1 | 3µs | $Type::Tiny::Duck::VERSION = '2.000001'; | ||
10 | 1 | 35µs | 1 | 3µs | } # spent 3µs making 1 call to Type::Tiny::Duck::BEGIN@7 |
11 | |||||
12 | 1 | 2µs | $Type::Tiny::Duck::VERSION =~ tr/_//d; | ||
13 | |||||
14 | 2 | 58µs | 2 | 70µs | # spent 40µs (10+30) within Type::Tiny::Duck::BEGIN@14 which was called:
# once (10µs+30µs) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:1033] at line 14 # spent 40µs making 1 call to Type::Tiny::Duck::BEGIN@14
# spent 30µs making 1 call to Exporter::import |
15 | |||||
16 | sub _croak ($;@) { require Error::TypeTiny; goto \&Error::TypeTiny::croak } | ||||
17 | |||||
18 | |||||
19 | 3 | 34µs | 2 | 26µs | # spent 19µs (12+7) within Type::Tiny::Duck::BEGIN@19 which was called:
# once (12µs+7µs) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:1033] at line 19 # spent 19µs making 1 call to Type::Tiny::Duck::BEGIN@19
# spent 7µs making 1 call to UNIVERSAL::VERSION |
20 | 2 | 892µs | 1 | 4µs | # spent 4µs within Type::Tiny::Duck::BEGIN@20 which was called:
# once (4µs+0s) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:1033] at line 20 # spent 4µs making 1 call to Type::Tiny::Duck::BEGIN@20 |
21 | 1 | 12µs | our @ISA = qw( Type::Tiny::ConstrainedObject Exporter::Tiny ); | ||
22 | |||||
23 | sub _short_name { 'Duck' } | ||||
24 | |||||
25 | sub _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 108µs (16+92) within Type::Tiny::Duck::new which was called:
# once (16µs+92µ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 | ||||
40 | 1 | 1µs | my $proto = shift; | ||
41 | |||||
42 | 1 | 2µs | my %opts = ( @_ == 1 ) ? %{ $_[0] } : @_; | ||
43 | 1 | 0s | _croak "Need to supply list of methods" unless exists $opts{methods}; | ||
44 | |||||
45 | 1 | 0s | $opts{methods} = [ $opts{methods} ] unless ref $opts{methods}; | ||
46 | |||||
47 | 1 | 2µs | 1 | 1µs | if ( Type::Tiny::_USE_XS ) { # spent 1µ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 | |||||
58 | 1 | 8µs | 1 | 91µs | return $proto->SUPER::new( %opts ); # spent 91µs making 1 call to Type::Tiny::ConstrainedObject::new |
59 | } #/ sub new | ||||
60 | |||||
61 | 1 | 3µ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 | ||
62 | 4 | 9µs | 1 | 7µs | # spent 12µs (5+7) within Type::Tiny::Duck::inlined which was called 4 times, avg 3µs/call:
# 4 times (5µs+7µs) by Type::Tiny::inline_check at line 895 of Type/Tiny.pm, avg 3µs/call # spent 7µs making 1 call to Type::Tiny::Duck::_build_inlined |
63 | |||||
64 | 9 | 13µs | # spent 3µs within Type::Tiny::Duck::has_inlined which was called 9 times, avg 333ns/call:
# 9 times (3µs+0s) by Type::Tiny::can_be_inlined at line 881 of Type/Tiny.pm, avg 333ns/call | ||
65 | |||||
66 | 14 | 22µs | # spent 7µs within Type::Tiny::Duck::_is_null_constraint which was called 14 times, avg 500ns/call:
# 9 times (4µs+0s) by Type::Tiny::can_be_inlined at line 877 of Type/Tiny.pm, avg 444ns/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 | ||
67 | |||||
68 | sub _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 7µs (5+2) within Type::Tiny::Duck::_build_inlined which was called:
# once (5µs+2µs) by Type::Tiny::Duck::inlined at line 62 | ||||
78 | 1 | 0s | my $self = shift; | ||
79 | 1 | 2µs | 1 | 2µs | my @methods = @{ $self->methods }; # spent 2µs making 1 call to Type::Tiny::Duck::methods |
80 | |||||
81 | 1 | 0s | 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 34µs (20+14) 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 8µs/call:
# 4 times (20µs+14µs) by Type::Tiny::inline_check at line 895 of Type/Tiny.pm, avg 8µs/call | ||||
88 | 4 | 0s | my $var = $_[1]; | ||
89 | 4 | 1µ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). | ||||
94 | 4 | 29µs | 4 | 14µs | my $code = # spent 14µs making 4 calls to Type::Tiny::Duck::CORE:match, avg 4µ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 | |||||
99 | 4 | 1µs | return qq{do { $Type::Tiny::SafePackage use Scalar::Util (); $code }} | ||
100 | if $Type::Tiny::AvoidCallbacks; | ||||
101 | 4 | 0s | return "$xsub\($var\)" | ||
102 | if $xsub; | ||||
103 | 4 | 8µs | $code; | ||
104 | 1 | 4µs | }; | ||
105 | } #/ sub _build_inlined | ||||
106 | |||||
107 | sub _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 | |||||
119 | sub 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 | |||||
140 | push @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; | ||||
166 | 1 | 3µs | }; | ||
167 | |||||
168 | 1 | 4µs | 1; | ||
169 | |||||
170 | __END__ | ||||
# spent 14µs within Type::Tiny::Duck::CORE:match which was called 4 times, avg 4µs/call:
# 4 times (14µ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 4µs/call |