| 1 | # $Id$ | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | package XML::Atom::Base; | ||||||||||||||||||||||||||||
| 4 | 22 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 22 | ▶ | use base qw( XML::Atom::ErrorHandler Class::Data::Inheritable ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 22 | ▶ | use Encode; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 22 | ▶ | use XML::Atom; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 22 | ▶ | use XML::Atom::Util qw( set_ns first nodelist childlist create_element ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||
| 11 | 22 | __PACKAGE__->mk_classdata('__attributes', []); | |||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||
| 13 | 215 | ▶ | sub new { | ||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 14 | 215 | my $class = shift; | |||||||||||||||||||||||||||
| 15 | 215 | my $obj = bless {}, $class; | |||||||||||||||||||||||||||
| 16 | 215 | ▶ | $obj->init(@_) or return $class->error($obj->errstr); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 17 | 215 | $obj; | |||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 215 | ▶ | sub init { | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=8 SCAR=20.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 21 | 215 | my $obj = shift; | |||||||||||||||||||||||||||
| 22 | 215 | my %param = @_; | |||||||||||||||||||||||||||
| 23 | 215 | ▶ | if (!exists $param{Namespace} and my $ns = $obj->element_ns) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not exists $param{"Namespace"} and my $ns = $obj->element_ns
MC/DC100%2/2
not exists $param{"Namespace"} and my $ns = $obj->element_ns
not exists $param{"Namespace"}
my $ns = $obj->element_ns
Truth table100%3/3
not(A) and B
A= not exists $param{"Namespace"}B= my $ns = $obj->element_ns
| |||||||||||||||||||||||||||||
| 24 | 3 | $param{Namespace} = $ns; | |||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||
| 26 | 215 | $obj->set_ns(\%param); | |||||||||||||||||||||||||||
| 27 | 215 | my $elem; | |||||||||||||||||||||||||||
| 28 | 215 | ▶ | unless ($elem = $param{Elem}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 29 | 53 | if (LIBXML) { | |||||||||||||||||||||||||||
| 30 | 53 | my $doc = XML::LibXML::Document->createDocument('1.0', 'UTF-8'); | |||||||||||||||||||||||||||
| 31 | 53 | my $ns = $obj->ns; | |||||||||||||||||||||||||||
| 32 | 53 | my ($ns_uri, $ns_prefix); | |||||||||||||||||||||||||||
| 33 | 53 | ▶ | if ( ref $ns and $ns->isa('XML::Atom::Namespace') ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $ns and $ns->isa("XML::Atom::Namespace")
MC/DC50%1/2
ref $ns and $ns->isa("XML::Atom::Namespace")
ref $ns
$ns->isa("XML::Atom::Namespace")
Truth table66%2/3
A and B
A= ref $nsB= $ns->isa("XML::Atom::Namespace")
| |||||||||||||||||||||||||||||
| 34 | 2 | $ns_uri = $ns->{uri}; | |||||||||||||||||||||||||||
| 35 | 2 | $ns_prefix = $ns->{prefix}; | |||||||||||||||||||||||||||
| 36 | } else { | ||||||||||||||||||||||||||||
| 37 | 51 | $ns_uri = $ns; | |||||||||||||||||||||||||||
| 38 | } | ||||||||||||||||||||||||||||
| 39 | 53 | ▶ | if ( $ns_uri and $ns_prefix ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$ns_uri and $ns_prefix
MC/DC50%1/2
$ns_uri and $ns_prefix
$ns_uri
$ns_prefix
Truth table66%2/3
A and B
A= $ns_uriB= $ns_prefix
| |||||||||||||||||||||||||||||
| 40 | 2 | $elem = $doc->createElement($obj->element_name); | |||||||||||||||||||||||||||
| 41 | 2 | $elem->setNamespace( $ns_uri, $ns_prefix, 1 ); | |||||||||||||||||||||||||||
| 42 | } else { | ||||||||||||||||||||||||||||
| 43 | 51 | $elem = $doc->createElementNS($obj->ns, $obj->element_name); | |||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | 53 | $doc->setDocumentElement($elem); | |||||||||||||||||||||||||||
| 46 | } else { | ||||||||||||||||||||||||||||
| 47 | $elem = XML::XPath::Node::Element->new($obj->element_name); | ||||||||||||||||||||||||||||
| 48 | my $ns = XML::XPath::Node::Namespace->new('#default' => $obj->ns); | ||||||||||||||||||||||||||||
| 49 | $elem->appendNamespace($ns); | ||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||
| 52 | 215 | $obj->{elem} = $elem; | |||||||||||||||||||||||||||
| 53 | 215 | $obj; | |||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 0 | ▶ | sub element_name { } | ||||||||||||||||||||||||||
|
Subroutine
element_name: not called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 57 | 176 | ▶ | sub element_ns { } | ||||||||||||||||||||||||||
|
Subroutine
element_ns: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 366 | ▶ | sub ns { $_[0]->{ns} } | ||||||||||||||||||||||||||
|
Subroutine
ns: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 60 | 673 | ▶ | sub elem { $_[0]->{elem} } | ||||||||||||||||||||||||||
|
Subroutine
elem: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 81 | ▶ | sub version { | ||||||||||||||||||||||||||
|
Subroutine
version: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 63 | 81 | my $atom = shift; | |||||||||||||||||||||||||||
| 64 | 81 | XML::Atom::Util::ns_to_version($atom->ns); | |||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | 2 | ▶ | sub content_type { | ||||||||||||||||||||||||||
|
Subroutine
content_type: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 68 | 2 | my $atom = shift; | |||||||||||||||||||||||||||
| 69 | 2 | ▶ | if ($atom->version >= 1.0) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 1 | return "application/atom+xml"; | |||||||||||||||||||||||||||
| 71 | } else { | ||||||||||||||||||||||||||||
| 72 | 1 | return "application/x.atom+xml"; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||
| 76 | 72 | ▶ | sub get { | ||||||||||||||||||||||||||
|
Subroutine
get: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 77 | 72 | my $obj = shift; | |||||||||||||||||||||||||||
| 78 | 72 | my($ns, $name) = @_; | |||||||||||||||||||||||||||
| 79 | 72 | my @list = $obj->getlist($ns, $name); | |||||||||||||||||||||||||||
| 80 | 72 | return $list[0]; | |||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||
| 83 | 73 | ▶ | sub getlist { | ||||||||||||||||||||||||||
|
Subroutine
getlist: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 84 | 73 | my $obj = shift; | |||||||||||||||||||||||||||
| 85 | 73 | my($ns, $name) = @_; | |||||||||||||||||||||||||||
| 86 | 73 | ▶ | my $ns_uri = ref($ns) eq 'XML::Atom::Namespace' ? $ns->{uri} : $ns; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 87 | 73 | my @node = childlist($obj->elem, $ns_uri, $name); | |||||||||||||||||||||||||||
| 88 | return map { | ||||||||||||||||||||||||||||
| 89 | 73 | my $val = LIBXML ? $_->textContent : $_->string_value; | |||||||||||||||||||||||||||
| 90 | 75 | ▶ | if ($] >= 5.008) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 91 | 75 | require Encode; | |||||||||||||||||||||||||||
| 92 | 75 | ▶ | Encode::_utf8_off($val) unless $XML::Atom::ForceUnicode; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||
| 94 | 75 | $val; | |||||||||||||||||||||||||||
| 95 | } @node; | ||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||
| 98 | 1 | ▶ | sub add { | ||||||||||||||||||||||||||
|
Subroutine
add: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 99 | 1 | my $obj = shift; | |||||||||||||||||||||||||||
| 100 | 1 | my($ns, $name, $val, $attr) = @_; | |||||||||||||||||||||||||||
| 101 | 1 | return $obj->set($ns, $name, $val, $attr, 1); | |||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | 43 | ▶ | sub set { | ||||||||||||||||||||||||||
|
Subroutine
set: called CC=11 SCAR=24.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 105 | 43 | my $obj = shift; | |||||||||||||||||||||||||||
| 106 | 43 | my($ns, $name, $val, $attr, $add) = @_; | |||||||||||||||||||||||||||
| 107 | 43 | ▶ | my $ns_uri = ref $ns eq 'XML::Atom::Namespace' ? $ns->{uri} : $ns; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | 43 | my @elem = childlist($obj->elem, $ns_uri, $name); | |||||||||||||||||||||||||||
| 109 | 43 | ▶ | if (!$add && @elem) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not $add and @elem
MC/DC100%2/2
not $add and @elem
not $add
@elem
Truth table100%3/3
not(A) and B
A= not $addB= @elem
| |||||||||||||||||||||||||||||
| 110 | 7 | $obj->elem->removeChild($_) for @elem; | |||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||
| 112 | 43 | my $elem = create_element($ns, $name); | |||||||||||||||||||||||||||
| 113 | 43 | ▶ | if (UNIVERSAL::isa($val, 'XML::Atom::Base')) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | 13 | if (LIBXML) { | |||||||||||||||||||||||||||
| 115 | 13 | for my $child ($val->elem->childNodes) { | |||||||||||||||||||||||||||
| 116 | 15 | $elem->appendChild($child->cloneNode(1)); | |||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||
| 118 | 13 | for my $attr ($val->elem->attributes) { | |||||||||||||||||||||||||||
| 119 | 22 | ▶ | next unless ref($attr) eq 'XML::LibXML::Attr'; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | 9 | $elem->setAttribute($attr->getName, $attr->getValue); | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | } else { | ||||||||||||||||||||||||||||
| 123 | for my $child ($val->elem->getChildNodes) { | ||||||||||||||||||||||||||||
| 124 | $elem->appendChild($child); | ||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | for my $attr ($val->elem->getAttributes) { | ||||||||||||||||||||||||||||
| 127 | $elem->appendAttribute($attr); | ||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||
| 130 | } elsif (DATETIME && UNIVERSAL::isa($val, "DateTime")) { | ||||||||||||||||||||||||||||
| 131 | return $obj->set($ns, $name, DateTime::Format::Atom->format_datetime($val), $attr, $add); | ||||||||||||||||||||||||||||
| 132 | } else { | ||||||||||||||||||||||||||||
| 133 | 30 | if (LIBXML) { | |||||||||||||||||||||||||||
| 134 | 30 | $elem->appendChild(XML::LibXML::Text->new($val)); | |||||||||||||||||||||||||||
| 135 | } else { | ||||||||||||||||||||||||||||
| 136 | $elem->appendChild(XML::XPath::Node::Text->new($val)); | ||||||||||||||||||||||||||||
| 137 | } | ||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||
| 139 | 43 | $obj->elem->appendChild($elem); | |||||||||||||||||||||||||||
| 140 | 43 | ▶ | if ($attr) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 141 | 0 | ▶ | while (my($k, $v) = each %$attr) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 142 | 0 | $elem->setAttribute($k, $v); | |||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||
| 144 | } | ||||||||||||||||||||||||||||
| 145 | 43 | return $val; | |||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||
| 148 | 125 | ▶ | sub get_attr { | ||||||||||||||||||||||||||
|
Subroutine
get_attr: called CC=3 SCAR=11.2
Pod
undocumented
| |||||||||||||||||||||||||||||
| 149 | 125 | my $obj = shift; | |||||||||||||||||||||||||||
| 150 | 125 | my($attr) = @_; | |||||||||||||||||||||||||||
| 151 | 125 | my $val = $obj->elem->getAttribute($attr); | |||||||||||||||||||||||||||
| 152 | 125 | ▶ | if ($] >= 5.008) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 153 | 125 | require Encode; | |||||||||||||||||||||||||||
| 154 | 125 | ▶ | Encode::_utf8_off($val) unless $XML::Atom::ForceUnicode; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | 125 | $val; | |||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | 47 | ▶ | sub set_attr { | ||||||||||||||||||||||||||
|
Subroutine
set_attr: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 160 | 47 | my $obj = shift; | |||||||||||||||||||||||||||
| 161 | 47 | ▶ | if (@_ == 2) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 162 | 45 | my($attr, $val) = @_; | |||||||||||||||||||||||||||
| 163 | 45 | $obj->elem->setAttribute($attr => $val); | |||||||||||||||||||||||||||
| 164 | } elsif (@_ == 3) { | ||||||||||||||||||||||||||||
| 165 | 2 | my($ns, $attr, $val) = @_; | |||||||||||||||||||||||||||
| 166 | 2 | my $attribute = "$ns->{prefix}:$attr"; | |||||||||||||||||||||||||||
| 167 | 2 | if (LIBXML) { | |||||||||||||||||||||||||||
| 168 | 2 | $obj->elem->setAttributeNS($ns->{uri}, $attribute, $val); | |||||||||||||||||||||||||||
| 169 | } else { | ||||||||||||||||||||||||||||
| 170 | my $ns = XML::XPath::Node::Namespace->new( | ||||||||||||||||||||||||||||
| 171 | $ns->{prefix} => $ns->{uri} | ||||||||||||||||||||||||||||
| 172 | ); | ||||||||||||||||||||||||||||
| 173 | $obj->elem->appendNamespace($ns); | ||||||||||||||||||||||||||||
| 174 | $obj->elem->setAttribute($attribute => $val); | ||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 64 | ▶ | sub get_object { | ||||||||||||||||||||||||||
|
Subroutine
get_object: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 180 | 64 | my $obj = shift; | |||||||||||||||||||||||||||
| 181 | 64 | my($ns, $name, $class) = @_; | |||||||||||||||||||||||||||
| 182 | 64 | ▶ | my $ns_uri = ref($ns) eq 'XML::Atom::Namespace' ? $ns->{uri} : $ns; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 183 | 64 | ▶ | my @elem = childlist($obj->elem, $ns_uri, $name) or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 184 | 63 | my @obj = map { $class->new( Elem => $_, Namespace => $ns ) } @elem; | |||||||||||||||||||||||||||
| 185 | 63 | ▶ | return wantarray ? @obj : $obj[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 186 | } | ||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||
| 188 | 97 | ▶ | sub mk_elem_accessors { | ||||||||||||||||||||||||||
|
Subroutine
mk_elem_accessors: called CC=8 SCAR=23.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 189 | 97 | my $class = shift; | |||||||||||||||||||||||||||
| 190 | 97 | my (@list) = @_; | |||||||||||||||||||||||||||
| 191 | 97 | my $override_ns; | |||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||
| 193 | 97 | ▶ | if ( ref $list[-1] ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 194 | 1 | my $ns_list = pop @list; | |||||||||||||||||||||||||||
| 195 | 1 | ▶ | if ( ref $ns_list eq 'ARRAY' ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 196 | 1 | $ns_list = $ns_list->[0]; | |||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||
| 198 | 1 | ▶ | if ( ref($ns_list) =~ /Namespace/ ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 199 | 1 | $override_ns = $ns_list; | |||||||||||||||||||||||||||
| 200 | } else { | ||||||||||||||||||||||||||||
| 201 | 0 | ▶ | if ( ref $ns_list eq 'HASH' ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 202 | 0 | $override_ns = XML::Atom::Namespace->new(%$ns_list); | |||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||
| 204 | ▶ | elsif ( not ref $ns_list and $ns_list ) { | |||||||||||||||||||||||||||
|
Condition0%0/3
not ref $ns_list and $ns_list
MC/DC0%0/2
not ref $ns_list and $ns_list
not ref $ns_list
$ns_list
Truth table0%0/3
not(A) and B
A= not ref $ns_listB= $ns_list
| |||||||||||||||||||||||||||||
| 205 | 0 | $override_ns = $ns_list; | |||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||
| 210 | 22 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 211 | 97 | for my $elem ( @list ) { | |||||||||||||||||||||||||||
| 212 | 232 | (my $meth = $elem) =~ tr/\-/_/; | |||||||||||||||||||||||||||
| 213 | 232 | ▶ | *{"${class}::$meth"} = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=14.0
| |||||||||||||||||||||||||||||
| 214 | 78 | my $obj = shift; | |||||||||||||||||||||||||||
| 215 | 78 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 216 | 25 | ▶ | return $obj->set( $override_ns || $obj->ns, $elem, $_[0]); | ||||||||||||||||||||||||||
|
Condition66%2/3
$override_ns || $obj->ns
MC/DC0%0/2
$override_ns || $obj->ns
$override_ns
$obj->ns
Truth table66%2/3
A || B
A= $override_nsB= $obj->ns
| |||||||||||||||||||||||||||||
| 217 | } else { | ||||||||||||||||||||||||||||
| 218 | 53 | ▶ | return $obj->get( $override_ns || $obj->ns, $elem); | ||||||||||||||||||||||||||
|
Condition66%2/3
$override_ns || $obj->ns
MC/DC0%0/2
$override_ns || $obj->ns
$override_ns
$obj->ns
Truth table66%2/3
A || B
A= $override_nsB= $obj->ns
| |||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||
| 220 | 232 | }; | |||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | 62 | ▶ | sub mk_attr_accessors { | ||||||||||||||||||||||||||
|
Subroutine
mk_attr_accessors: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 225 | 62 | my $class = shift; | |||||||||||||||||||||||||||
| 226 | 62 | my(@list) = @_; | |||||||||||||||||||||||||||
| 227 | 22 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 228 | 62 | for my $attr (@list) { | |||||||||||||||||||||||||||
| 229 | 224 | (my $meth = $attr) =~ tr/\-/_/; | |||||||||||||||||||||||||||
| 230 | 224 | ▶ | *{"${class}::$meth"} = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 231 | 170 | my $obj = shift; | |||||||||||||||||||||||||||
| 232 | 170 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 233 | 45 | return $obj->set_attr($attr => $_[0]); | |||||||||||||||||||||||||||
| 234 | } else { | ||||||||||||||||||||||||||||
| 235 | 125 | return $obj->get_attr($attr); | |||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||
| 237 | 224 | }; | |||||||||||||||||||||||||||
| 238 | 224 | $class->_add_attribute($attr); | |||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||
| 240 | } | ||||||||||||||||||||||||||||
| 241 | |||||||||||||||||||||||||||||
| 242 | 224 | ▶ | sub _add_attribute { | ||||||||||||||||||||||||||
|
Subroutine
_add_attribute: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 243 | 224 | my($class, $attr) = @_; | |||||||||||||||||||||||||||
| 244 | 224 | push @{$class->__attributes}, $attr; | |||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | 4 | ▶ | sub attributes { | ||||||||||||||||||||||||||
|
Subroutine
attributes: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 248 | 4 | my $class = shift; | |||||||||||||||||||||||||||
| 249 | 4 | @{ $class->__attributes }; | |||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||
| 251 | |||||||||||||||||||||||||||||
| 252 | 59 | ▶ | sub mk_xml_attr_accessors { | ||||||||||||||||||||||||||
|
Subroutine
mk_xml_attr_accessors: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 253 | 59 | my($class, @list) = @_; | |||||||||||||||||||||||||||
| 254 | 22 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 255 | 59 | for my $attr (@list) { | |||||||||||||||||||||||||||
| 256 | 118 | (my $meth = $attr) =~ tr/\-/_/; | |||||||||||||||||||||||||||
| 257 | 118 | ▶ | *{"${class}::$meth"} = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 258 | 5 | my $obj = shift; | |||||||||||||||||||||||||||
| 259 | 5 | if (LIBXML) { | |||||||||||||||||||||||||||
| 260 | 5 | my $elem = $obj->elem; | |||||||||||||||||||||||||||
| 261 | 5 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 262 | 1 | $elem->setAttributeNS('http://www.w3.org/XML/1998/namespace', | |||||||||||||||||||||||||||
| 263 | $attr, $_[0]); | ||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||
| 265 | 5 | return $elem->getAttribute("xml:$attr"); | |||||||||||||||||||||||||||
| 266 | } else { | ||||||||||||||||||||||||||||
| 267 | if (@_) { | ||||||||||||||||||||||||||||
| 268 | $obj->elem->setAttribute("xml:$attr", $_[0]); | ||||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||
| 270 | return $obj->elem->getAttribute("xml:$attr"); | ||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||
| 272 | 118 | }; | |||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||
| 276 | 97 | ▶ | sub mk_object_accessor { | ||||||||||||||||||||||||||
|
Subroutine
mk_object_accessor: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 277 | 97 | my $class = shift; | |||||||||||||||||||||||||||
| 278 | 97 | my($name, $ext_class) = @_; | |||||||||||||||||||||||||||
| 279 | 22 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 280 | 97 | (my $meth = $name) =~ tr/\-/_/; | |||||||||||||||||||||||||||
| 281 | 97 | ▶ | *{"${class}::$meth"} = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||
| 282 | 28 | my $obj = shift; | |||||||||||||||||||||||||||
| 283 | 28 | ▶ | my $ns_uri = $ext_class->element_ns || $obj->ns; | ||||||||||||||||||||||||||
|
Condition66%2/3
$ext_class->element_ns || $obj->ns
MC/DC0%0/2
$ext_class->element_ns || $obj->ns
$ext_class->element_ns
$obj->ns
Truth table66%2/3
A || B
A= $ext_class->element_nsB= $obj->ns
| |||||||||||||||||||||||||||||
| 284 | 28 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 285 | 4 | return $obj->set($ns_uri, $name, $_[0]); | |||||||||||||||||||||||||||
| 286 | } else { | ||||||||||||||||||||||||||||
| 287 | 24 | return $obj->get_object($ns_uri, $name, $ext_class); | |||||||||||||||||||||||||||
| 288 | } | ||||||||||||||||||||||||||||
| 289 | 97 | }; | |||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | 78 | ▶ | sub mk_object_list_accessor { | ||||||||||||||||||||||||||
|
Subroutine
mk_object_list_accessor: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||
| 294 | 78 | my $class = shift; | |||||||||||||||||||||||||||
| 295 | 78 | my($name, $ext_class, $moniker) = @_; | |||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||
| 297 | 22 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||
| 299 | 78 | ▶ | *{"$class\::$name"} = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=20.9
| |||||||||||||||||||||||||||||
| 300 | 17 | my $obj = shift; | |||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||
| 302 | 17 | ▶ | my $ns_uri = $ext_class->element_ns || $obj->ns; | ||||||||||||||||||||||||||
|
Condition66%2/3
$ext_class->element_ns || $obj->ns
MC/DC0%0/2
$ext_class->element_ns || $obj->ns
$ext_class->element_ns
$obj->ns
Truth table66%2/3
A || B
A= $ext_class->element_nsB= $obj->ns
| |||||||||||||||||||||||||||||
| 303 | 17 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 304 | # setter: clear existent elements first | ||||||||||||||||||||||||||||
| 305 | 0 | my @elem = childlist($obj->elem, $ns_uri, $name); | |||||||||||||||||||||||||||
| 306 | 0 | for my $el (@elem) { | |||||||||||||||||||||||||||
| 307 | 0 | $obj->elem->removeChild($el); | |||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||
| 310 | # add the new elements for each | ||||||||||||||||||||||||||||
| 311 | 0 | my $adder = "add_$name"; | |||||||||||||||||||||||||||
| 312 | 0 | for my $add_elem (@_) { | |||||||||||||||||||||||||||
| 313 | 0 | $obj->$adder($add_elem); | |||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||
| 315 | } else { | ||||||||||||||||||||||||||||
| 316 | # getter: just call get_object which is a context aware | ||||||||||||||||||||||||||||
| 317 | 17 | return $obj->get_object($ns_uri, $name, $ext_class); | |||||||||||||||||||||||||||
| 318 | } | ||||||||||||||||||||||||||||
| 319 | 78 | }; | |||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||
| 321 | # moniker returns always list: array ref in a scalar context | ||||||||||||||||||||||||||||
| 322 | 78 | ▶ | if ($moniker) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 323 | 76 | ▶ | *{"$class\::$moniker"} = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.8
| |||||||||||||||||||||||||||||
| 324 | 5 | my $obj = shift; | |||||||||||||||||||||||||||
| 325 | 5 | ▶ | if (@_) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 326 | 0 | return $obj->$name(@_); | |||||||||||||||||||||||||||
| 327 | } else { | ||||||||||||||||||||||||||||
| 328 | 5 | my @obj = $obj->$name; | |||||||||||||||||||||||||||
| 329 | 5 | ▶ | return wantarray ? @obj : \@obj; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 330 | } | ||||||||||||||||||||||||||||
| 331 | 76 | }; | |||||||||||||||||||||||||||
| 332 | } | ||||||||||||||||||||||||||||
| 333 | |||||||||||||||||||||||||||||
| 334 | # add_$name | ||||||||||||||||||||||||||||
| 335 | 78 | ▶ | *{"$class\::add_$name"} = sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||
| 336 | 10 | my $obj = shift; | |||||||||||||||||||||||||||
| 337 | 10 | my($stuff) = @_; | |||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||
| 339 | 10 | ▶ | my $ns_uri = $ext_class->element_ns || $obj->ns; | ||||||||||||||||||||||||||
|
Condition66%2/3
$ext_class->element_ns || $obj->ns
MC/DC0%0/2
$ext_class->element_ns || $obj->ns
$ext_class->element_ns
$obj->ns
Truth table66%2/3
A || B
A= $ext_class->element_nsB= $obj->ns
| |||||||||||||||||||||||||||||
| 340 | 10 | ▶ | my $elem = (ref $stuff && UNIVERSAL::isa($stuff, $ext_class)) ? | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $stuff and UNIVERSAL::isa($stuff, $ext_class)
MC/DC50%1/2
ref $stuff and UNIVERSAL::isa($stuff, $ext_class)
ref $stuff
UNIVERSAL::isa($stuff, $ext_class)
Truth table66%2/3
A and B
A= ref $stuffB= UNIVERSAL::isa($stuff, $ext_class)
| |||||||||||||||||||||||||||||
| 341 | $stuff->elem : create_element($ns_uri, $name); | ||||||||||||||||||||||||||||
| 342 | 10 | $obj->elem->appendChild($elem); | |||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||
| 344 | 10 | ▶ | if (ref($stuff) eq 'HASH') { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 345 | 4 | for my $k ( $ext_class->attributes ) { | |||||||||||||||||||||||||||
| 346 | 44 | ▶ | defined $stuff->{$k} or next; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 347 | 11 | $elem->setAttribute($k, $stuff->{$k}); | |||||||||||||||||||||||||||
| 348 | } | ||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||
| 350 | 78 | }; | |||||||||||||||||||||||||||
| 351 | } | ||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||
| 353 | 28 | ▶ | sub as_xml { | ||||||||||||||||||||||||||
|
Subroutine
as_xml: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 354 | 28 | my $obj = shift; | |||||||||||||||||||||||||||
| 355 | 28 | if (LIBXML) { | |||||||||||||||||||||||||||
| 356 | 28 | my $doc = XML::LibXML::Document->new('1.0', 'UTF-8'); | |||||||||||||||||||||||||||
| 357 | 28 | $doc->setDocumentElement($obj->elem->cloneNode(1)); | |||||||||||||||||||||||||||
| 358 | 28 | return $doc->toString(1); | |||||||||||||||||||||||||||
| 359 | } else { | ||||||||||||||||||||||||||||
| 360 | return '<?xml version="1.0" encoding="UTF-8"?>' . "\n" . | ||||||||||||||||||||||||||||
| 361 | $obj->elem->toString; | ||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||
| 365 | 1 | ▶ | sub as_xml_utf8 { | ||||||||||||||||||||||||||
|
Subroutine
as_xml_utf8: called CC=2 SCAR=7.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 366 | 1 | my $obj = shift; | |||||||||||||||||||||||||||
| 367 | 1 | my $xml = $obj->as_xml; | |||||||||||||||||||||||||||
| 368 | 1 | ▶ | if (utf8::is_utf8($xml)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 369 | 0 | return Encode::encode_utf8($xml); | |||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||
| 371 | 1 | return $xml; | |||||||||||||||||||||||||||
| 372 | } | ||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||
| 374 | 22 | 1; | |||||||||||||||||||||||||||