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