line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::AlephX::XPath::Helper; |
2
|
25
|
|
|
25
|
|
104010
|
use Catmandu::Sane; |
|
25
|
|
|
|
|
193805
|
|
|
25
|
|
|
|
|
167
|
|
3
|
25
|
|
|
25
|
|
20668
|
use XML::LibXML; |
|
25
|
|
|
|
|
1160431
|
|
|
25
|
|
|
|
|
168
|
|
4
|
25
|
|
|
25
|
|
4001
|
use XML::LibXML::XPathContext; |
|
25
|
|
|
|
|
63
|
|
|
25
|
|
|
|
|
645
|
|
5
|
25
|
|
|
25
|
|
145
|
use Catmandu::Util qw(:is io); |
|
25
|
|
|
|
|
55
|
|
|
25
|
|
|
|
|
7278
|
|
6
|
25
|
|
|
25
|
|
196
|
use Exporter qw(import); |
|
25
|
|
|
|
|
61
|
|
|
25
|
|
|
|
|
11345
|
|
7
|
|
|
|
|
|
|
our @EXPORT_OK=qw(get_children xpath); |
8
|
|
|
|
|
|
|
our %EXPORT_TAGS = (all=>[@EXPORT_OK]); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = "1.072"; |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub get_children { |
13
|
0
|
|
|
0
|
0
|
|
my($xpath,$is_hash) = @_; |
14
|
|
|
|
|
|
|
|
15
|
0
|
|
|
|
|
|
my $hash = {}; |
16
|
|
|
|
|
|
|
|
17
|
0
|
0
|
|
|
|
|
if($xpath){ |
18
|
0
|
|
|
|
|
|
for my $child($xpath->find('child::*')->get_nodelist()){ |
19
|
0
|
|
|
|
|
|
my $name = $child->nodeName(); |
20
|
0
|
|
|
|
|
|
my $value = $child->textContent(); |
21
|
0
|
0
|
|
|
|
|
if($is_hash){ |
22
|
0
|
|
|
|
|
|
$hash->{ $name } = $value; |
23
|
|
|
|
|
|
|
}else{ |
24
|
0
|
|
0
|
|
|
|
$hash->{$name} //= []; |
25
|
0
|
0
|
|
|
|
|
push @{ $hash->{$name} },$value if is_string($value); |
|
0
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
$hash; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub xpath { |
34
|
0
|
|
|
0
|
0
|
|
my $str = $_[0]; |
35
|
0
|
|
|
|
|
|
my $xpath; |
36
|
0
|
0
|
|
|
|
|
if(is_scalar_ref($str)){ |
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
my $xml = XML::LibXML->load_xml(IO => io($str)); |
38
|
0
|
|
|
|
|
|
$xpath = XML::LibXML::XPathContext->new($xml); |
39
|
|
|
|
|
|
|
}elsif(-f $str){ |
40
|
0
|
|
|
|
|
|
my $xml = XML::LibXML->load_xml(location => $str); |
41
|
0
|
|
|
|
|
|
$xpath = XML::LibXML::XPathContext->new($xml); |
42
|
|
|
|
|
|
|
}elsif(is_glob_ref($str)){ |
43
|
0
|
|
|
|
|
|
my $xml = XML::LibXML->load_xml(IO => io($str)); |
44
|
0
|
|
|
|
|
|
$xpath = XML::LibXML::XPathContext->new($xml); |
45
|
|
|
|
|
|
|
} |
46
|
0
|
|
|
|
|
|
return $xpath; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
1; |