| 1 | package XML::Loy; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 21 | ▶ | use Mojo::ByteStream 'b'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 21 | ▶ | use Mojo::Loader qw/load_class/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 21 | ▶ | use Carp qw/croak carp/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 21 | ▶ | use Scalar::Util qw/blessed weaken/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 21 | ▶ | use Mojo::Base 'Mojo::DOM'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 21 | our $VERSION = '0.50'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | sub DESTROY; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | # TODO: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | # - Support Mojolicious version > 7.77 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | # - "ns|*" namespace selector | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | # - Add ->clone | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | # (Maybe via JSON serialisation of ->tree or using Storable or Dumper) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | # Maybe necessary: *AUTOLOAD = \&XML::Loy::AUTOLOAD; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | # - sub try_further { }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | # # usage: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | # sub author { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | # return $autor or $self->try_further; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | # }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # - ALERT! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # Do not allow for namespace islands | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | # Search $obj->find('* *[xmlns]') and change prefixing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | # After ->SUPER::new; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | # Or: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | # Do allow for namespace islands and check for the | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | # namespace to add instead of the package name before | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | # prefixing. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | # - set() should really try to overwrite. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | # - add() with -before => '' and -after => '' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | # - maybe possible to save to element | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | # - Maybe with small changes a change to the object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | # (encoding, xml etc.) can be done | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | # | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | # - closest() (jQuery) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 21 | our @CARP_NOT; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | # Import routine, run when calling the class properly | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | sub import { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 54 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=7 SCAR=19.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 54 | ▶ | return unless my $flag = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 27 | ▶ | return unless $flag =~ /^-?(?i:base|with)$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | # Allow for manipulating the symbol table | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 21 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 21 | ▶ | no warnings 'once'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | # The caller is the calling (inheriting) class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 26 | my $caller = caller; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 26 | push @{"${caller}::ISA"}, __PACKAGE__; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 26 | ▶ | if (@_) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | # Get class variables | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | 25 | my %param = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | # Set class variables | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 25 | foreach (qw/namespace prefix mime/) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 75 | ▶ | if (exists $param{$_}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | 63 | ${ "${caller}::" . uc $_ } = delete $param{$_}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | # Set class hook | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 25 | ▶ | if (exists $param{on_init}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 2 | *{"${caller}::ON_INIT"} = delete $param{on_init}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | # Make inheriting classes strict and modern | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 26 | strict->import; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 26 | warnings->import; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 26 | utf8->import; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 26 | feature->import(':5.10'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | # Return class variables | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 21 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 635 | ▶ | sub _namespace { ${"${_[0]}::NAMESPACE"} || '' }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_namespace: called CC=2 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 57 | ▶ | sub _prefix { ${"${_[0]}::PREFIX"} || '' }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_prefix: called CC=2 SCAR=7.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | sub mime { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 6 | ▶ | ${ (blessed $_[0] || $_[0]) . '::MIME'} || 'application/xml' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
mime: called CC=3 SCAR=11.1
Pod
documented
Branch: 1 branch
Condition66%2/3
builtin::blessed($_[0]) || $_[0]
MC/DC0%0/2
builtin::blessed($_[0]) || $_[0]
builtin::blessed($_[0])
$_[0]
Truth table66%2/3
A || B
A= builtin::blessed($_[0])B= $_[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | sub _on_init { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 1684 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_on_init: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 1684 | my $self = $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | # Run object method | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 1684 | ▶ | if (blessed $class) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 1672 | $class = blessed $class; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | # Run class method | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 12 | $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | # Run init hook | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | 1684 | ▶ | if ($class->can('ON_INIT')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | 525 | *{"${class}::ON_INIT"}->($self) ; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 21 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | # Construct new XML::Loy object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | sub new { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 1670 | ▶ | my $class = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=11 SCAR=24.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 1670 | my $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | # Create from parent class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | # Empty constructor | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 1670 | ▶ | unless ($_[0]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | 1086 | $self = $class->SUPER::new->xml(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | # XML::Loy object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | elsif (ref $_[0]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 1 | $self = $class->SUPER::new(@_)->xml(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | # XML string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | ▶ | elsif (index($_[0],'<') >= 0 || index($_[0],' ') >= 0) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
index($_[0], "<") != -1 or index($_[0], " ") != -1
MC/DC50%1/2
index($_[0], "<") != -1 or index($_[0], " ") != -1
index($_[0], "<") != -1
index($_[0], " ") != -1
Truth table66%2/3
A or B
A= index($_[0], "<") != -1B= index($_[0], " ") != -1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 17 | $self = $class->SUPER::new->xml(1)->parse(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | # Create a new node | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 566 | my $name = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 566 | ▶ | my $att = ref( $_[0] ) eq 'HASH' ? shift : +{}; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 566 | my ($text, $comment) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 566 | $att->{'xmlns:loy'} = 'http://sojolicious.example/ns/xml-loy'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | # Transform special attributes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 566 | ▶ | _special_attributes($att) if $att; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | # Create root | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 566 | my $tree = [ | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | 'root', | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | [ pi => 'xml version="1.0" encoding="UTF-8" standalone="yes"'] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | # Add comment if given | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | 566 | ▶ | push(@$tree, [ comment => $comment ]) if $comment; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | # Create Tag element | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | 566 | my $element = [ tag => $name, $att, $tree ]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | # Add element | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 566 | push(@$tree, $element); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | # Add text if given | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 566 | ▶ | push(@$element, [ text => $text ]) if defined $text; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | # Create root element by parent class | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 566 | $self = $class->SUPER::new->xml(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | # Add newly created tree | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 566 | $self->tree($tree); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | # The class is derived | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 566 | ▶ | if ($class ne __PACKAGE__) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | # Set namespace if given | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | 536 | ▶ | if (my $ns = $class->_namespace) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 27 | $att->{xmlns} = $ns; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | # Start init hook | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 1670 | $self->_on_init; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | # Return root node | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 1670 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | # Append a new child node to the XML Node | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | sub add { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 152 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add: called CC=12 SCAR=25.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | # Store tag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 152 | my $tag = $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | # If node is root, use first element | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | 152 | ▶ | if (!$self->parent && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition77%7/9
not $self->parent and ref $self->tree->[1] and ref $self->tree->[1] eq "ARRAY" and $self->tree->[1][0] eq "pi"
not $self->parent and ref $self->tree->[1] and ref $self->tree->[1] eq "ARRAY"
not $self->parent and ref $self->tree->[1]
MC/DC50%2/4
not $self->parent and ref $self->tree->[1] and ref $self->tree->[1] eq "ARRAY" and $self->tree->[1][0] eq "pi"
not $self->parent
ref $self->tree->[1]
ref $self->tree->[1] eq "ARRAY"
$self->tree->[1][0] eq "pi"
Truth table60%3/5
not(A) and B and C and D
A= not $self->parentB= ref $self->tree->[1]C= ref $self->tree->[1] eq "ARRAY"D= $self->tree->[1][0] eq "pi"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | ref($self->tree->[1]) && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | ref($self->tree->[1]) eq 'ARRAY' && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | $self->tree->[1]->[0] eq 'pi') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 90 | $self = $self->at('*'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | # Add element | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | 152 | ▶ | my $element = $self->_add_clean(@_) or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | 146 | my $tree = $element->tree; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | # Prepend with no prefix | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 146 | ▶ | if (index($tag, '-') == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | 4 | $tree->[1] = substr($tag, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | 4 | return $element; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | # Element is no tag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 142 | ▶ | return $element unless $tree->[0] eq 'tag'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | # Prepend prefix if necessary | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | 142 | my $caller = caller; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | 142 | my $class = ref $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | # Caller and class are not the same | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 142 | ▶ | if ($caller ne $class && $caller->can('_prefix')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$caller ne $class and $caller->can("_prefix")
MC/DC100%2/2
$caller ne $class and $caller->can("_prefix")
$caller ne $class
$caller->can("_prefix")
Truth table100%3/3
A and B
A= $caller ne $classB= $caller->can("_prefix")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 24 | ▶ | if ((my $prefix = $caller->_prefix) && $caller->_namespace) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
my $prefix = $caller->_prefix and $caller->_namespace
MC/DC0%0/2
my $prefix = $caller->_prefix and $caller->_namespace
my $prefix = $caller->_prefix
$caller->_namespace
Truth table33%1/3
A and B
A= my $prefix = $caller->_prefixB= $caller->_namespace
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 24 | $element->tree->[1] = "${prefix}:$tag"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | # Return element | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | 142 | return $element; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | # Append a child only once to the XML node. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | sub set { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 52 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
set: called CC=12 SCAR=25.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 52 | my $tag; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | # If node is root, use first element | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | 52 | ▶ | if (!$self->parent && $self->tree->[1]->[0] eq 'pi') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not $self->parent and $self->tree->[1][0] eq "pi"
MC/DC50%1/2
not $self->parent and $self->tree->[1][0] eq "pi"
not $self->parent
$self->tree->[1][0] eq "pi"
Truth table66%2/3
not(A) and B
A= not $self->parentB= $self->tree->[1][0] eq "pi"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | 31 | $self = $self->at('*'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | # Get tag from document object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | 52 | ▶ | if (ref $_[0]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 4 | $tag = $_[0]->at('*')->tag; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | # Get tag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | # Store tag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | 48 | $tag = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | # No prefix | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 48 | ▶ | if (index($tag, '-') == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | $tag = substr($tag, 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | # Maybe prefix | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | # Prepend prefix if necessary | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | 48 | my $caller = caller; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 48 | my $class = ref $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | # Caller and class are not the same | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 48 | ▶ | if ($caller ne $class && $caller->can('_prefix')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$caller ne $class and $caller->can("_prefix")
MC/DC100%2/2
$caller ne $class and $caller->can("_prefix")
$caller ne $class
$caller->can("_prefix")
Truth table100%3/3
A and B
A= $caller ne $classB= $caller->can("_prefix")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 21 | ▶ | if ((my $prefix = $caller->_prefix) && $caller->_namespace) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
my $prefix = $caller->_prefix and $caller->_namespace
MC/DC0%0/2
my $prefix = $caller->_prefix and $caller->_namespace
my $prefix = $caller->_prefix
$caller->_namespace
Truth table33%1/3
A and B
A= my $prefix = $caller->_prefixB= $caller->_namespace
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 21 | $tag = "${prefix}:$tag"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | 52 | my $att = $self->tree->[2]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | # Introduce attribute 'once' | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 52 | ▶ | $att->{'loy:once'} //= ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$att->{"loy:once"} //= ""
MC/DC100%1/1
$att->{"loy:once"} //= ""
$att->{"loy:once"}
Truth table100%2/2
A
A= $att->{"loy:once"}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | # Check if set to once | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | 52 | ▶ | if (index($att->{'loy:once'}, "($tag)") >= 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | # Todo: Maybe escaping - check in extensions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 13 | $self->children("$tag")->map('remove'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | # Set if not already set | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | 39 | $att->{'loy:once'} .= "($tag)"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | # Add a ref, not the tag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 52 | ▶ | unshift(@_, $tag) unless blessed $_[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | # Add element (Maybe prefixed) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 52 | return $self->_add_clean(@_); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | # Children of the node | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | sub children { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 282 | ▶ | my ($self, $type) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
children: called CC=15 SCAR=27.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | # This method is a modified version of | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | # the children method of Mojo::DOM | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | # It works as written in the documentation, | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | # but is also aware of namespace prefixes. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | # If node is root, use first element | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | 282 | ▶ | if (!$self->parent && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition77%7/9
not $self->parent and ref $self->tree->[1] and ref $self->tree->[1] eq "ARRAY" and $self->tree->[1][0] eq "pi"
not $self->parent and ref $self->tree->[1] and ref $self->tree->[1] eq "ARRAY"
not $self->parent and ref $self->tree->[1]
MC/DC50%2/4
not $self->parent and ref $self->tree->[1] and ref $self->tree->[1] eq "ARRAY" and $self->tree->[1][0] eq "pi"
not $self->parent
ref $self->tree->[1]
ref $self->tree->[1] eq "ARRAY"
$self->tree->[1][0] eq "pi"
Truth table60%3/5
not(A) and B and C and D
A= not $self->parentB= ref $self->tree->[1]C= ref $self->tree->[1] eq "ARRAY"D= $self->tree->[1][0] eq "pi"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | ref($self->tree->[1]) && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | ref($self->tree->[1]) eq 'ARRAY' && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | $self->tree->[1]->[0] eq 'pi') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 21 | $self = $self->at('*'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 282 | my @children; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | 282 | my $xml = $self->xml; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 282 | my $tree = $self->tree; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 282 | ▶ | my $type_l = $type ? length $type : 0; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 282 | ▶ | for my $e (@$tree[($tree->[0] eq 'root' ? 1 : 4) .. $#$tree]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | # Make sure child is the right type | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 1083 | ▶ | next unless $e->[0] eq 'tag'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | # Type is given | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 941 | ▶ | if (defined $type) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | # Type is already prefixed or element is not prefixed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | 291 | ▶ | if (index($type, ':') > 0 || index($e->[1], ':') < 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition100%3/3
index($type, ":") > 0 or index($e->[1], ":") == -1
MC/DC100%2/2
index($type, ":") > 0 or index($e->[1], ":") == -1
index($type, ":") > 0
index($e->[1], ":") == -1
Truth table100%3/3
A or B
A= index($type, ":") > 0B= index($e->[1], ":") == -1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 252 | ▶ | next if $e->[1] ne $type; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | # Check, if type is valid, and ignore prefixes, cause tag is prefixed | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | elsif (index($e->[1], ':') > 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | 39 | ▶ | next if substr($e->[1], (index($e->[1], ':') + 1)) ne $type; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | 733 | push(@children, $self->new->tree($e)->xml($xml)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | # Create new Mojo::Collection | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 282 | return Mojo::Collection->new( @children ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | # Append a new child node to the XML Node | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | sub _add_clean { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 204 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_add_clean: called CC=14 SCAR=26.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | # Node is a node object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 204 | ▶ | if (ref $_[0]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | # Serialize node | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | 10 | my $node = $self->SUPER::new->xml(1)->tree( shift->tree ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | # Get root attributes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | 10 | my $root_attr = $node->_root_element->[2]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | # Push namespaces to new root | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 10 | foreach ( grep( index($_, 'xmlns:') == 0, keys %$root_attr ) ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | # Strip xmlns prefix | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 10 | $_ = substr($_, 6); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | # Add namespace | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | 10 | $self->namespace( $_ => delete $root_attr->{ "xmlns:$_" } ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | # Delete namespace information, if already set | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | 10 | ▶ | if (exists $root_attr->{xmlns}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | # Namespace information can be deleted | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | 5 | ▶ | if (my $ns = $self->namespace) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 5 | ▶ | delete $root_attr->{xmlns} if $root_attr->{xmlns} eq $ns; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | # Get root of parent node | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 10 | my $base_root_attr = $self->_root_element->[2]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | # Copy extensions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | 10 | ▶ | if (exists $root_attr->{'loy:ext'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | my $ext = $base_root_attr->{'loy:ext'}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | $base_root_attr->{'loy:ext'} = | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | 0 | join('; ', $ext, split(/;\s/, delete $root_attr->{'loy:ext'})); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | # Delete pi from node | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 10 | my $sec = $node->tree->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 10 | ▶ | if (ref $sec eq 'ARRAY' && $sec->[0] eq 'pi') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $sec eq "ARRAY" and $sec->[0] eq "pi"
MC/DC50%1/2
ref $sec eq "ARRAY" and $sec->[0] eq "pi"
ref $sec eq "ARRAY"
$sec->[0] eq "pi"
Truth table66%2/3
A and B
A= ref $sec eq "ARRAY"B= $sec->[0] eq "pi"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 9 | splice( @{ $node->tree }, 1,1 ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | # Append new node | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 10 | $self->append_content($node); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | # Return first child | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | 10 | return $self->children->[-1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | # Node is a string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | 194 | my $name = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | # Pretty sloppy check for valid names | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 194 | ▶ | return unless $name =~ m!^-?[^\s<>]+$!; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 192 | ▶ | my $att = shift if ref( $_[0] ) eq 'HASH'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | 192 | my ($text, $comment) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | # Node content with text | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | 192 | my $string = "<$name"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | 192 | ▶ | if (defined $text) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | 113 | $string .= '>' . b($text)->trim->xml_escape . "</$name>"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | # Empty element | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 79 | $string .= ' />'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | # Append new node | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | 192 | $self->append_content( $string ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | # Get first child | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 192 | my $node = $self->children->[-1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | # Attributes were given | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | 192 | ▶ | if ($att) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | # Transform special attributes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 85 | _special_attributes($att); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | # Add attributes to node | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 85 | $node->attr($att); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | # Add comment | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 189 | ▶ | $node->comment($comment) if $comment; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | 189 | return $node; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | # Transform special attributes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | sub _special_attributes { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | 651 | ▶ | my $att = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_special_attributes: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 651 | foreach ( grep { index($_, '-') == 0 } keys %$att ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | # Set special attribute | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 15 | $att->{'loy:' . substr($_, 1) } = lc delete $att->{$_}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | # Prepend a comment to the XML node | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | sub comment { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | 22 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
comment: called CC=6 SCAR=18.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | 22 | my $parent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | # If node is root, use first element | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | 22 | ▶ | return $self unless $parent = $self->parent; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | # Find previous sibling | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 22 | my $previous; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | # Find previous node | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 22 | for my $e (@{$parent->tree}) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 146 | ▶ | last if $e eq $self->tree; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 124 | $previous = $e; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | # Trim and encode comment text | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | 22 | my $comment_text = b( shift )->trim->xml_escape; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | # Add to previous comment | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | 22 | ▶ | if ($previous && $previous->[0] eq 'comment') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$previous and $previous->[0] eq "comment"
MC/DC50%1/2
$previous and $previous->[0] eq "comment"
$previous
$previous->[0] eq "comment"
Truth table66%2/3
A and B
A= $previousB= $previous->[0] eq "comment"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 7 | $previous->[1] .= '; ' . $comment_text; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | # Create new comment node | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 15 | $self->prepend("<!--$comment_text-->"); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | # Return node | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | 22 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | # Add extension to document | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | sub extension { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | 130 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
extension: called CC=11 SCAR=26.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | # Get root element | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | 130 | my $root = $self->_root_element; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | # No root to associate extension to | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | 130 | ▶ | unless ($root) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | 0 | carp 'There is no document to associate the extension with'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | # Get ext string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | 130 | ▶ | my @ext = split(/;\s/, $root->[2]->{'loy:ext'} || ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$root->[2]{'loy:ext'} || ''
MC/DC100%1/1
$root->[2]{'loy:ext'} || ''
$root->[2]{'loy:ext'}
Truth table100%2/2
A
A= $root->[2]{'loy:ext'}
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | 130 | ▶ | return @ext unless $_[0]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | # New Loader | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | # my $loader = Mojo::Loader->new; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | # Try all given extension names | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | 11 | ▶ | while (my $ext = shift( @_ )) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | 12 | ▶ | next if grep { $ext eq $_ } @ext; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | # Default 'XML::Loy::' prefix | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | 12 | ▶ | if (index($ext, '-') == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 6 | $ext =~ s/^-/XML::Loy::/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | # Unable to load extension | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | 12 | ▶ | if (my $e = load_class $ext) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | 0 | ▶ | carp "Exception: $e" if ref $e; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | 0 | carp qq{Unable to load extension "$ext"}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | # Add extension to extensions list | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | 12 | push(@ext, $ext); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | # Start init hook | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 12 | $ext->_on_init($self); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 12 | ▶ | if ((my $n_ns = $ext->_namespace) && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
my $n_ns = $ext->_namespace and my $n_pref = $ext->_prefix
MC/DC0%0/2
my $n_ns = $ext->_namespace and my $n_pref = $ext->_prefix
my $n_ns = $ext->_namespace
my $n_pref = $ext->_prefix
Truth table33%1/3
A and B
A= my $n_ns = $ext->_namespaceB= my $n_pref = $ext->_prefix
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | (my $n_pref = $ext->_prefix)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | 12 | $root->[2]->{"xmlns:$n_pref"} = $n_ns; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 552 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 553 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 555 | # Save extension list as attribute | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 556 | 11 | $root->[2]->{'loy:ext'} = join('; ', @ext); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 558 | 11 | return $self; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 559 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 561 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 562 | # Get or add namespace to root | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 563 | sub namespace { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 564 | 589 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
namespace: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 566 | # Get namespace | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 567 | 589 | ▶ | unless ($_[0]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 568 | 50 | ▶ | return $self->SUPER::namespace || undef; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$self->SUPER::namespace || undef
MC/DC100%1/1
$self->SUPER::namespace || undef
$self->SUPER::namespace
Truth table100%2/2
A
A= $self->SUPER::namespace
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 569 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 571 | 539 | my $ns = pop; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 572 | 539 | my $prefix = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 574 | # Get root element | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 575 | 539 | my $root = $self->_root_element; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 577 | # No warning, but not able to set | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 578 | 539 | ▶ | return unless $root; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 579 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 580 | # Save namespace as attribute | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 581 | 539 | ▶ | $root->[2]->{'xmlns' . ($prefix ? ":$prefix" : '')} = $ns; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 582 | 539 | return $prefix; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 583 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 586 | # As another object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 587 | sub as { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 588 | 2 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as: called CC=6 SCAR=22.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 590 | # Base object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 591 | 2 | my $base = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 593 | # Default 'XML::Loy::' prefix | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 594 | 2 | ▶ | if (index($base, '-') == 0) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 595 | 0 | for ($base) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 597 | # Was Loy prefix | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 598 | 0 | s/^-Loy$/XML::Loy/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 599 | 0 | s/^-/XML::Loy::/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 600 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 601 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 603 | # Unable to load extension | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 604 | 2 | ▶ | if (my $e = load_class $base) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 605 | 0 | ▶ | carp "Exception: $e" if ref $e; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 606 | 0 | carp qq{Unable to load base class "$e"}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 607 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 608 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 609 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 610 | # Create new base document | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 611 | 2 | my $xml = $base->new( $self->to_string ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 613 | # Start init hook | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 614 | 2 | $xml->_on_init; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 616 | # Set base namespace | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 617 | 2 | ▶ | if ($base->_namespace) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 618 | 2 | $xml->namespace( $base->_namespace ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 619 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 620 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 621 | # Delete extension information | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 622 | $xml->find('*[loy\:ext]')->each( | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 623 | sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 624 | 0 | ▶ | delete $_->{attrs}->{'loy:ext'} | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 625 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 626 | 2 | ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 627 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 628 | # Add extensions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 629 | 2 | $xml->extension( @_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 630 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 631 | # Return XML document | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 632 | 2 | return $xml; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 633 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 634 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 635 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 636 | # Render as pretty xml | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 637 | sub to_pretty_xml { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 638 | 76 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_pretty_xml: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 639 | 76 | ▶ | return _render_pretty( shift // 0, $self->tree); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
shift() // 0
MC/DC100%1/1
shift() // 0
shift()
Truth table100%2/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 640 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 641 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 642 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 643 | # Render subtrees with pretty printing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 644 | sub _render_pretty { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 645 | 348 | ▶ | my $i = shift; # Indentation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_render_pretty: called CC=11 SCAR=24.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 646 | 348 | my $tree = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 647 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 648 | 348 | my $e = $tree->[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 649 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 650 | # No element | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 651 | 348 | ▶ | croak('No element') and return unless $e; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition20%1/5
$e || croak('No element') && (return)
croak("No element") and return
MC/DC0%0/2
$e || croak('No element') && (return)
$e
croak("No element")
Truth table33%1/3
A || B
A= $eB= croak("No element")
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 652 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 653 | # Element is tag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 654 | 348 | ▶ | if ($e eq 'tag') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 655 | my $subtree = [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 656 | 172 | @{ $tree }[ 0 .. 2 ], | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 657 | [ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 658 | 172 | @{ $tree }[ 4 .. $#$tree ] | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 659 | ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 660 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 661 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 662 | 172 | return _element($i, $subtree); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 663 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 664 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 665 | # Element is text | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 666 | elsif ($e eq 'text') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 667 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 668 | 5 | my $escaped = $tree->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 669 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 670 | 5 | for ($escaped) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 671 | 5 | ▶ | next unless $_; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 672 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 673 | # Escape and trim whitespaces from both ends | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 674 | 5 | $_ = b($_)->xml_escape->trim; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 675 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 676 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 677 | 5 | return $escaped; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 678 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 679 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 680 | # Element is comment | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 681 | elsif ($e eq 'comment') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 682 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 683 | # Padding for every line | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 684 | 31 | my $p = ' ' x $i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 685 | 31 | my $comment = join "\n$p ", split(/;\s+/, $tree->[1]); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 686 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 687 | 31 | return "\n" . (' ' x $i) . "<!-- $comment -->\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 688 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 689 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 690 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 691 | # Element is processing instruction | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 692 | elsif ($e eq 'pi') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 693 | 69 | return (' ' x $i) . '<?' . $tree->[1] . "?>\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 694 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 695 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 696 | # Element is root | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 697 | elsif ($e eq 'root') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 698 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 699 | 71 | my $content; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 700 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 701 | # Pretty print the content | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 702 | 71 | $content .= _render_pretty( $i, $tree->[ $_ ] ) for 1 .. $#$tree; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 703 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 704 | 71 | return $content; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 705 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 706 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 707 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 708 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 709 | # Render element with pretty printing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 710 | sub _element { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 711 | 172 | ▶ | my $i = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_element: called CC=18 SCAR=29.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 712 | 172 | my ($type, $qname, $attr, $child) = @{ shift() }; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 713 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 714 | # Is the qname valid? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 715 | 172 | ▶ | croak "$qname is no valid QName" | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 716 | unless $qname =~ /^(?:[a-zA-Z_]+:)?[^\s]+$/; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 717 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 718 | # Start start tag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 719 | 172 | my $content = (' ' x $i) . "<$qname"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 720 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 721 | # Add attributes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 722 | 172 | $content .= _attr((' ' x $i). (' ' x ( length($qname) + 2)), $attr); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 723 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 724 | # Has the element a child? | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 725 | 172 | ▶ | if ($child->[0]) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 726 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 727 | # Close start tag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 728 | 98 | $content .= '>'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 729 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 730 | # There is only a textual child - no indentation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 731 | 98 | ▶ | if (!$child->[1] && ($child->[0] && $child->[0]->[0] eq 'text')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition83%5/6
not $child->[1] and ($child->[0] and $child->[0][0] eq "text")
$child->[0] and $child->[0][0] eq "text"
MC/DC66%2/3
not $child->[1] and ($child->[0] and $child->[0][0] eq "text")
not $child->[1]
$child->[0]
$child->[0][0] eq "text"
Truth table75%3/4
not(A) and B and C
A= not $child->[1]B= $child->[0]C= $child->[0][0] eq "text"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 732 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 733 | # Special content treatment | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 734 | 56 | ▶ | if (exists $attr->{'loy:type'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 735 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 736 | # With base64 indentation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 737 | 5 | ▶ | if ($attr->{'loy:type'} =~ /^armour(?::(\d+))?$/i) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 738 | 3 | ▶ | my $n = $1 || 60; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$1 || 60
MC/DC0%0/1
$1 || 60
$1
Truth table50%1/2
A
A= $1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 739 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 740 | 3 | my $string = $child->[0]->[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 741 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 742 | # Delete whitespace | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 743 | 3 | $string =~ tr{\t-\x0d }{}d; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 744 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 745 | # Introduce newlines after n characters | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 746 | 3 | $content .= "\n" . (' ' x ($i + 1)); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 747 | 3 | $content .= join "\n" . ( ' ' x ($i + 1) ), (unpack "(A$n)*", $string ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 748 | 3 | $content .= "\n" . (' ' x $i); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 749 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 750 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 751 | # No special treatment | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 752 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 753 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 754 | # Escape | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 755 | 2 | $content .= b($child->[0]->[1])->trim->xml_escape; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 756 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 757 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 758 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 759 | # No special content treatment indentation | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 760 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 761 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 762 | # Escape | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 763 | 51 | $content .= b($child->[0]->[1])->trim->xml_escape; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 764 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 765 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 766 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 767 | # Treat children special | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 768 | elsif (exists $attr->{'loy:type'}) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 769 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 770 | # Raw | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 771 | 3 | ▶ | if ($attr->{'loy:type'} eq 'raw') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 772 | 1 | foreach (@$child) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 773 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 774 | # Create new dom object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 775 | 2 | my $dom = __PACKAGE__->new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 776 | 2 | $dom->xml(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 777 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 778 | # Print without prettifying | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 779 | 2 | $content .= $dom->tree($_)->to_string; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 780 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 781 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 782 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 783 | # Todo: | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 784 | elsif ($attr->{'loy:type'} eq 'escape') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 785 | 2 | $content .= "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 786 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 787 | 2 | foreach (@$child) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 788 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 789 | # Create new dom object | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 790 | 5 | my $dom = __PACKAGE__->new; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 791 | 5 | $dom->xml(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 792 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 793 | # Pretty print | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 794 | 5 | my $string = $dom->tree($_)->to_pretty_xml($i + 1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 795 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 796 | # Encode | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 797 | 5 | $content .= b($string)->xml_escape; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 798 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 799 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 800 | # Correct Indent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 801 | 2 | $content .= ' ' x $i; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 802 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 803 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 804 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 805 | # There are a couple of children | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 806 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 807 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 808 | 39 | my $offset = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 809 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 810 | # First element is unformatted textual | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 811 | 39 | ▶ | if (!exists $attr->{'loy:type'} && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
not exists $attr->{"loy:type"} and $child->[0] and $child->[0][0] eq "text"
not exists $attr->{"loy:type"} and $child->[0]
MC/DC33%1/3
not exists $attr->{"loy:type"} and $child->[0] and $child->[0][0] eq "text"
not exists $attr->{"loy:type"}
$child->[0]
$child->[0][0] eq "text"
Truth table50%2/4
not(A) and B and C
A= not exists $attr->{"loy:type"}B= $child->[0]C= $child->[0][0] eq "text"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 812 | $child->[0] && | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 813 | $child->[0]->[0] eq 'text') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 814 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 815 | # Append directly to the last tag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 816 | 4 | $content .= b($child->[0]->[1])->trim->xml_escape; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 817 | 4 | $offset = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 818 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 819 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 820 | # Start on a new line | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 821 | 39 | $content .= "\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 822 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 823 | # Loop through all child elements | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 824 | 39 | foreach (@{$child}[ $offset .. $#$child ]) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 825 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 826 | # Render next element | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 827 | 121 | $content .= _render_pretty( $i + 1, $_ ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 828 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 829 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 830 | # Correct Indent | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 831 | 39 | $content .= (' ' x $i); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 832 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 833 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 834 | # End Tag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 835 | 98 | $content .= "</$qname>\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 836 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 837 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 838 | # No child - close start element as empty tag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 839 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 840 | 74 | $content .= " />\n"; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 841 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 842 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 843 | # Return content | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 844 | 172 | return $content; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 845 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 846 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 847 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 848 | # Render attributes with pretty printing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 849 | sub _attr { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 850 | 172 | ▶ | my $indent_space = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_attr: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 851 | 172 | my %attr = %{$_[0]}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 852 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 853 | # Delete special and namespace attributes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 854 | my @special = grep { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 855 | 172 | ▶ | $_ eq 'xmlns:loy' || index($_, 'loy:') == 0 | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 856 | } keys %attr; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 857 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 858 | # Delete special attributes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 859 | 172 | delete $attr{$_} foreach @special; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 860 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 861 | # Prepare attribute values | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 862 | 172 | $_ = b($_)->xml_escape->quote foreach values %attr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 863 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 864 | # Return indented attribute string | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 865 | 172 | ▶ | if (keys %attr) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 866 | return ' ' . | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 867 | 67 | join "\n$indent_space", map { "$_=" . $attr{$_} } sort keys %attr; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 868 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 869 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 870 | # Return nothing | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 871 | 105 | return ''; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 872 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 873 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 874 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 875 | # Get root element (not as an object) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 876 | sub _root_element { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 877 | 807 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_root_element: called CC=7 SCAR=19.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 878 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 879 | # Todo: Optimize! Often called! | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 880 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 881 | # Find root (Based on Mojo::DOM::root) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 882 | 807 | ▶ | my $root = $self->tree or return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 883 | 807 | my $tag; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 884 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 885 | # Root is root node | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 886 | 807 | ▶ | if ($root->[0] eq 'root') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 887 | 697 | my $i = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 888 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 889 | # Search for the first tag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 890 | 697 | ▶ | $i++ while $root->[$i] && $root->[$i]->[0] ne 'tag'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$root->[$i] and $root->[$i][0] ne "tag"
MC/DC50%1/2
$root->[$i] and $root->[$i][0] ne "tag"
$root->[$i]
$root->[$i][0] ne "tag"
Truth table66%2/3
A and B
A= $root->[$i]B= $root->[$i][0] ne "tag"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 891 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 892 | # Tag found | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 893 | 697 | $tag = $root->[$i]; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 894 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 895 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 896 | # Root is a tag | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 897 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 898 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 899 | # Tag found | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 900 | 110 | ▶ | while ($root->[0] eq 'tag') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 901 | 213 | $tag = $root; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 902 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 903 | 213 | ▶ | last unless my $parent = $root->[3]; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 904 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 905 | 213 | $root = $parent; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 906 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 907 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 908 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 909 | # Return root element | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 910 | 807 | return $tag; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 911 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 912 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 913 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 914 | # Autoload for extensions | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 915 | sub AUTOLOAD { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 916 | 118 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
AUTOLOAD: called CC=6 SCAR=17.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 917 | 118 | my @param = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 918 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 919 | # Split parameter | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 920 | 118 | my ($package, $method) = our $AUTOLOAD =~ /^([\w\:]+)\:\:(\w+)$/; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 921 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 922 | # Choose root element | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 923 | 118 | my $root = $self->_root_element; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 924 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 925 | # Get extension array | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 926 | 118 | my @ext = $self->extension; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 927 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 928 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 929 | 21 | ▶ | no strict 'refs'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 930 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 931 | 118 | foreach (@ext) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 932 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 933 | # Method does not exist in extension | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 934 | 126 | ▶ | next unless $_->can($method); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 935 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 936 | # Release method | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 937 | 116 | return *{ "${_}::$method" }->($self, @param); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 938 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 939 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 940 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 941 | 2 | my $errstr = qq{Can't locate "${method}" in "$package"}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 942 | 2 | ▶ | if (@ext) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 943 | 1 | ▶ | $errstr .= ' with extension' . (@ext > 1 ? 's' : ''); | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 944 | 1 | $errstr .= ' "' . join('", "', @ext) . '"'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 945 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 946 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 947 | 2 | ▶ | carp $errstr and return; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 948 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 949 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 950 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 951 | 21 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 952 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 953 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 954 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||