Filename | /Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard/ArrayRef.pm |
Statements | Executed 282 statements in 1.69ms |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
24 | 1 | 1 | 540µs | 3.14ms | __ANON__[:121] | Types::Standard::ArrayRef::
4 | 1 | 1 | 92µs | 2.57ms | __constraint_generator | Types::Standard::ArrayRef::
4 | 1 | 1 | 42µs | 91µs | __inline_generator | Types::Standard::ArrayRef::
1 | 1 | 1 | 38µs | 38µs | BEGIN@5 | Types::Standard::ArrayRef::
1 | 1 | 1 | 8µs | 25µs | BEGIN@22 | Types::Standard::ArrayRef::
1 | 1 | 1 | 6µs | 9µs | BEGIN@6 | Types::Standard::ArrayRef::
1 | 1 | 1 | 4µs | 4µs | BEGIN@16 | Types::Standard::ArrayRef::
1 | 1 | 1 | 4µs | 32µs | BEGIN@7 | Types::Standard::ArrayRef::
1 | 1 | 1 | 3µs | 3µs | BEGIN@17 | Types::Standard::ArrayRef::
1 | 1 | 1 | 3µs | 3µs | BEGIN@18 | Types::Standard::ArrayRef::
1 | 1 | 1 | 3µs | 3µs | BEGIN@9 | Types::Standard::ArrayRef::
0 | 0 | 0 | 0s | 0s | __ANON__[:186] | Types::Standard::ArrayRef::
0 | 0 | 0 | 0s | 0s | __ANON__[:199] | Types::Standard::ArrayRef::
0 | 0 | 0 | 0s | 0s | __ANON__[:58] | Types::Standard::ArrayRef::
0 | 0 | 0 | 0s | 0s | __ANON__[:67] | Types::Standard::ArrayRef::
0 | 0 | 0 | 0s | 0s | __ANON__[:75] | Types::Standard::ArrayRef::
0 | 0 | 0 | 0s | 0s | __ANON__[:84] | Types::Standard::ArrayRef::
0 | 0 | 0 | 0s | 0s | __coercion_generator | Types::Standard::ArrayRef::
0 | 0 | 0 | 0s | 0s | __deep_explanation | Types::Standard::ArrayRef::
0 | 0 | 0 | 0s | 0s | _croak | Types::Standard::ArrayRef::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # INTERNAL MODULE: guts for ArrayRef type from Types::Standard. | ||||
2 | |||||
3 | package Types::Standard::ArrayRef; | ||||
4 | |||||
5 | 2 | 48µs | 1 | 38µs | # spent 38µs within Types::Standard::ArrayRef::BEGIN@5 which was called:
# once (38µs+0s) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:190] at line 5 # spent 38µs making 1 call to Types::Standard::ArrayRef::BEGIN@5 |
6 | 2 | 24µs | 2 | 12µs | # spent 9µs (6+3) within Types::Standard::ArrayRef::BEGIN@6 which was called:
# once (6µs+3µs) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:190] at line 6 # spent 9µs making 1 call to Types::Standard::ArrayRef::BEGIN@6
# spent 3µs making 1 call to strict::import |
7 | 2 | 39µs | 2 | 60µs | # spent 32µs (4+28) within Types::Standard::ArrayRef::BEGIN@7 which was called:
# once (4µs+28µs) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:190] at line 7 # spent 32µs making 1 call to Types::Standard::ArrayRef::BEGIN@7
# spent 28µs making 1 call to warnings::import |
8 | |||||
9 | # spent 3µs within Types::Standard::ArrayRef::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::ArrayRef::AUTHORITY = 'cpan:TOBYINK'; | ||
11 | 1 | 2µs | $Types::Standard::ArrayRef::VERSION = '2.000001'; | ||
12 | 1 | 31µs | 1 | 3µs | } # spent 3µs making 1 call to Types::Standard::ArrayRef::BEGIN@9 |
13 | |||||
14 | 1 | 1µs | $Types::Standard::ArrayRef::VERSION =~ tr/_//d; | ||
15 | |||||
16 | 2 | 16µs | 1 | 4µs | # spent 4µs within Types::Standard::ArrayRef::BEGIN@16 which was called:
# once (4µs+0s) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:190] at line 16 # spent 4µs making 1 call to Types::Standard::ArrayRef::BEGIN@16 |
17 | 2 | 14µs | 1 | 3µs | # spent 3µs within Types::Standard::ArrayRef::BEGIN@17 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 17 # spent 3µs making 1 call to Types::Standard::ArrayRef::BEGIN@17 |
18 | 2 | 46µs | 1 | 3µs | # spent 3µs within Types::Standard::ArrayRef::BEGIN@18 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 18 # spent 3µs making 1 call to Types::Standard::ArrayRef::BEGIN@18 |
19 | |||||
20 | sub _croak ($;@) { require Error::TypeTiny; goto \&Error::TypeTiny::croak } | ||||
21 | |||||
22 | 2 | 960µs | 2 | 42µs | # spent 25µs (8+17) within Types::Standard::ArrayRef::BEGIN@22 which was called:
# once (8µs+17µs) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:190] at line 22 # spent 25µs making 1 call to Types::Standard::ArrayRef::BEGIN@22
# spent 17µs making 1 call to warnings::unimport |
23 | |||||
24 | # spent 2.57ms (92µs+2.48) within Types::Standard::ArrayRef::__constraint_generator which was called 4 times, avg 644µs/call:
# 4 times (92µs+2.48ms) by Type::Tiny::parameterize at line 1044 of Type/Tiny.pm, avg 644µs/call | ||||
25 | 4 | 1µs | return Types::Standard::ArrayRef unless @_; | ||
26 | |||||
27 | 4 | 3µs | my $param = shift; | ||
28 | 4 | 7µs | 4 | 61µs | Types::TypeTiny::is_TypeTiny( $param ) # spent 61µs making 4 calls to Types::TypeTiny::is_TypeTiny, avg 15µs/call |
29 | or _croak( | ||||
30 | "Parameter to ArrayRef[`a] expected to be a type constraint; got $param" ); | ||||
31 | |||||
32 | 4 | 3µs | my ( $min, $max ) = ( 0, -1 ); | ||
33 | 4 | 1µs | $min = Types::Standard::assert_Int( shift ) if @_; | ||
34 | 4 | 0s | $max = Types::Standard::assert_Int( shift ) if @_; | ||
35 | |||||
36 | 4 | 8µs | 4 | 505µs | my $param_compiled_check = $param->compiled_check; # spent 505µs making 4 calls to Type::Tiny::compiled_check, avg 126µs/call |
37 | 4 | 0s | my $xsub; | ||
38 | 4 | 11µs | 4 | 7µs | if ( Type::Tiny::_USE_XS and $min == 0 and $max == -1 ) { # spent 7µs making 4 calls to Type::Tiny::__ANON__[Type/Tiny.pm:55], avg 2µs/call |
39 | my $paramname = Type::Tiny::XS::is_known( $param_compiled_check ); | ||||
40 | $xsub = Type::Tiny::XS::get_coderef_for( "ArrayRef[$paramname]" ) | ||||
41 | if $paramname; | ||||
42 | } | ||||
43 | elsif ( Type::Tiny::_USE_MOUSE | ||||
44 | and $param->_has_xsub | ||||
45 | and $min == 0 | ||||
46 | and $max == -1 ) | ||||
47 | { | ||||
48 | require Mouse::Util::TypeConstraints; | ||||
49 | my $maker = "Mouse::Util::TypeConstraints"->can( "_parameterize_ArrayRef_for" ); | ||||
50 | $xsub = $maker->( $param ) if $maker; | ||||
51 | } | ||||
52 | |||||
53 | return ( | ||||
54 | sub { | ||||
55 | my $array = shift; | ||||
56 | $param->check( $_ ) || return for @$array; | ||||
57 | return !!1; | ||||
58 | }, | ||||
59 | 4 | 21µs | $xsub, | ||
60 | ) if $min == 0 and $max == -1; | ||||
61 | |||||
62 | return sub { | ||||
63 | my $array = shift; | ||||
64 | return if @$array < $min; | ||||
65 | $param->check( $_ ) || return for @$array; | ||||
66 | return !!1; | ||||
67 | } | ||||
68 | if $max == -1; | ||||
69 | |||||
70 | return sub { | ||||
71 | my $array = shift; | ||||
72 | return if @$array > $max; | ||||
73 | $param->check( $_ ) || return for @$array; | ||||
74 | return !!1; | ||||
75 | } | ||||
76 | if $min == 0; | ||||
77 | |||||
78 | return sub { | ||||
79 | my $array = shift; | ||||
80 | return if @$array < $min; | ||||
81 | return if @$array > $max; | ||||
82 | $param->check( $_ ) || return for @$array; | ||||
83 | return !!1; | ||||
84 | }; | ||||
85 | } #/ sub __constraint_generator | ||||
86 | |||||
87 | # spent 91µs (42+49) within Types::Standard::ArrayRef::__inline_generator which was called 4 times, avg 23µs/call:
# 4 times (42µs+49µs) by Type::Tiny::parameterize at line 1057 of Type/Tiny.pm, avg 23µs/call | ||||
88 | 4 | 1µs | my $param = shift; | ||
89 | 4 | 3µs | my ( $min, $max ) = ( 0, -1 ); | ||
90 | 4 | 0s | $min = shift if @_; | ||
91 | 4 | 2µs | $max = shift if @_; | ||
92 | |||||
93 | 4 | 6µs | 4 | 3µs | my $param_compiled_check = $param->compiled_check; # spent 3µs making 4 calls to Type::Tiny::compiled_check, avg 750ns/call |
94 | 4 | 1µs | my $xsubname; | ||
95 | if ( Type::Tiny::_USE_XS and $min == 0 and $max == -1 ) { | ||||
96 | my $paramname = Type::Tiny::XS::is_known( $param_compiled_check ); | ||||
97 | $xsubname = Type::Tiny::XS::get_subname_for( "ArrayRef[$paramname]" ); | ||||
98 | } | ||||
99 | |||||
100 | 4 | 6µs | 4 | 46µs | return unless $param->can_be_inlined; # spent 46µs making 4 calls to Type::Tiny::can_be_inlined, avg 12µs/call |
101 | |||||
102 | # spent 3.14ms (540µs+2.60) within Types::Standard::ArrayRef::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard/ArrayRef.pm:121] which was called 24 times, avg 131µs/call:
# 24 times (540µs+2.60ms) by Type::Tiny::inline_check at line 895 of Type/Tiny.pm, avg 131µs/call | ||||
103 | 24 | 21µs | my $v = $_[1]; | ||
104 | 24 | 13µs | return "$xsubname\($v\)" if $xsubname && !$Type::Tiny::AvoidCallbacks; | ||
105 | 24 | 105µs | 48 | 114µs | my $p = Types::Standard::ArrayRef->inline_check( $v ); # spent 114µs making 24 calls to Types::Standard::ArrayRef, avg 5µs/call
# spent 857µs making 24 calls to Type::Tiny::inline_check, avg 36µs/call, recursion: max depth 3, sum of overlapping time 857µs |
106 | |||||
107 | 24 | 19µs | if ( $min != 0 ) { | ||
108 | $p .= sprintf( ' and @{%s} >= %d', $v, $min ); | ||||
109 | } | ||||
110 | 24 | 9µs | if ( $max > 0 ) { | ||
111 | $p .= sprintf( ' and @{%s} <= %d', $v, $max ); | ||||
112 | } | ||||
113 | |||||
114 | 24 | 87µs | 24 | 0s | my $param_check = $param->inline_check( '$i' ); # spent 1.57ms making 24 calls to Type::Tiny::inline_check, avg 66µs/call, recursion: max depth 3, sum of overlapping time 1.57ms |
115 | 24 | 83µs | 24 | 52µs | return $p if $param->{uniq} eq Types::Standard::Any->{uniq}; # spent 52µs making 24 calls to Types::Standard::Any, avg 2µs/call |
116 | |||||
117 | 24 | 78µs | "$p and do { " | ||
118 | . "my \$ok = 1; " | ||||
119 | . "for my \$i (\@{$v}) { " | ||||
120 | . "(\$ok = 0, last) unless $param_check " . "}; " . "\$ok " . "}"; | ||||
121 | 4 | 17µs | }; | ||
122 | } #/ sub __inline_generator | ||||
123 | |||||
124 | sub __deep_explanation { | ||||
125 | my ( $type, $value, $varname ) = @_; | ||||
126 | my $param = $type->parameters->[0]; | ||||
127 | my ( $min, $max ) = ( 0, -1 ); | ||||
128 | $min = $type->parameters->[1] if @{ $type->parameters } > 1; | ||||
129 | $max = $type->parameters->[2] if @{ $type->parameters } > 2; | ||||
130 | |||||
131 | if ( $min != 0 and @$value < $min ) { | ||||
132 | return [ | ||||
133 | sprintf( '"%s" constrains array length at least %s', $type, $min ), | ||||
134 | sprintf( '@{%s} is %d', $varname, scalar @$value ), | ||||
135 | ]; | ||||
136 | } | ||||
137 | |||||
138 | if ( $max > 0 and @$value > $max ) { | ||||
139 | return [ | ||||
140 | sprintf( '"%s" constrains array length at most %d', $type, $max ), | ||||
141 | sprintf( '@{%s} is %d', $varname, scalar @$value ), | ||||
142 | ]; | ||||
143 | } | ||||
144 | |||||
145 | for my $i ( 0 .. $#$value ) { | ||||
146 | my $item = $value->[$i]; | ||||
147 | next if $param->check( $item ); | ||||
148 | return [ | ||||
149 | sprintf( '"%s" constrains each value in the array with "%s"', $type, $param ), | ||||
150 | @{ $param->validate_explain( $item, sprintf( '%s->[%d]', $varname, $i ) ) }, | ||||
151 | ]; | ||||
152 | } | ||||
153 | |||||
154 | # This should never happen... | ||||
155 | return; # uncoverable statement | ||||
156 | } #/ sub __deep_explanation | ||||
157 | |||||
158 | # XXX: min and max need to be handled by coercion? | ||||
159 | sub __coercion_generator { | ||||
160 | my ( $parent, $child, $param ) = @_; | ||||
161 | return unless $param->has_coercion; | ||||
162 | |||||
163 | my $coercable_item = $param->coercion->_source_type_union; | ||||
164 | my $C = "Type::Coercion"->new( type_constraint => $child ); | ||||
165 | |||||
166 | if ( $param->coercion->can_be_inlined and $coercable_item->can_be_inlined ) { | ||||
167 | $C->add_type_coercions( | ||||
168 | $parent => Types::Standard::Stringable { | ||||
169 | my @code; | ||||
170 | push @code, 'do { my ($orig, $return_orig, @new) = ($_, 0);'; | ||||
171 | push @code, 'for (@$orig) {'; | ||||
172 | push @code, | ||||
173 | sprintf( | ||||
174 | '++$return_orig && last unless (%s);', | ||||
175 | $coercable_item->inline_check( '$_' ) | ||||
176 | ); | ||||
177 | push @code, | ||||
178 | sprintf( | ||||
179 | 'push @new, (%s);', | ||||
180 | $param->coercion->inline_coercion( '$_' ) | ||||
181 | ); | ||||
182 | push @code, '}'; | ||||
183 | push @code, '$return_orig ? $orig : \\@new'; | ||||
184 | push @code, '}'; | ||||
185 | "@code"; | ||||
186 | } | ||||
187 | ); | ||||
188 | } #/ if ( $param->coercion->...) | ||||
189 | else { | ||||
190 | $C->add_type_coercions( | ||||
191 | $parent => sub { | ||||
192 | my $value = @_ ? $_[0] : $_; | ||||
193 | my @new; | ||||
194 | for my $item ( @$value ) { | ||||
195 | return $value unless $coercable_item->check( $item ); | ||||
196 | push @new, $param->coerce( $item ); | ||||
197 | } | ||||
198 | return \@new; | ||||
199 | }, | ||||
200 | ); | ||||
201 | } #/ else [ if ( $param->coercion->...)] | ||||
202 | |||||
203 | return $C; | ||||
204 | } #/ sub __coercion_generator | ||||
205 | |||||
206 | 1 | 4µs | 1; |