line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
# -*- tab-width: 4 -*- |
2
|
|
|
|
|
|
|
# ex: set tabstop=4: |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
=head1 NAME |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
XML::TinyXML::Selector - Tinyxml Selector base class |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
=head1 SYNOPSIS |
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=over 4 |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
use XML::TinyXML; |
13
|
|
|
|
|
|
|
use XML::TinyXML::Selector; |
14
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
# first obtain an xml context: |
16
|
|
|
|
|
|
|
$xml = XML::TinyXML->new("rootnode", param => "somevalue", attrs => { attr1 => "v1", attr2 => "v2" }); |
17
|
|
|
|
|
|
|
$selector = XML::TinyXML::Selector->new($xml, "XPath"); # create an xpath selector; |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
my @attributes = $selector->select("attribute::*"); |
20
|
|
|
|
|
|
|
or |
21
|
|
|
|
|
|
|
my $attr2 = $selector->select("attribute::attr2"); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
# Check XML::TinyXML::Selector::XPath documentation for more xpath-specific examples |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
=back |
26
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
=head1 DESCRIPTION |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
Selector base class |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=head1 INSTANCE VARIABLES |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=over 4 |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=back |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 METHODS |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=over 4 |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=cut |
42
|
|
|
|
|
|
|
package XML::TinyXML::Selector; |
43
|
|
|
|
|
|
|
|
44
|
6
|
|
|
6
|
|
6377
|
use strict; |
|
6
|
|
|
|
|
10
|
|
|
6
|
|
|
|
|
225
|
|
45
|
6
|
|
|
6
|
|
31
|
use warnings; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
1406
|
|
46
|
|
|
|
|
|
|
our $VERSION = '0.34'; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=item * new ($xml, $type, %args) |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
Creates a new XML::TinyXML::Selector::$type object. |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
$xml must be a valid XML::TinyXML instance |
53
|
|
|
|
|
|
|
$type must be a known selector $type |
54
|
|
|
|
|
|
|
%args will be passed to the specific selector initializer |
55
|
|
|
|
|
|
|
(for instance to XML::TinyXML::Selector::XPath |
56
|
|
|
|
|
|
|
if using the xpath selector) |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
Returns a valid XML::TinyXML::Node object |
59
|
|
|
|
|
|
|
Returns undef is $type is not known or if $xml is not a valid instance |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
=cut |
62
|
|
|
|
|
|
|
sub new { |
63
|
4
|
|
|
4
|
1
|
64
|
my ($class, $xml, $type, %args) = @_; |
64
|
|
|
|
|
|
|
return undef |
65
|
4
|
50
|
33
|
|
|
67
|
unless($xml && ref($xml) && UNIVERSAL::isa($xml, "XML::TinyXML")); |
|
|
|
33
|
|
|
|
|
66
|
4
|
|
|
|
|
14
|
my $module = __PACKAGE__ . "::" . $type; |
67
|
4
|
50
|
|
|
|
427
|
if (eval "require $module; 1") { |
68
|
4
|
|
|
|
|
155
|
my $self = {}; |
69
|
4
|
|
|
|
|
17
|
bless($self, $module); |
70
|
4
|
|
|
|
|
36
|
$self->{_xml} = $xml; |
71
|
4
|
|
|
|
|
27
|
return $self->init(%args); |
72
|
|
|
|
|
|
|
} |
73
|
0
|
|
|
|
|
|
return undef; |
74
|
|
|
|
|
|
|
} |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub init { |
77
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
78
|
|
|
|
|
|
|
# this is an optional method. Just return $self |
79
|
|
|
|
|
|
|
# if not overridden by a subclass implementation |
80
|
0
|
|
|
|
|
|
return $self; |
81
|
|
|
|
|
|
|
} |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
sub select { |
84
|
0
|
|
|
0
|
0
|
|
die __PACKAGE__." You MUST Override Me!!" |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
1; |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
=back |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
=head1 SEE ALSO |
92
|
|
|
|
|
|
|
|
93
|
|
|
|
|
|
|
=over 4 |
94
|
|
|
|
|
|
|
|
95
|
|
|
|
|
|
|
XML::TinyXML |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
=back |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=head1 AUTHOR |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
xant, Exant@cpan.orgE |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
Copyright (C) 2008-2010 by xant |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
108
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.8.8 or, |
109
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=cut |