| 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 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 45 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 6 | 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 | 4 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=5 SCAR=18.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 63 | 4 | my ($class, $xml, $type, %args) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 64 | return undef | ||||||||||||||||||||||||||||||||||||||||||
| 65 | 4 | ▶ | unless($xml && ref($xml) && UNIVERSAL::isa($xml, "XML::TinyXML")); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
$xml and ref $xml and UNIVERSAL::isa($xml, "XML::TinyXML")
$xml and ref $xml
MC/DC0%0/3
$xml and ref $xml and UNIVERSAL::isa($xml, "XML::TinyXML")
$xml
ref $xml
UNIVERSAL::isa($xml, "XML::TinyXML")
Truth table25%1/4
A and B and C
A= $xmlB= ref $xmlC= UNIVERSAL::isa($xml, "XML::TinyXML")
| |||||||||||||||||||||||||||||||||||||||||||
| 66 | 4 | my $module = __PACKAGE__ . "::" . $type; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 4 | ▶ | if (eval "require $module; 1") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 4 | my $self = {}; | |||||||||||||||||||||||||||||||||||||||||
| 69 | 4 | bless($self, $module); | |||||||||||||||||||||||||||||||||||||||||
| 70 | 4 | $self->{_xml} = $xml; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 4 | return $self->init(%args); | |||||||||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | return undef; | |||||||||||||||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | sub init { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
init: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 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 | 0 | ▶ | sub select { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
select: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | die __PACKAGE__." You MUST Override Me!!" | |||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 6 | 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, E<lt>xant@cpan.orgE<gt> | ||||||||||||||||||||||||||||||||||||||||||
| 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 | ||||||||||||||||||||||||||||||||||||||||||