line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Catmandu::AlephX::XPath::Helper; |
2
|
25
|
|
|
25
|
|
112234
|
use Catmandu::Sane; |
|
25
|
|
|
|
|
199861
|
|
|
25
|
|
|
|
|
171
|
|
3
|
25
|
|
|
25
|
|
22259
|
use XML::LibXML; |
|
25
|
|
|
|
|
1239787
|
|
|
25
|
|
|
|
|
186
|
|
4
|
25
|
|
|
25
|
|
4426
|
use XML::LibXML::XPathContext; |
|
25
|
|
|
|
|
75
|
|
|
25
|
|
|
|
|
722
|
|
5
|
25
|
|
|
25
|
|
151
|
use Catmandu::Util qw(:is io); |
|
25
|
|
|
|
|
56
|
|
|
25
|
|
|
|
|
7101
|
|
6
|
25
|
|
|
25
|
|
203
|
use Exporter qw(import); |
|
25
|
|
|
|
|
66
|
|
|
25
|
|
|
|
|
11814
|
|
7
|
|
|
|
|
|
|
our @EXPORT_OK=qw(get_children xpath); |
8
|
|
|
|
|
|
|
our %EXPORT_TAGS = (all=>[@EXPORT_OK]); |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
our $VERSION = "1.073"; |
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; |