| Filename | /Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard/ArrayRef.pm |
| Statements | Executed 282 statements in 1.32ms |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 24 | 1 | 1 | 853µs | 2.91ms | Types::Standard::ArrayRef::__ANON__[:121] |
| 4 | 1 | 1 | 61µs | 2.23ms | Types::Standard::ArrayRef::__constraint_generator |
| 1 | 1 | 1 | 54µs | 54µs | Types::Standard::ArrayRef::BEGIN@5 |
| 4 | 1 | 1 | 32µs | 68µs | Types::Standard::ArrayRef::__inline_generator |
| 1 | 1 | 1 | 6µs | 15µs | Types::Standard::ArrayRef::BEGIN@22 |
| 1 | 1 | 1 | 6µs | 9µs | Types::Standard::ArrayRef::BEGIN@6 |
| 1 | 1 | 1 | 3µs | 3µs | Types::Standard::ArrayRef::BEGIN@16 |
| 1 | 1 | 1 | 3µs | 3µs | Types::Standard::ArrayRef::BEGIN@17 |
| 1 | 1 | 1 | 2µs | 30µs | Types::Standard::ArrayRef::BEGIN@7 |
| 1 | 1 | 1 | 1µs | 1µs | Types::Standard::ArrayRef::BEGIN@18 |
| 1 | 1 | 1 | 1µs | 1µs | Types::Standard::ArrayRef::BEGIN@9 |
| 0 | 0 | 0 | 0s | 0s | Types::Standard::ArrayRef::__ANON__[:186] |
| 0 | 0 | 0 | 0s | 0s | Types::Standard::ArrayRef::__ANON__[:199] |
| 0 | 0 | 0 | 0s | 0s | Types::Standard::ArrayRef::__ANON__[:58] |
| 0 | 0 | 0 | 0s | 0s | Types::Standard::ArrayRef::__ANON__[:67] |
| 0 | 0 | 0 | 0s | 0s | Types::Standard::ArrayRef::__ANON__[:75] |
| 0 | 0 | 0 | 0s | 0s | Types::Standard::ArrayRef::__ANON__[:84] |
| 0 | 0 | 0 | 0s | 0s | Types::Standard::ArrayRef::__coercion_generator |
| 0 | 0 | 0 | 0s | 0s | Types::Standard::ArrayRef::__deep_explanation |
| 0 | 0 | 0 | 0s | 0s | Types::Standard::ArrayRef::_croak |
| 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 | 62µs | 1 | 54µs | # spent 54µs within Types::Standard::ArrayRef::BEGIN@5 which was called:
# once (54µs+0s) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:190] at line 5 # spent 54µs making 1 call to Types::Standard::ArrayRef::BEGIN@5 |
| 6 | 2 | 19µ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 | 25µs | 2 | 58µs | # spent 30µs (2+28) within Types::Standard::ArrayRef::BEGIN@7 which was called:
# once (2µs+28µs) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:190] at line 7 # spent 30µs making 1 call to Types::Standard::ArrayRef::BEGIN@7
# spent 28µs making 1 call to warnings::import |
| 8 | |||||
| 9 | # spent 1µs within Types::Standard::ArrayRef::BEGIN@9 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 12 | ||||
| 10 | 1 | 0s | $Types::Standard::ArrayRef::AUTHORITY = 'cpan:TOBYINK'; | ||
| 11 | 1 | 2µs | $Types::Standard::ArrayRef::VERSION = '2.000001'; | ||
| 12 | 1 | 25µs | 1 | 1µs | } # spent 1µs making 1 call to Types::Standard::ArrayRef::BEGIN@9 |
| 13 | |||||
| 14 | 1 | 1µs | $Types::Standard::ArrayRef::VERSION =~ tr/_//d; | ||
| 15 | |||||
| 16 | 2 | 11µs | 1 | 3µs | # spent 3µs within Types::Standard::ArrayRef::BEGIN@16 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 16 # spent 3µs making 1 call to Types::Standard::ArrayRef::BEGIN@16 |
| 17 | 2 | 9µ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 | 26µs | 1 | 1µs | # spent 1µs within Types::Standard::ArrayRef::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::ArrayRef::BEGIN@18 |
| 19 | |||||
| 20 | sub _croak ($;@) { require Error::TypeTiny; goto \&Error::TypeTiny::croak } | ||||
| 21 | |||||
| 22 | 2 | 814µs | 2 | 24µs | # spent 15µs (6+9) within Types::Standard::ArrayRef::BEGIN@22 which was called:
# once (6µs+9µs) by Types::Standard::__ANON__[/Users/ether/.perlbrew/libs/36.0@std/lib/perl5/Types/Standard.pm:190] at line 22 # spent 15µs making 1 call to Types::Standard::ArrayRef::BEGIN@22
# spent 9µs making 1 call to warnings::unimport |
| 23 | |||||
| 24 | # spent 2.23ms (61µs+2.16) within Types::Standard::ArrayRef::__constraint_generator which was called 4 times, avg 556µs/call:
# 4 times (61µs+2.16ms) by Type::Tiny::parameterize at line 1044 of Type/Tiny.pm, avg 556µs/call | ||||
| 25 | 4 | 2µs | return Types::Standard::ArrayRef unless @_; | ||
| 26 | |||||
| 27 | 4 | 1µs | my $param = shift; | ||
| 28 | 4 | 3µs | 4 | 37µs | Types::TypeTiny::is_TypeTiny( $param ) # spent 37µs making 4 calls to Types::TypeTiny::is_TypeTiny, avg 9µs/call |
| 29 | or _croak( | ||||
| 30 | "Parameter to ArrayRef[`a] expected to be a type constraint; got $param" ); | ||||
| 31 | |||||
| 32 | 4 | 1µs | my ( $min, $max ) = ( 0, -1 ); | ||
| 33 | 4 | 1µs | $min = Types::Standard::assert_Int( shift ) if @_; | ||
| 34 | 4 | 2µs | $max = Types::Standard::assert_Int( shift ) if @_; | ||
| 35 | |||||
| 36 | 4 | 5µs | 4 | 331µs | my $param_compiled_check = $param->compiled_check; # spent 331µs making 4 calls to Type::Tiny::compiled_check, avg 83µs/call |
| 37 | 4 | 0s | my $xsub; | ||
| 38 | 4 | 6µ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 | 15µ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 68µs (32+36) within Types::Standard::ArrayRef::__inline_generator which was called 4 times, avg 17µs/call:
# 4 times (32µs+36µs) by Type::Tiny::parameterize at line 1057 of Type/Tiny.pm, avg 17µs/call | ||||
| 88 | 4 | 2µs | my $param = shift; | ||
| 89 | 4 | 0s | my ( $min, $max ) = ( 0, -1 ); | ||
| 90 | 4 | 1µs | $min = shift if @_; | ||
| 91 | 4 | 1µs | $max = shift if @_; | ||
| 92 | |||||
| 93 | 4 | 4µ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 | 0s | 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 | 5µs | 4 | 33µs | return unless $param->can_be_inlined; # spent 33µs making 4 calls to Type::Tiny::can_be_inlined, avg 8µs/call |
| 101 | |||||
| 102 | # spent 2.91ms (853µs+2.06) 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 121µs/call:
# 24 times (853µs+2.06ms) by Type::Tiny::inline_check at line 895 of Type/Tiny.pm, avg 121µs/call | ||||
| 103 | 24 | 2µs | my $v = $_[1]; | ||
| 104 | 24 | 10µs | return "$xsubname\($v\)" if $xsubname && !$Type::Tiny::AvoidCallbacks; | ||
| 105 | 24 | 63µs | 48 | 76µs | my $p = Types::Standard::ArrayRef->inline_check( $v ); # spent 76µs making 24 calls to Types::Standard::ArrayRef, avg 3µs/call
# spent 623µs making 24 calls to Type::Tiny::inline_check, avg 26µs/call, recursion: max depth 3, sum of overlapping time 623µs |
| 106 | |||||
| 107 | 24 | 7µs | if ( $min != 0 ) { | ||
| 108 | $p .= sprintf( ' and @{%s} >= %d', $v, $min ); | ||||
| 109 | } | ||||
| 110 | 24 | 12µs | if ( $max > 0 ) { | ||
| 111 | $p .= sprintf( ' and @{%s} <= %d', $v, $max ); | ||||
| 112 | } | ||||
| 113 | |||||
| 114 | 24 | 40µs | 24 | 0s | my $param_check = $param->inline_check( '$i' ); # spent 1.32ms making 24 calls to Type::Tiny::inline_check, avg 55µs/call, recursion: max depth 3, sum of overlapping time 1.32ms |
| 115 | 24 | 61µs | 24 | 37µs | return $p if $param->{uniq} eq Types::Standard::Any->{uniq}; # spent 37µs making 24 calls to Types::Standard::Any, avg 2µs/call |
| 116 | |||||
| 117 | 24 | 62µs | "$p and do { " | ||
| 118 | . "my \$ok = 1; " | ||||
| 119 | . "for my \$i (\@{$v}) { " | ||||
| 120 | . "(\$ok = 0, last) unless $param_check " . "}; " . "\$ok " . "}"; | ||||
| 121 | 4 | 16µ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 | 3µs | 1; |