| Filename | /home/ss5/perl5/perlbrew/perls/tapper-perl/lib/site_perl/5.16.3/Data/DPath/Filters.pm |
| Statements | Executed 24 statements in 446µs |
| Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
|---|---|---|---|---|---|
| 1 | 1 | 1 | 9µs | 16µs | Data::DPath::Filters::BEGIN@57 |
| 1 | 1 | 1 | 9µs | 15µs | Data::DPath::Filters::BEGIN@64 |
| 1 | 1 | 1 | 8µs | 70µs | Data::DPath::Filters::BEGIN@15 |
| 1 | 1 | 1 | 8µs | 16µs | Data::DPath::Filters::BEGIN@32 |
| 1 | 1 | 1 | 8µs | 14µs | Data::DPath::Filters::BEGIN@50 |
| 1 | 1 | 1 | 7µs | 10µs | Data::DPath::Filters::BEGIN@11 |
| 1 | 1 | 1 | 7µs | 16µs | Data::DPath::Filters::BEGIN@14 |
| 1 | 1 | 1 | 7µs | 7µs | Data::DPath::Filters::BEGIN@2 |
| 1 | 1 | 1 | 6µs | 25µs | Data::DPath::Filters::BEGIN@13 |
| 1 | 1 | 1 | 6µs | 16µs | Data::DPath::Filters::BEGIN@10 |
| 0 | 0 | 0 | 0s | 0s | Data::DPath::Filters::affe |
| 0 | 0 | 0 | 0s | 0s | Data::DPath::Filters::idx |
| 0 | 0 | 0 | 0s | 0s | Data::DPath::Filters::is_reftype |
| 0 | 0 | 0 | 0s | 0s | Data::DPath::Filters::isa |
| 0 | 0 | 0 | 0s | 0s | Data::DPath::Filters::key |
| 0 | 0 | 0 | 0s | 0s | Data::DPath::Filters::reftype |
| 0 | 0 | 0 | 0s | 0s | Data::DPath::Filters::size |
| 0 | 0 | 0 | 0s | 0s | Data::DPath::Filters::value |
| Line | State ments |
Time on line |
Calls | Time in subs |
Code |
|---|---|---|---|---|---|
| 1 | package Data::DPath::Filters; | ||||
| 2 | # spent 7µs within Data::DPath::Filters::BEGIN@2 which was called:
# once (7µs+0s) by Data::DPath::Context::BEGIN@18 at line 4 | ||||
| 3 | 1 | 4µs | $Data::DPath::Filters::AUTHORITY = 'cpan:SCHWIGON'; | ||
| 4 | 1 | 20µs | 1 | 7µs | } # spent 7µs making 1 call to Data::DPath::Filters::BEGIN@2 |
| 5 | { | ||||
| 6 | 2 | 900ns | $Data::DPath::Filters::VERSION = '0.49'; | ||
| 7 | } | ||||
| 8 | # ABSTRACT: Magic functions available inside filter conditions | ||||
| 9 | |||||
| 10 | 2 | 17µs | 2 | 25µs | # spent 16µs (6+10) within Data::DPath::Filters::BEGIN@10 which was called:
# once (6µs+10µs) by Data::DPath::Context::BEGIN@18 at line 10 # spent 16µs making 1 call to Data::DPath::Filters::BEGIN@10
# spent 10µs making 1 call to strict::import |
| 11 | 2 | 16µs | 2 | 13µs | # spent 10µs (7+3) within Data::DPath::Filters::BEGIN@11 which was called:
# once (7µs+3µs) by Data::DPath::Context::BEGIN@18 at line 11 # spent 10µs making 1 call to Data::DPath::Filters::BEGIN@11
# spent 3µs making 1 call to warnings::import |
| 12 | |||||
| 13 | 2 | 18µs | 2 | 43µs | # spent 25µs (6+18) within Data::DPath::Filters::BEGIN@13 which was called:
# once (6µs+18µs) by Data::DPath::Context::BEGIN@18 at line 13 # spent 25µs making 1 call to Data::DPath::Filters::BEGIN@13
# spent 18µs making 1 call to Exporter::import |
| 14 | 2 | 27µs | 2 | 26µs | # spent 16µs (7+10) within Data::DPath::Filters::BEGIN@14 which was called:
# once (7µs+10µs) by Data::DPath::Context::BEGIN@18 at line 14 # spent 16µs making 1 call to Data::DPath::Filters::BEGIN@14
# spent 10µs making 1 call to Exporter::import |
| 15 | # spent 70µs (8+62) within Data::DPath::Filters::BEGIN@15 which was called:
# once (8µs+62µs) by Data::DPath::Context::BEGIN@18 at line 19 | ||||
| 16 | 1 | 12µs | 1 | 62µs | HASH => 'HASH', # spent 62µs making 1 call to constant::import |
| 17 | ARRAY => 'ARRAY', | ||||
| 18 | SCALAR => 'SCALAR', | ||||
| 19 | 1 | 57µs | 1 | 70µs | }; # spent 70µs making 1 call to Data::DPath::Filters::BEGIN@15 |
| 20 | |||||
| 21 | 1 | 0s | our $idx; | ||
| 22 | 1 | 0s | our $p; # current point | ||
| 23 | |||||
| 24 | sub affe { | ||||
| 25 | return $_ eq 'affe' ? 1 : 0; | ||||
| 26 | } | ||||
| 27 | |||||
| 28 | sub idx { $idx } | ||||
| 29 | |||||
| 30 | sub size() | ||||
| 31 | { | ||||
| 32 | 2 | 105µs | 2 | 24µs | # spent 16µs (8+8) within Data::DPath::Filters::BEGIN@32 which was called:
# once (8µs+8µs) by Data::DPath::Context::BEGIN@18 at line 32 # spent 16µs making 1 call to Data::DPath::Filters::BEGIN@32
# spent 8µs making 1 call to warnings::unimport |
| 33 | |||||
| 34 | return -1 unless defined $_; | ||||
| 35 | # speed optimization: first try faster ref, then reftype | ||||
| 36 | # ref | ||||
| 37 | return scalar @$_ if ref $_ eq ARRAY; | ||||
| 38 | return scalar keys %$_ if ref $_ eq HASH; | ||||
| 39 | return 1 if ref \$_ eq SCALAR; | ||||
| 40 | # reftype | ||||
| 41 | return scalar @$_ if Scalar::Util::reftype $_ eq ARRAY; | ||||
| 42 | return scalar keys %$_ if Scalar::Util::reftype $_ eq HASH; | ||||
| 43 | return 1 if Scalar::Util::reftype \$_ eq SCALAR; | ||||
| 44 | # else | ||||
| 45 | return -1; | ||||
| 46 | } | ||||
| 47 | |||||
| 48 | sub key() | ||||
| 49 | { | ||||
| 50 | 2 | 46µs | 2 | 21µs | # spent 14µs (8+7) within Data::DPath::Filters::BEGIN@50 which was called:
# once (8µs+7µs) by Data::DPath::Context::BEGIN@18 at line 50 # spent 14µs making 1 call to Data::DPath::Filters::BEGIN@50
# spent 7µs making 1 call to warnings::unimport |
| 51 | my $attrs = defined $p->attrs ? $p->attrs : {}; | ||||
| 52 | return $attrs->{key}; | ||||
| 53 | } | ||||
| 54 | |||||
| 55 | sub value() | ||||
| 56 | { | ||||
| 57 | 2 | 38µs | 2 | 22µs | # spent 16µs (9+7) within Data::DPath::Filters::BEGIN@57 which was called:
# once (9µs+7µs) by Data::DPath::Context::BEGIN@18 at line 57 # spent 16µs making 1 call to Data::DPath::Filters::BEGIN@57
# spent 7µs making 1 call to warnings::unimport |
| 58 | return $_; | ||||
| 59 | } | ||||
| 60 | |||||
| 61 | sub isa($) { | ||||
| 62 | my ($classname) = @_; | ||||
| 63 | |||||
| 64 | 2 | 83µs | 2 | 21µs | # spent 15µs (9+6) within Data::DPath::Filters::BEGIN@64 which was called:
# once (9µs+6µs) by Data::DPath::Context::BEGIN@18 at line 64 # spent 15µs making 1 call to Data::DPath::Filters::BEGIN@64
# spent 6µs making 1 call to warnings::unimport |
| 65 | #print STDERR "*** value ", Dumper($_ ? $_ : "UNDEF"); | ||||
| 66 | return $_->isa($classname) if Scalar::Util::blessed $_; | ||||
| 67 | return undef; | ||||
| 68 | } | ||||
| 69 | |||||
| 70 | sub reftype() { | ||||
| 71 | return Scalar::Util::reftype($_); | ||||
| 72 | } | ||||
| 73 | |||||
| 74 | sub is_reftype($) { | ||||
| 75 | return (Scalar::Util::reftype($_) eq shift); | ||||
| 76 | } | ||||
| 77 | |||||
| 78 | 1 | 2µs | 1; | ||
| 79 | |||||
| 80 | =pod | ||||
| 81 | |||||
| 82 | =encoding utf-8 | ||||
| 83 | |||||
| 84 | =head1 NAME | ||||
| 85 | |||||
| 86 | Data::DPath::Filters - Magic functions available inside filter conditions | ||||
| 87 | |||||
| 88 | =head1 API METHODS | ||||
| 89 | |||||
| 90 | =head2 affe | ||||
| 91 | |||||
| 92 | Mysterious test function. Will vanish. Soon. Or will it really? No, | ||||
| 93 | probably not. I like it. :-) | ||||
| 94 | |||||
| 95 | Returns true if the value eq "affe". | ||||
| 96 | |||||
| 97 | =head2 idx | ||||
| 98 | |||||
| 99 | Returns the current index inside array elements. | ||||
| 100 | |||||
| 101 | Please note that the current matching elements might not be in a | ||||
| 102 | defined order if resulting from anything else than arrays. | ||||
| 103 | |||||
| 104 | =head2 size | ||||
| 105 | |||||
| 106 | Returns the size of the current element. If it is a hash ref it | ||||
| 107 | returns number of elements, if hashref it returns number of keys, if | ||||
| 108 | scalar it returns 1, everything else returns -1. | ||||
| 109 | |||||
| 110 | =head2 key | ||||
| 111 | |||||
| 112 | If it is a hashref returns the key under which the current element is | ||||
| 113 | associated as value. Else it returns undef. | ||||
| 114 | |||||
| 115 | This gives the key() function kind of a "look back" behaviour because | ||||
| 116 | the associated point is already after that key. | ||||
| 117 | |||||
| 118 | =head2 value | ||||
| 119 | |||||
| 120 | Returns the value of the current element. | ||||
| 121 | |||||
| 122 | =head2 isa | ||||
| 123 | |||||
| 124 | Frontend to UNIVERSAL::isa. True if the current element is_a given | ||||
| 125 | class. | ||||
| 126 | |||||
| 127 | =head2 reftype | ||||
| 128 | |||||
| 129 | Frontend to Scalar::Util::reftype. | ||||
| 130 | |||||
| 131 | Returns Scalar::Util::reftype of current element $_. With this you can | ||||
| 132 | do comparison by yourself with C<eq>, C<=~>, C<~~> or whatever in | ||||
| 133 | filter expressions. | ||||
| 134 | |||||
| 135 | =head2 is_reftype($EXPECTED_TYPE) | ||||
| 136 | |||||
| 137 | Frontend to Scalar::Util::reftype. | ||||
| 138 | |||||
| 139 | Checks whether Scalar::Util::reftype of current element $_ equals the | ||||
| 140 | provided argument $EXPECTED_TYPE and returns true/false. | ||||
| 141 | |||||
| 142 | =head1 AUTHOR | ||||
| 143 | |||||
| 144 | Steffen Schwigon <ss5@renormalist.net> | ||||
| 145 | |||||
| 146 | =head1 COPYRIGHT AND LICENSE | ||||
| 147 | |||||
| 148 | This software is copyright (c) 2012 by Steffen Schwigon. | ||||
| 149 | |||||
| 150 | This is free software; you can redistribute it and/or modify it under | ||||
| 151 | the same terms as the Perl 5 programming language system itself. | ||||
| 152 | |||||
| 153 | =cut | ||||
| 154 | |||||
| 155 | __END__ |