line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package XML::RSS::Parser::Element; |
2
|
|
|
|
|
|
|
|
3
|
1
|
|
|
1
|
|
1186
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
42
|
|
4
|
1
|
|
|
1
|
|
5
|
use base qw(XML::Elemental::Element); |
|
1
|
|
|
|
|
8
|
|
|
1
|
|
|
|
|
1057
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
535
|
use XML::Elemental::Util qw(process_name); |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
60
|
|
7
|
1
|
|
|
1
|
|
7
|
use XML::RSS::Parser::Util; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
174
|
|
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
use Class::XPath 1.4 |
10
|
|
|
|
|
|
|
get_name => 'qname', |
11
|
|
|
|
|
|
|
get_parent => 'parent', |
12
|
|
|
|
|
|
|
get_root => 'root', |
13
|
489
|
100
|
|
|
|
11506
|
get_children => sub { $_[0]->contents ? @{$_[0]->contents} : () }, |
|
169
|
|
|
|
|
1040
|
|
14
|
1
|
|
|
|
|
9
|
get_attr_names => 'attribute_qnames', |
15
|
|
|
|
|
|
|
get_attr_value => 'attribute_by_qname', |
16
|
1
|
|
|
1
|
|
1163
|
get_content => 'text_content'; |
|
1
|
|
|
|
|
2635
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub new { |
19
|
22
|
|
|
22
|
1
|
7971
|
my $self = shift->SUPER::new(@_); |
20
|
22
|
|
50
|
|
|
228
|
my $a = shift || {}; |
21
|
0
|
|
|
|
|
0
|
map { $self->{$_} = $a->{$_} } |
|
88
|
|
|
|
|
147
|
|
22
|
22
|
|
|
|
|
32
|
grep { defined $a->{$_} } qw( name attributes root parent ); |
23
|
22
|
|
|
|
|
54
|
$self; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
0
|
1
|
0
|
sub as_xml { XML::RSS::Parser::Util::as_xml($_[0]); } |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
#--- xpath methods |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub query { |
31
|
5
|
|
|
5
|
1
|
3903
|
my @nodes = $_[0]->match($_[1]); |
32
|
5
|
100
|
|
|
|
82
|
wantarray ? @nodes : $nodes[0]; |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
sub qname { |
36
|
88
|
|
66
|
88
|
1
|
2035
|
my $in = $_[1] || $_[0]->name; |
37
|
88
|
|
|
|
|
536
|
my ($local, $ns) = process_name($in); |
38
|
88
|
100
|
|
|
|
857
|
return $local if ($_[0]->root->rss_namespace_uri eq $ns); |
39
|
24
|
|
|
|
|
81
|
my $prefix = XML::RSS::Parser->prefix($ns); |
40
|
24
|
100
|
|
|
|
51
|
unless ($prefix) { # make a generic prefix for unknown namespace URI. |
41
|
1
|
|
|
|
|
2
|
my $i = 1; |
42
|
1
|
|
|
|
|
8
|
while (XML::RSS::Parser->namespace("NS$i")) { $i++ } |
|
0
|
|
|
|
|
0
|
|
43
|
1
|
|
|
|
|
6
|
XML::RSS::Parser->register_ns_prefix("NS$i", $ns); |
44
|
1
|
|
|
|
|
2
|
$prefix = "NS$i"; |
45
|
|
|
|
|
|
|
} |
46
|
24
|
|
|
|
|
94
|
"$prefix:$local"; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub attribute_qnames { |
50
|
20
|
50
|
|
20
|
1
|
501
|
return () unless my $attr = $_[0]->attributes; |
51
|
20
|
|
|
|
|
142
|
my ($foo, $ns) = process_name($_[0]->name); |
52
|
20
|
|
|
|
|
235
|
my @names; |
53
|
20
|
|
|
|
|
49
|
foreach (keys %$attr) { |
54
|
1
|
|
|
|
|
4
|
my ($local, $nsa) = process_name($_); |
55
|
1
|
|
33
|
|
|
14
|
$nsa ||= $ns; |
56
|
1
|
|
|
|
|
6
|
push @names, $_[0]->qname("{$nsa}$local"); |
57
|
|
|
|
|
|
|
} |
58
|
20
|
|
|
|
|
49
|
@names; |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
my $NAME = qr/[[:alpha:]_][\w\-\.]*/; |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub attribute_by_qname { |
64
|
1
|
|
|
1
|
1
|
31
|
my $self = shift; |
65
|
1
|
|
|
|
|
2
|
my $name = shift; |
66
|
1
|
|
|
|
|
2
|
my $ns = ''; |
67
|
1
|
50
|
|
|
|
80
|
if ($name =~ /($NAME):($NAME)/) { |
68
|
0
|
|
|
|
|
0
|
$name = $2; |
69
|
0
|
|
0
|
|
|
0
|
$ns = XML::RSS::Parser->namespace($1) || '#UNKNOWN'; |
70
|
|
|
|
|
|
|
} else { |
71
|
1
|
|
50
|
|
|
6
|
$ns = XML::RSS::Parser->namespace('#DEFAULT') || ''; |
72
|
|
|
|
|
|
|
} |
73
|
1
|
|
|
|
|
6
|
my ($local, $ns_parent) = process_name($self->name); |
74
|
1
|
50
|
|
|
|
16
|
$ns = '' if $ns_parent eq $ns; |
75
|
1
|
|
|
|
|
3
|
$self->attributes->{"{$ns}$name"}; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
#--- XML::RSS::Parser::Element 2x API methods. Now deprecated. |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
sub child { |
81
|
0
|
|
|
0
|
1
|
|
my ($self, $tag) = @_; |
82
|
0
|
|
|
|
|
|
my $class = ref($self); |
83
|
0
|
|
|
|
|
|
my $e = $class->new({parent => $self, name => $tag}); |
84
|
0
|
|
|
|
|
|
push(@{$self->contents}, $e); |
|
0
|
|
|
|
|
|
|
85
|
0
|
|
|
|
|
|
$e; |
86
|
|
|
|
|
|
|
} |
87
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
sub children { |
89
|
0
|
|
|
0
|
1
|
|
my ($self, $name) = @_; |
90
|
0
|
0
|
|
|
|
|
return $self->contents unless defined($name); |
91
|
0
|
0
|
|
|
|
|
my @c = grep { $_->can('name') && $_->name eq $name } @{$self->contents}; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
92
|
0
|
0
|
|
|
|
|
wantarray ? @c : $c[0]; |
93
|
|
|
|
|
|
|
} |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
sub attribute { |
96
|
0
|
0
|
|
0
|
1
|
|
$_[0]->attributes->{$_[1]} = $_[2] if $_[2]; |
97
|
0
|
|
|
|
|
|
$_[0]->attributes->{$_[1]}; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub children_names { |
101
|
0
|
|
|
0
|
1
|
|
my $class = ref($_[0]); |
102
|
0
|
|
|
|
|
|
map { $_->name } grep { ref($_) eq $class } @{$_[0]->contents}; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
# previously deprecated methods value and append_value have been removed. |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
1; |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
__END__ |