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