Filename | /Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard/HashRef.pm |
Statements | Executed 303 statements in 1.56ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
37 | 1 | 1 | 556µs | 21.9ms | __ANON__[:76] | Types::Standard::HashRef::
8 | 1 | 1 | 134µs | 11.0ms | __constraint_generator | Types::Standard::HashRef::
8 | 1 | 1 | 86µs | 229µs | __inline_generator | Types::Standard::HashRef::
1 | 1 | 1 | 43µs | 43µs | BEGIN@5 | Types::Standard::HashRef::
2 | 1 | 1 | 15µs | 714µs | __coercion_generator | Types::Standard::HashRef::
1 | 1 | 1 | 8µs | 28µs | BEGIN@22 | Types::Standard::HashRef::
1 | 1 | 1 | 7µs | 11µs | BEGIN@6 | Types::Standard::HashRef::
1 | 1 | 1 | 7µs | 46µs | BEGIN@7 | Types::Standard::HashRef::
1 | 1 | 1 | 5µs | 5µs | BEGIN@16 | Types::Standard::HashRef::
1 | 1 | 1 | 3µs | 3µs | BEGIN@9 | Types::Standard::HashRef::
1 | 1 | 1 | 2µs | 2µs | BEGIN@17 | Types::Standard::HashRef::
1 | 1 | 1 | 1µs | 1µs | BEGIN@18 | Types::Standard::HashRef::
0 | 0 | 0 | 0s | 0s | __ANON__[:128] | Types::Standard::HashRef::
0 | 0 | 0 | 0s | 0s | __ANON__[:141] | Types::Standard::HashRef::
0 | 0 | 0 | 0s | 0s | __ANON__[:161] | Types::Standard::HashRef::
0 | 0 | 0 | 0s | 0s | __ANON__[:50] | Types::Standard::HashRef::
0 | 0 | 0 | 0s | 0s | __deep_explanation | Types::Standard::HashRef::
0 | 0 | 0 | 0s | 0s | __hashref_allows_key | Types::Standard::HashRef::
0 | 0 | 0 | 0s | 0s | __hashref_allows_value | Types::Standard::HashRef::
0 | 0 | 0 | 0s | 0s | _croak | Types::Standard::HashRef::
0 | 0 | 0 | 0s | 0s | my_hashref_allows_key | Types::Standard::HashRef::
0 | 0 | 0 | 0s | 0s | my_hashref_allows_value | Types::Standard::HashRef::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # INTERNAL MODULE: guts for HashRef type from Types::Standard. | ||||
2 | |||||
3 | package Types::Standard::HashRef; | ||||
4 | |||||
5 | 2 | 55µs | 1 | 43µs | # spent 43µs within Types::Standard::HashRef::BEGIN@5 which was called:
# once (43µs+0s) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:190] at line 5 # spent 43µs making 1 call to Types::Standard::HashRef::BEGIN@5 |
6 | 2 | 28µs | 2 | 15µs | # spent 11µs (7+4) within Types::Standard::HashRef::BEGIN@6 which was called:
# once (7µs+4µs) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:190] at line 6 # spent 11µs making 1 call to Types::Standard::HashRef::BEGIN@6
# spent 4µs making 1 call to strict::import |
7 | 2 | 43µs | 2 | 85µs | # spent 46µs (7+39) within Types::Standard::HashRef::BEGIN@7 which was called:
# once (7µs+39µs) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:190] at line 7 # spent 46µs making 1 call to Types::Standard::HashRef::BEGIN@7
# spent 39µs making 1 call to warnings::import |
8 | |||||
9 | # spent 3µs within Types::Standard::HashRef::BEGIN@9 which was called:
# once (3µs+0s) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:190] at line 12 | ||||
10 | 1 | 0s | $Types::Standard::HashRef::AUTHORITY = 'cpan:TOBYINK'; | ||
11 | 1 | 4µs | $Types::Standard::HashRef::VERSION = '2.000001'; | ||
12 | 1 | 35µs | 1 | 3µs | } # spent 3µs making 1 call to Types::Standard::HashRef::BEGIN@9 |
13 | |||||
14 | 1 | 1µs | $Types::Standard::HashRef::VERSION =~ tr/_//d; | ||
15 | |||||
16 | 2 | 17µs | 1 | 5µs | # spent 5µs within Types::Standard::HashRef::BEGIN@16 which was called:
# once (5µs+0s) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:190] at line 16 # spent 5µs making 1 call to Types::Standard::HashRef::BEGIN@16 |
17 | 2 | 12µs | 1 | 2µs | # spent 2µs within Types::Standard::HashRef::BEGIN@17 which was called:
# once (2µs+0s) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:190] at line 17 # spent 2µs making 1 call to Types::Standard::HashRef::BEGIN@17 |
18 | 2 | 45µs | 1 | 1µs | # spent 1µs within Types::Standard::HashRef::BEGIN@18 which was called:
# once (1µs+0s) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:190] at line 18 # spent 1µs making 1 call to Types::Standard::HashRef::BEGIN@18 |
19 | |||||
20 | sub _croak ($;@) { require Error::TypeTiny; goto \&Error::TypeTiny::croak } | ||||
21 | |||||
22 | 2 | 827µs | 2 | 48µs | # spent 28µs (8+20) within Types::Standard::HashRef::BEGIN@22 which was called:
# once (8µs+20µs) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:190] at line 22 # spent 28µs making 1 call to Types::Standard::HashRef::BEGIN@22
# spent 20µs making 1 call to warnings::unimport |
23 | |||||
24 | # spent 11.0ms (134µs+10.8) within Types::Standard::HashRef::__constraint_generator which was called 8 times, avg 1.37ms/call:
# 8 times (134µs+10.8ms) by Type::Tiny::parameterize at line 1044 of Type/Tiny.pm, avg 1.37ms/call | ||||
25 | 8 | 5µs | return Types::Standard::HashRef unless @_; | ||
26 | |||||
27 | 8 | 1µs | my $param = shift; | ||
28 | 8 | 7µs | 8 | 109µs | Types::TypeTiny::is_TypeTiny( $param ) # spent 109µs making 8 calls to Types::TypeTiny::is_TypeTiny, avg 14µs/call |
29 | or _croak( | ||||
30 | "Parameter to HashRef[`a] expected to be a type constraint; got $param" ); | ||||
31 | |||||
32 | 8 | 12µs | 8 | 8.59ms | my $param_compiled_check = $param->compiled_check; # spent 8.59ms making 8 calls to Type::Tiny::compiled_check, avg 1.07ms/call |
33 | 8 | 1µs | my $xsub; | ||
34 | 8 | 23µs | 8 | 21µs | if ( Type::Tiny::_USE_XS ) { # spent 21µs making 8 calls to Type::Tiny::__ANON__[Type/Tiny.pm:55], avg 3µs/call |
35 | my $paramname = Type::Tiny::XS::is_known( $param_compiled_check ); | ||||
36 | $xsub = Type::Tiny::XS::get_coderef_for( "HashRef[$paramname]" ) | ||||
37 | if $paramname; | ||||
38 | } | ||||
39 | elsif ( Type::Tiny::_USE_MOUSE and $param->_has_xsub ) { | ||||
40 | require Mouse::Util::TypeConstraints; | ||||
41 | my $maker = "Mouse::Util::TypeConstraints"->can( "_parameterize_HashRef_for" ); | ||||
42 | $xsub = $maker->( $param ) if $maker; | ||||
43 | } | ||||
44 | |||||
45 | return ( | ||||
46 | sub { | ||||
47 | my $hash = shift; | ||||
48 | $param->check( $_ ) || return for values %$hash; | ||||
49 | return !!1; | ||||
50 | }, | ||||
51 | 8 | 43µs | $xsub, | ||
52 | ); | ||||
53 | } #/ sub __constraint_generator | ||||
54 | |||||
55 | # spent 229µs (86+143) within Types::Standard::HashRef::__inline_generator which was called 8 times, avg 29µs/call:
# 8 times (86µs+143µs) by Type::Tiny::parameterize at line 1057 of Type/Tiny.pm, avg 29µs/call | ||||
56 | 8 | 4µs | my $param = shift; | ||
57 | |||||
58 | 8 | 12µs | 8 | 7µs | my $compiled = $param->compiled_check; # spent 7µs making 8 calls to Type::Tiny::compiled_check, avg 875ns/call |
59 | 8 | 0s | my $xsubname; | ||
60 | if ( Type::Tiny::_USE_XS and not $Type::Tiny::AvoidCallbacks ) { | ||||
61 | my $paramname = Type::Tiny::XS::is_known( $compiled ); | ||||
62 | $xsubname = Type::Tiny::XS::get_subname_for( "HashRef[$paramname]" ); | ||||
63 | } | ||||
64 | |||||
65 | 8 | 12µs | 8 | 136µs | return unless $param->can_be_inlined; # spent 136µs making 8 calls to Type::Tiny::can_be_inlined, avg 17µs/call |
66 | # spent 21.9ms (556µs+21.3) within Types::Standard::HashRef::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard/HashRef.pm:76] which was called 37 times, avg 591µs/call:
# 37 times (556µs+21.3ms) by Type::Tiny::inline_check at line 895 of Type/Tiny.pm, avg 591µs/call | ||||
67 | 37 | 16µs | my $v = $_[1]; | ||
68 | 37 | 13µs | return "$xsubname\($v\)" if $xsubname && !$Type::Tiny::AvoidCallbacks; | ||
69 | 37 | 104µs | 74 | 104µs | my $p = Types::Standard::HashRef->inline_check( $v ); # spent 104µs making 37 calls to Types::Standard::HashRef, avg 3µs/call
# spent 1.21ms making 37 calls to Type::Tiny::inline_check, avg 33µs/call, recursion: max depth 2, sum of overlapping time 1.21ms |
70 | 37 | 44µs | 37 | 0s | my $param_check = $param->inline_check( '$i' ); # spent 20.0ms making 37 calls to Type::Tiny::inline_check, avg 540µs/call, recursion: max depth 2, sum of overlapping time 20.0ms |
71 | |||||
72 | 37 | 139µs | "$p and do { " | ||
73 | . "my \$ok = 1; " | ||||
74 | . "for my \$i (values \%{$v}) { " | ||||
75 | . "(\$ok = 0, last) unless $param_check " . "}; " . "\$ok " . "}"; | ||||
76 | 8 | 36µs | }; | ||
77 | } #/ sub __inline_generator | ||||
78 | |||||
79 | sub __deep_explanation { | ||||
80 | require B; | ||||
81 | my ( $type, $value, $varname ) = @_; | ||||
82 | my $param = $type->parameters->[0]; | ||||
83 | |||||
84 | for my $k ( sort keys %$value ) { | ||||
85 | my $item = $value->{$k}; | ||||
86 | next if $param->check( $item ); | ||||
87 | return [ | ||||
88 | sprintf( '"%s" constrains each value in the hash with "%s"', $type, $param ), | ||||
89 | @{ | ||||
90 | $param->validate_explain( | ||||
91 | $item, sprintf( '%s->{%s}', $varname, B::perlstring( $k ) ) | ||||
92 | ) | ||||
93 | }, | ||||
94 | ]; | ||||
95 | } #/ for my $k ( sort keys %$value) | ||||
96 | |||||
97 | # This should never happen... | ||||
98 | return; # uncoverable statement | ||||
99 | } #/ sub __deep_explanation | ||||
100 | |||||
101 | # spent 714µs (15+699) within Types::Standard::HashRef::__coercion_generator which was called 2 times, avg 357µs/call:
# 2 times (15µs+699µs) by Type::Tiny::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Type/Tiny.pm:1073] at line 1070 of Type/Tiny.pm, avg 357µs/call | ||||
102 | 2 | 2µs | my ( $parent, $child, $param ) = @_; | ||
103 | 2 | 13µs | 2 | 0s | return unless $param->has_coercion; # spent 699µs making 2 calls to Type::Tiny::has_coercion, avg 350µs/call, recursion: max depth 1, sum of overlapping time 699µs |
104 | |||||
105 | my $coercable_item = $param->coercion->_source_type_union; | ||||
106 | my $C = "Type::Coercion"->new( type_constraint => $child ); | ||||
107 | |||||
108 | if ( $param->coercion->can_be_inlined and $coercable_item->can_be_inlined ) { | ||||
109 | $C->add_type_coercions( | ||||
110 | $parent => Types::Standard::Stringable { | ||||
111 | my @code; | ||||
112 | push @code, 'do { my ($orig, $return_orig, %new) = ($_, 0);'; | ||||
113 | push @code, 'for (keys %$orig) {'; | ||||
114 | push @code, | ||||
115 | sprintf( | ||||
116 | '$return_orig++ && last unless (%s);', | ||||
117 | $coercable_item->inline_check( '$orig->{$_}' ) | ||||
118 | ); | ||||
119 | push @code, | ||||
120 | sprintf( | ||||
121 | '$new{$_} = (%s);', | ||||
122 | $param->coercion->inline_coercion( '$orig->{$_}' ) | ||||
123 | ); | ||||
124 | push @code, '}'; | ||||
125 | push @code, '$return_orig ? $orig : \\%new'; | ||||
126 | push @code, '}'; | ||||
127 | "@code"; | ||||
128 | } | ||||
129 | ); | ||||
130 | } #/ if ( $param->coercion->...) | ||||
131 | else { | ||||
132 | $C->add_type_coercions( | ||||
133 | $parent => sub { | ||||
134 | my $value = @_ ? $_[0] : $_; | ||||
135 | my %new; | ||||
136 | for my $k ( keys %$value ) { | ||||
137 | return $value unless $coercable_item->check( $value->{$k} ); | ||||
138 | $new{$k} = $param->coerce( $value->{$k} ); | ||||
139 | } | ||||
140 | return \%new; | ||||
141 | }, | ||||
142 | ); | ||||
143 | } #/ else [ if ( $param->coercion->...)] | ||||
144 | |||||
145 | return $C; | ||||
146 | } #/ sub __coercion_generator | ||||
147 | |||||
148 | sub __hashref_allows_key { | ||||
149 | my $self = shift; | ||||
150 | Types::Standard::is_Str( $_[0] ); | ||||
151 | } | ||||
152 | |||||
153 | sub __hashref_allows_value { | ||||
154 | my $self = shift; | ||||
155 | my ( $key, $value ) = @_; | ||||
156 | |||||
157 | return !!0 unless $self->my_hashref_allows_key( $key ); | ||||
158 | return !!1 if $self == Types::Standard::HashRef(); | ||||
159 | |||||
160 | my $href = $self->find_parent( | ||||
161 | sub { $_->has_parent && $_->parent == Types::Standard::HashRef() } ); | ||||
162 | my $param = $href->type_parameter; | ||||
163 | |||||
164 | Types::Standard::is_Str( $key ) and $param->check( $value ); | ||||
165 | } #/ sub __hashref_allows_value | ||||
166 | |||||
167 | 1 | 5µs | 1; |