| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Data::DPath::Filters; |
|
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:SCHWIGON'; |
|
3
|
|
|
|
|
|
|
# ABSTRACT: Magic functions available inside filter conditions |
|
4
|
|
|
|
|
|
|
$Data::DPath::Filters::VERSION = '0.59'; |
|
5
|
13
|
|
|
13
|
|
89
|
use strict; |
|
|
13
|
|
|
|
|
25
|
|
|
|
13
|
|
|
|
|
372
|
|
|
6
|
13
|
|
|
13
|
|
71
|
use warnings; |
|
|
13
|
|
|
|
|
24
|
|
|
|
13
|
|
|
|
|
294
|
|
|
7
|
|
|
|
|
|
|
|
|
8
|
13
|
|
|
13
|
|
64
|
use Data::Dumper; |
|
|
13
|
|
|
|
|
23
|
|
|
|
13
|
|
|
|
|
595
|
|
|
9
|
13
|
|
|
13
|
|
78
|
use Scalar::Util; |
|
|
13
|
|
|
|
|
48
|
|
|
|
13
|
|
|
|
|
651
|
|
|
10
|
|
|
|
|
|
|
use constant { |
|
11
|
13
|
|
|
|
|
2319
|
HASH => 'HASH', |
|
12
|
|
|
|
|
|
|
ARRAY => 'ARRAY', |
|
13
|
|
|
|
|
|
|
SCALAR => 'SCALAR', |
|
14
|
13
|
|
|
13
|
|
75
|
}; |
|
|
13
|
|
|
|
|
36
|
|
|
15
|
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
our $idx; |
|
17
|
|
|
|
|
|
|
our $p; # current point |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
sub affe { |
|
20
|
14
|
100
|
|
14
|
1
|
3472
|
return $_ eq 'affe' ? 1 : 0; |
|
21
|
|
|
|
|
|
|
} |
|
22
|
|
|
|
|
|
|
|
|
23
|
12
|
|
|
12
|
1
|
2989
|
sub idx { $idx } |
|
24
|
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub size() |
|
26
|
|
|
|
|
|
|
{ |
|
27
|
13
|
|
|
13
|
|
127
|
no warnings 'uninitialized'; |
|
|
13
|
|
|
|
|
32
|
|
|
|
13
|
|
|
|
|
2635
|
|
|
28
|
|
|
|
|
|
|
|
|
29
|
292
|
50
|
|
292
|
1
|
69876
|
return -1 unless defined $_; |
|
30
|
|
|
|
|
|
|
# speed optimization: first try faster ref, then reftype |
|
31
|
|
|
|
|
|
|
# ref |
|
32
|
292
|
100
|
|
|
|
1368
|
return scalar @$_ if ref $_ eq ARRAY; |
|
33
|
244
|
100
|
|
|
|
1501
|
return scalar keys %$_ if ref $_ eq HASH; |
|
34
|
160
|
100
|
|
|
|
1986
|
return 1 if ref \$_ eq SCALAR; |
|
35
|
|
|
|
|
|
|
# reftype |
|
36
|
6
|
50
|
|
|
|
90
|
return scalar @$_ if Scalar::Util::reftype $_ eq ARRAY; |
|
37
|
0
|
0
|
|
|
|
0
|
return scalar keys %$_ if Scalar::Util::reftype $_ eq HASH; |
|
38
|
0
|
0
|
|
|
|
0
|
return 1 if Scalar::Util::reftype \$_ eq SCALAR; |
|
39
|
|
|
|
|
|
|
# else |
|
40
|
0
|
|
|
|
|
0
|
return -1; |
|
41
|
|
|
|
|
|
|
} |
|
42
|
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
sub key() |
|
44
|
|
|
|
|
|
|
{ |
|
45
|
13
|
|
|
13
|
|
101
|
no warnings 'uninitialized'; |
|
|
13
|
|
|
|
|
55
|
|
|
|
13
|
|
|
|
|
1403
|
|
|
46
|
256
|
100
|
|
256
|
1
|
64342
|
my $attrs = defined $p->attrs ? $p->attrs : {}; |
|
47
|
256
|
|
|
|
|
3564
|
return $attrs->{key}; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub value() |
|
51
|
|
|
|
|
|
|
{ |
|
52
|
13
|
|
|
13
|
|
92
|
no warnings 'uninitialized'; |
|
|
13
|
|
|
|
|
54
|
|
|
|
13
|
|
|
|
|
1058
|
|
|
53
|
327
|
|
|
327
|
1
|
54174
|
return $_; |
|
54
|
|
|
|
|
|
|
} |
|
55
|
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub isa($) { |
|
57
|
12
|
|
|
12
|
1
|
3316
|
my ($classname) = @_; |
|
58
|
|
|
|
|
|
|
|
|
59
|
13
|
|
|
13
|
|
104
|
no warnings 'uninitialized'; |
|
|
13
|
|
|
|
|
31
|
|
|
|
13
|
|
|
|
|
1480
|
|
|
60
|
|
|
|
|
|
|
#print STDERR "*** value ", Dumper($_ ? $_ : "UNDEF"); |
|
61
|
12
|
100
|
|
|
|
254
|
return $_->isa($classname) if Scalar::Util::blessed $_; |
|
62
|
2
|
|
|
|
|
24
|
return undef; |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
sub reftype() { |
|
66
|
10
|
|
|
10
|
1
|
2939
|
return Scalar::Util::reftype($_); |
|
67
|
|
|
|
|
|
|
} |
|
68
|
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
sub is_reftype($) { |
|
70
|
13
|
|
|
13
|
|
114
|
no warnings 'uninitialized'; |
|
|
13
|
|
|
|
|
34
|
|
|
|
13
|
|
|
|
|
1118
|
|
|
71
|
32
|
|
|
32
|
1
|
8445
|
return (Scalar::Util::reftype($_) eq shift); |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
1; |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
=pod |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=encoding UTF-8 |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
=head1 NAME |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
Data::DPath::Filters - Magic functions available inside filter conditions |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
=head1 API METHODS |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=head2 affe |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
Mysterious test function. Will vanish. Soon. Or will it really? No, |
|
89
|
|
|
|
|
|
|
probably not. I like it. :-) |
|
90
|
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Returns true if the value eq "affe". |
|
92
|
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=head2 idx |
|
94
|
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
Returns the current index inside array elements. |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
Please note that the current matching elements might not be in a |
|
98
|
|
|
|
|
|
|
defined order if resulting from anything else than arrays. |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
=head2 size |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
Returns the size of the current element. If it is an array ref it |
|
103
|
|
|
|
|
|
|
returns the number of elements, if it is a hash ref it returns number of keys, |
|
104
|
|
|
|
|
|
|
if it is a scalar it returns 1, everything else returns -1. |
|
105
|
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
=head2 key |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
If it is a hashref returns the key under which the current element is |
|
109
|
|
|
|
|
|
|
associated as value. Else it returns undef. |
|
110
|
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
This gives the key() function kind of a "look back" behaviour because |
|
112
|
|
|
|
|
|
|
the associated point is already after that key. |
|
113
|
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
=head2 value |
|
115
|
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
Returns the value of the current element. |
|
117
|
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head2 isa |
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
Frontend to UNIVERSAL::isa. True if the current element is_a given |
|
121
|
|
|
|
|
|
|
class. |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=head2 reftype |
|
124
|
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
Frontend to Scalar::Util::reftype. |
|
126
|
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
Returns Scalar::Util::reftype of current element $_. With this you can |
|
128
|
|
|
|
|
|
|
do comparison by yourself with C, C<=~>, C<~~> or whatever in |
|
129
|
|
|
|
|
|
|
filter expressions. |
|
130
|
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
=head2 is_reftype($EXPECTED_TYPE) |
|
132
|
|
|
|
|
|
|
|
|
133
|
|
|
|
|
|
|
Frontend to Scalar::Util::reftype. |
|
134
|
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
Checks whether Scalar::Util::reftype of current element $_ equals the |
|
136
|
|
|
|
|
|
|
provided argument $EXPECTED_TYPE and returns true/false. |
|
137
|
|
|
|
|
|
|
|
|
138
|
|
|
|
|
|
|
=head1 AUTHOR |
|
139
|
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
Steffen Schwigon |
|
141
|
|
|
|
|
|
|
|
|
142
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
143
|
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
This software is copyright (c) 2023 by Steffen Schwigon. |
|
145
|
|
|
|
|
|
|
|
|
146
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
147
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
148
|
|
|
|
|
|
|
|
|
149
|
|
|
|
|
|
|
=cut |
|
150
|
|
|
|
|
|
|
|
|
151
|
|
|
|
|
|
|
__END__ |