← Index
NYTProf Performance Profile   « block view • line view • sub view »
For bin/dpath
  Run on Tue Jun 5 15:31:33 2012
Reported on Tue Jun 5 15:31:48 2012

Filename/home/ss5/perl5/perlbrew/perls/perl-5.14.1/lib/site_perl/5.14.1/Data/DPath/Filters.pm
StatementsExecuted 24 statements in 3.12ms
Subroutines
Calls P F Exclusive
Time
Inclusive
Time
Subroutine
1114.02ms5.55msData::DPath::Filters::::BEGIN@15Data::DPath::Filters::BEGIN@15
11148µs108µsData::DPath::Filters::::BEGIN@14Data::DPath::Filters::BEGIN@14
11140µs73µsData::DPath::Filters::::BEGIN@57Data::DPath::Filters::BEGIN@57
11137µs37µsData::DPath::Filters::::BEGIN@2Data::DPath::Filters::BEGIN@2
11135µs64µsData::DPath::Filters::::BEGIN@11Data::DPath::Filters::BEGIN@11
11135µs92µsData::DPath::Filters::::BEGIN@32Data::DPath::Filters::BEGIN@32
11134µs72µsData::DPath::Filters::::BEGIN@50Data::DPath::Filters::BEGIN@50
11131µs47µsData::DPath::Filters::::BEGIN@10Data::DPath::Filters::BEGIN@10
11131µs143µsData::DPath::Filters::::BEGIN@13Data::DPath::Filters::BEGIN@13
11127µs61µsData::DPath::Filters::::BEGIN@64Data::DPath::Filters::BEGIN@64
0000s0sData::DPath::Filters::::affeData::DPath::Filters::affe
0000s0sData::DPath::Filters::::idxData::DPath::Filters::idx
0000s0sData::DPath::Filters::::is_reftypeData::DPath::Filters::is_reftype
0000s0sData::DPath::Filters::::isaData::DPath::Filters::isa
0000s0sData::DPath::Filters::::keyData::DPath::Filters::key
0000s0sData::DPath::Filters::::reftypeData::DPath::Filters::reftype
0000s0sData::DPath::Filters::::sizeData::DPath::Filters::size
0000s0sData::DPath::Filters::::valueData::DPath::Filters::value
Call graph for these subroutines as a Graphviz dot language file.
Line State
ments
Time
on line
Calls Time
in subs
Code
1package 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
BEGIN {
3131µs $Data::DPath::Filters::AUTHORITY = 'cpan:SCHWIGON';
41130µs137µs}
# spent 37µs making 1 call to Data::DPath::Filters::BEGIN@2
5{
624µs $Data::DPath::Filters::VERSION = '0.48';
7}
8# ABSTRACT: Magic functions available inside filter conditions
9
10292µs264µ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
use strict;
# spent 47µs making 1 call to Data::DPath::Filters::BEGIN@10 # spent 16µs making 1 call to strict::import
11296µs294µ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
use warnings;
# spent 64µs making 1 call to Data::DPath::Filters::BEGIN@11 # spent 29µs making 1 call to warnings::import
12
132114µs2256µ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
use Data::Dumper;
# spent 143µs making 1 call to Data::DPath::Filters::BEGIN@13 # spent 112µs making 1 call to Exporter::import
142152µs2168µ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
use Scalar::Util;
# 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
use constant {
16141µs1331µs HASH => 'HASH',
# spent 331µs making 1 call to constant::import
17 ARRAY => 'ARRAY',
18 SCALAR => 'SCALAR',
191710µs15.55ms };
# spent 5.55ms making 1 call to Data::DPath::Filters::BEGIN@15
20
211300nsour $idx;
221300nsour $p; # current point
23
24sub affe {
25 return $_ eq 'affe' ? 1 : 0;
26}
27
28sub idx { $idx }
29
30sub size()
31{
322669µs2150µ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
no warnings 'uninitialized';
# 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
48sub key()
49{
502245µs2109µ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
no warnings 'uninitialized';
# 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
55sub value()
56{
572222µs2107µ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
no warnings 'uninitialized';
# 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
61sub isa($) {
62 my ($classname) = @_;
63
642600µs294µ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
no warnings 'uninitialized';
# 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
70sub reftype() {
71 return Scalar::Util::reftype($_);
72}
73
74sub is_reftype($) {
75 return (Scalar::Util::reftype($_) eq shift);
76}
77
78113µs1;
79
- -
82=pod
83
84=encoding utf-8
85
86=head1 NAME
87
88Data::DPath::Filters - Magic functions available inside filter conditions
89
90=head1 API METHODS
91
92=head2 affe
93
94Mysterious test function. Will vanish. Soon. Or will it really? No,
95probably not. I like it. :-)
96
97Returns true if the value eq "affe".
98
99=head2 idx
100
101Returns the current index inside array elements.
102
103Please note that the current matching elements might not be in a
104defined order if resulting from anything else than arrays.
105
106=head2 size
107
108Returns the size of the current element. If it is a hash ref it
109returns number of elements, if hashref it returns number of keys, if
110scalar it returns 1, everything else returns -1.
111
112=head2 key
113
114If it is a hashref returns the key under which the current element is
115associated as value. Else it returns undef.
116
117This gives the key() function kind of a "look back" behaviour because
118the associated point is already after that key.
119
120=head2 value
121
122Returns the value of the current element.
123
124=head2 isa
125
126Frontend to UNIVERSAL::isa. True if the current element is_a given
127class.
128
129=head2 reftype
130
131Frontend to Scalar::Util::reftype.
132
133Returns Scalar::Util::reftype of current element $_. With this you can
134do comparison by yourself with C<eq>, C<=~>, C<~~> or whatever in
135filter expressions.
136
137=head2 is_reftype($EXPECTED_TYPE)
138
139Frontend to Scalar::Util::reftype.
140
141Checks whether Scalar::Util::reftype of current element $_ equals the
142provided argument $EXPECTED_TYPE and returns true/false.
143
144=head1 AUTHOR
145
146Steffen Schwigon <ss5@renormalist.net>
147
148=head1 COPYRIGHT AND LICENSE
149
150This software is copyright (c) 2012 by Steffen Schwigon.
151
152This is free software; you can redistribute it and/or modify it under
153the same terms as the Perl 5 programming language system itself.
154
155=cut
156
157
158__END__