| 1 | package Treex::PML::Schema::Reader; | ||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||
| 3 | 9 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 4 | 9 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||||||||
| 6 | 9 | ▶ | use vars qw($VERSION); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 7 | 9 | ▶ | BEGIN { | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 8 | 9 | $VERSION='2.29'; # version template | |||||||||||||||||||||||||||||||||
| 9 | } | ||||||||||||||||||||||||||||||||||
| 10 | 9 | ▶ | no warnings 'uninitialized'; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 11 | 9 | ▶ | use Carp; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||
| 13 | 9 | ▶ | use Scalar::Util qw(weaken blessed); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 14 | 9 | ▶ | use XML::LibXML::Reader; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||
| 16 | 67 | ▶ | sub new { | ||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=17 SCAR=44.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 17 | 67 | my ($class,$opts)=@_; | |||||||||||||||||||||||||||||||||
| 18 | 67 | my $URL = $opts->{URL}; | |||||||||||||||||||||||||||||||||
| 19 | 67 | my @common = ( | |||||||||||||||||||||||||||||||||
| 20 | no_xinclude_nodes => 1, | ||||||||||||||||||||||||||||||||||
| 21 | no_cdata => 1, | ||||||||||||||||||||||||||||||||||
| 22 | expand_xinclude => 1, | ||||||||||||||||||||||||||||||||||
| 23 | no_blanks => 1, | ||||||||||||||||||||||||||||||||||
| 24 | expand_entities => 1, | ||||||||||||||||||||||||||||||||||
| 25 | suppress_errors => 0, | ||||||||||||||||||||||||||||||||||
| 26 | suppress_warnings => 0, | ||||||||||||||||||||||||||||||||||
| 27 | ); | ||||||||||||||||||||||||||||||||||
| 28 | 67 | ▶ | if ($opts->{validate}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 29 | 0 | ▶ | my $rng = $opts->{relaxng_schema} || Treex::PML::FindInResources('pml_schema_inline.rng'); | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$opts->{'relaxng_schema'} || Treex::PML::FindInResources('pml_schema_inline.rng')
MC/DC0%0/2
$opts->{'relaxng_schema'} || Treex::PML::FindInResources('pml_schema_inline.rng')
$opts->{'relaxng_schema'}
Treex::PML::FindInResources('pml_schema_inline.rng')
Truth table0%0/3
A || B
A= $opts->{'relaxng_schema'}B= Treex::PML::FindInResources('pml_schema_inline.rng')
| |||||||||||||||||||||||||||||||||||
| 30 | 0 | ▶ | if (defined $rng) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 31 | 0 | push @common, (RelaxNG => $rng); | |||||||||||||||||||||||||||||||||
| 32 | } else { | ||||||||||||||||||||||||||||||||||
| 33 | 0 | warn __PACKAGE__.": Validation requested, but 'pml_schema_inline.rng' was not found in the ResourcePath: ".Treex::PML::ResourcePath()."\n"; | |||||||||||||||||||||||||||||||||
| 34 | } | ||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||
| 36 | 67 | my ($reader,$fh); | |||||||||||||||||||||||||||||||||
| 37 | # print "loading schema $opts->{URL}\n"; | ||||||||||||||||||||||||||||||||||
| 38 | 67 | ▶ | if ($opts->{string}) { | ||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | $URL ||= 'string://'; | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
$URL ||= "string://"
MC/DC0%0/1
$URL ||= "string://"
$URL
Truth table0%0/2
A
A= $URL
| |||||||||||||||||||||||||||||||||||
| 40 | $reader = XML::LibXML::Reader->new(string => $opts->{string}, | ||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | @common, | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 42 | URI => $URL, | ||||||||||||||||||||||||||||||||||
| 43 | ) | ||||||||||||||||||||||||||||||||||
| 44 | or die "Error reading string ($URL)"; | ||||||||||||||||||||||||||||||||||
| 45 | } elsif ($opts->{fh}) { | ||||||||||||||||||||||||||||||||||
| 46 | 0 | ▶ | $URL ||= 'fh://'; | ||||||||||||||||||||||||||||||||
|
Condition0%0/2
$URL ||= "fh://"
MC/DC0%0/1
$URL ||= "fh://"
$URL
Truth table0%0/2
A
A= $URL
| |||||||||||||||||||||||||||||||||||
| 47 | 0 | ▶ | $reader = XML::LibXML::Reader->new(IO => $opts->{string}, @common ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 48 | or die "Error reading file-handle $fh ($URL)"; | ||||||||||||||||||||||||||||||||||
| 49 | ▶ | } elsif (blessed($opts->{reader}) and $opts->{reader}->isa('XML::LibXML::Reader')) { | |||||||||||||||||||||||||||||||||
|
Condition33%1/3
builtin::blessed($opts->{"reader"}) and $opts->{"reader"}->isa("XML::LibXML::Reader")
MC/DC0%0/2
builtin::blessed($opts->{"reader"}) and $opts->{"reader"}->isa("XML::LibXML::Reader")
builtin::blessed($opts->{"reader"})
$opts->{"reader"}->isa("XML::LibXML::Reader")
Truth table33%1/3
A and B
A= builtin::blessed($opts->{"reader"})B= $opts->{"reader"}->isa("XML::LibXML::Reader")
| |||||||||||||||||||||||||||||||||||
| 50 | 0 | $reader = $opts->{reader}; | |||||||||||||||||||||||||||||||||
| 51 | 0 | ▶ | $URL ||= $reader->document->URI; | ||||||||||||||||||||||||||||||||
|
Condition0%0/3
$URL ||= $reader->document->URI
MC/DC0%0/2
$URL ||= $reader->document->URI
$URL
$reader->document->URI
Truth table0%0/3
A ||= B
A= $URLB= $reader->document->URI
| |||||||||||||||||||||||||||||||||||
| 52 | } else { | ||||||||||||||||||||||||||||||||||
| 53 | 67 | my $file = $opts->{URL}; | |||||||||||||||||||||||||||||||||
| 54 | 67 | ▶ | print STDERR "parsing schema $file\n" if $Treex::PML::Debug; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 55 | 67 | $fh = eval { Treex::PML::IO::open_uri($file) }; | |||||||||||||||||||||||||||||||||
| 56 | 67 | ▶ | croak "Couldn't open PML schema file '$file'\n".$@ if (!$fh || $@); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $fh or $@
MC/DC0%0/2
not $fh or $@
not $fh
$@
Truth table33%1/3
not(A) or B
A= not $fhB= $@
| |||||||||||||||||||||||||||||||||||
| 57 | 67 | ▶ | $reader = XML::LibXML::Reader->new(FD => $fh, @common, URI => $URL ) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 58 | or die "Error reading $file"; | ||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||
| 60 | 67 | return bless [$reader,$opts,$fh], $class; | |||||||||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||||||||
| 62 | 67 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||
| 63 | 67 | my ($self)=@_; | |||||||||||||||||||||||||||||||||
| 64 | 67 | my $fh = $self->file_handle; | |||||||||||||||||||||||||||||||||
| 65 | 67 | ▶ | Treex::PML::IO::close_uri($fh) if $fh; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 66 | } | ||||||||||||||||||||||||||||||||||
| 67 | 3030 | ▶ | sub reader { | ||||||||||||||||||||||||||||||||
|
Subroutine
reader: called CC=2 SCAR=9.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 68 | 3030 | ▶ | return ref($_[0]) && $_[0][0]; | ||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $_[0] && $_[0][0]
MC/DC0%0/2
ref $_[0] && $_[0][0]
ref $_[0]
$_[0][0]
Truth table33%1/3
A && B
A= ref $_[0]B= $_[0][0]
| |||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||
| 70 | 2963 | ▶ | sub options { | ||||||||||||||||||||||||||||||||
|
Subroutine
options: called CC=2 SCAR=9.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 71 | 2963 | ▶ | return ref($_[0]) && $_[0][1]; | ||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $_[0] && $_[0][1]
MC/DC0%0/2
ref $_[0] && $_[0][1]
ref $_[0]
$_[0][1]
Truth table33%1/3
A && B
A= ref $_[0]B= $_[0][1]
| |||||||||||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||||||||
| 73 | 67 | ▶ | sub file_handle { | ||||||||||||||||||||||||||||||||
|
Subroutine
file_handle: called CC=2 SCAR=9.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 74 | 67 | ▶ | return ref($_[0]) && $_[0][2]; | ||||||||||||||||||||||||||||||||
|
Condition33%1/3
ref $_[0] && $_[0][2]
MC/DC0%0/2
ref $_[0] && $_[0][2]
ref $_[0]
$_[0][2]
Truth table33%1/3
A && B
A= ref $_[0]B= $_[0][2]
| |||||||||||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||
| 77 | 2963 | ▶ | sub parse_element { | ||||||||||||||||||||||||||||||||
|
Subroutine
parse_element: called CC=38 SCAR=39.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||
| 78 | 2963 | my ($self,$parent)=@_; | |||||||||||||||||||||||||||||||||
| 79 | 2963 | my $reader = $self->reader; | |||||||||||||||||||||||||||||||||
| 80 | 2963 | my $opts = $self->options; | |||||||||||||||||||||||||||||||||
| 81 | 2963 | my (@children,@attrs); | |||||||||||||||||||||||||||||||||
| 82 | 2963 | my $el_ns = $reader->namespaceURI; | |||||||||||||||||||||||||||||||||
| 83 | 2963 | my $el_name = $reader->localName; | |||||||||||||||||||||||||||||||||
| 84 | 2963 | ▶ | my $has_default_ns = $el_ns eq $opts->{DefaultNs} ? 1 : 0; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 85 | 2963 | ▶ | my $el_ns_name = ($has_default_ns) ? $el_name : '{'.$el_ns.'}'.$el_name; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 86 | 2963 | my $prefix = $reader->prefix; | |||||||||||||||||||||||||||||||||
| 87 | 2963 | ▶ | my %val = ( | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
defined $prefix and length $prefix
MC/DC0%0/2
defined $prefix and length $prefix
defined $prefix
length $prefix
Truth table33%1/3
A and B
A= defined $prefixB= length $prefix
| |||||||||||||||||||||||||||||||||||
| 88 | -xml_name => $el_ns_name, | ||||||||||||||||||||||||||||||||||
| 89 | ($has_default_ns ? () : (-xml_ns => $el_ns)), | ||||||||||||||||||||||||||||||||||
| 90 | (defined($prefix) && length($prefix) ? (-xml_prefix => $prefix) : ()), | ||||||||||||||||||||||||||||||||||
| 91 | -parent => $parent, | ||||||||||||||||||||||||||||||||||
| 92 | -attributes => \@attrs, | ||||||||||||||||||||||||||||||||||
| 93 | ); | ||||||||||||||||||||||||||||||||||
| 94 | 2963 | ▶ | weaken($val{-parent}) if $val{-parent}; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||
| 96 | 2963 | ▶ | if ($reader->moveToFirstAttribute==1) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 97 | 2062 | ▶ | do {{ | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 98 | 3182 | my $name = $reader->name; | |||||||||||||||||||||||||||||||||
| 99 | 3182 | push @attrs,$name; | |||||||||||||||||||||||||||||||||
| 100 | 3182 | $val{$name} = $reader->value; | |||||||||||||||||||||||||||||||||
| 101 | }} while ($reader->moveToNextAttribute); | ||||||||||||||||||||||||||||||||||
| 102 | 2062 | $reader->moveToElement; | |||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||
| 104 | 2963 | my $obj = \%val; | |||||||||||||||||||||||||||||||||
| 105 | { | ||||||||||||||||||||||||||||||||||
| 106 | 2963 | ▶ | my $class = $opts->{Bless}{$el_ns_name} || $opts->{Bless}{'*'}; | ||||||||||||||||||||||||||||||||
|
Condition66%2/3
$opts->{'Bless'}{$el_ns_name} || $opts->{'Bless'}{'*'}
MC/DC0%0/2
$opts->{'Bless'}{$el_ns_name} || $opts->{'Bless'}{'*'}
$opts->{'Bless'}{$el_ns_name}
$opts->{'Bless'}{'*'}
Truth table66%2/3
A || B
A= $opts->{'Bless'}{$el_ns_name}B= $opts->{'Bless'}{'*'}
| |||||||||||||||||||||||||||||||||||
| 107 | 2963 | ▶ | if (defined $class) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 108 | 2963 | bless $obj,$class; | |||||||||||||||||||||||||||||||||
| 109 | 2963 | ▶ | $obj->init($opts) if $obj->can('init'); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||
| 112 | 2963 | my $depth = $reader->depth; | |||||||||||||||||||||||||||||||||
| 113 | 2963 | my $status; | |||||||||||||||||||||||||||||||||
| 114 | 2963 | ▶ | while (($status = $reader->read==1)) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 115 | 8709 | ▶ | last unless $reader->depth > $depth; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 116 | 5746 | my $nodeType = $reader->nodeType; | |||||||||||||||||||||||||||||||||
| 117 | 5746 | my $chld; | |||||||||||||||||||||||||||||||||
| 118 | 5746 | my $redo = 0; | |||||||||||||||||||||||||||||||||
| 119 | 5746 | ▶ | if ($nodeType == XML_READER_TYPE_ELEMENT) { | ||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||
| 120 | 2896 | $chld = $self->parse_element($obj); | |||||||||||||||||||||||||||||||||
| 121 | 2896 | $redo = 1; | |||||||||||||||||||||||||||||||||
| 122 | ▶ | } elsif ($nodeType == XML_READER_TYPE_TEXT or | |||||||||||||||||||||||||||||||||
|
Condition66%2/3
$nodeType == 3 or $nodeType == 4
MC/DC50%1/2
$nodeType == 3 or $nodeType == 4
$nodeType == 3
$nodeType == 4
Truth table66%2/3
A or B
A= $nodeType == 3B= $nodeType == 4
| |||||||||||||||||||||||||||||||||||
| 123 | $nodeType == XML_READER_TYPE_CDATA) { | ||||||||||||||||||||||||||||||||||
| 124 | 582 | $chld = bless { | |||||||||||||||||||||||||||||||||
| 125 | -xml_name => '#text', | ||||||||||||||||||||||||||||||||||
| 126 | -value => $reader->value, | ||||||||||||||||||||||||||||||||||
| 127 | }, 'Treex::PML::Schema::XMLNode'; | ||||||||||||||||||||||||||||||||||
| 128 | } elsif ($nodeType == XML_READER_TYPE_COMMENT) { | ||||||||||||||||||||||||||||||||||
| 129 | 323 | $chld = bless { | |||||||||||||||||||||||||||||||||
| 130 | -xml_name => '#comment', | ||||||||||||||||||||||||||||||||||
| 131 | -value => $reader->value, | ||||||||||||||||||||||||||||||||||
| 132 | }, 'Treex::PML::Schema::XMLNode'; | ||||||||||||||||||||||||||||||||||
| 133 | } elsif ($nodeType == XML_READER_TYPE_PROCESSING_INSTRUCTION) { | ||||||||||||||||||||||||||||||||||
| 134 | 0 | $chld = bless { | |||||||||||||||||||||||||||||||||
| 135 | -xml_name => '#processing-instruction', | ||||||||||||||||||||||||||||||||||
| 136 | -name => $reader->name, | ||||||||||||||||||||||||||||||||||
| 137 | -value => $reader->value, | ||||||||||||||||||||||||||||||||||
| 138 | }, 'Treex::PML::Schema::XMLNode'; | ||||||||||||||||||||||||||||||||||
| 139 | ▶ | } elsif ($nodeType == XML_READER_TYPE_END_ELEMENT or | |||||||||||||||||||||||||||||||||
|
Condition33%2/6
$nodeType == 15 or $nodeType == 14 or $nodeType == 13
$nodeType == 15 or $nodeType == 14
MC/DC0%0/3
$nodeType == 15 or $nodeType == 14 or $nodeType == 13
$nodeType == 15
$nodeType == 14
$nodeType == 13
Truth table25%1/4
A or B or C
A= $nodeType == 15B= $nodeType == 14C= $nodeType == 13
| |||||||||||||||||||||||||||||||||||
| 140 | $nodeType == XML_READER_TYPE_SIGNIFICANT_WHITESPACE or | ||||||||||||||||||||||||||||||||||
| 141 | $nodeType == XML_READER_TYPE_WHITESPACE) { | ||||||||||||||||||||||||||||||||||
| 142 | 1945 | next; | |||||||||||||||||||||||||||||||||
| 143 | } else { | ||||||||||||||||||||||||||||||||||
| 144 | 0 | ▶ | $chld = bless { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 145 | -xml_name => '#other', | ||||||||||||||||||||||||||||||||||
| 146 | -xml_nodetype => $nodeType, | ||||||||||||||||||||||||||||||||||
| 147 | -name => $reader->name, | ||||||||||||||||||||||||||||||||||
| 148 | ($reader->hasValue ? (-value => $reader->value) : ()), | ||||||||||||||||||||||||||||||||||
| 149 | -xml => $reader->readOuterXml, | ||||||||||||||||||||||||||||||||||
| 150 | }, 'Treex::PML::Schema::XMLNode'; | ||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||
| 152 | 3801 | ▶ | push @children, $chld if defined $chld; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 153 | 3801 | ▶ | redo if $redo; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||
| 155 | 2963 | ▶ | if ($status == -1) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 156 | 0 | croak "XMLReader error in $opts->{URL} near line ".$reader->lineNumber; | |||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||
| 159 | 2963 | my $i=0; | |||||||||||||||||||||||||||||||||
| 160 | 2963 | my %try_data; | |||||||||||||||||||||||||||||||||
| 161 | 2963 | ▶ | if (my $cont = $opts->{TextOnly}{$el_ns_name}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 162 | 582 | my $text; | |||||||||||||||||||||||||||||||||
| 163 | 582 | foreach my $c (@children) { | |||||||||||||||||||||||||||||||||
| 164 | 582 | ▶ | if ($c->{'-xml_name'} ne '#text') { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 165 | 0 | warn "Ignoring unexpected node ".$c->{'-xml_name'}." in a text-only element $el_ns_name\n"; | |||||||||||||||||||||||||||||||||
| 166 | } else { | ||||||||||||||||||||||||||||||||||
| 167 | 582 | $text.=$c->{-value}; | |||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||
| 170 | 582 | $val{$cont} = $text; | |||||||||||||||||||||||||||||||||
| 171 | } else { | ||||||||||||||||||||||||||||||||||
| 172 | 2381 | foreach my $c (@children) { | |||||||||||||||||||||||||||||||||
| 173 | 3219 | $c->{'-#'} = $i++; | |||||||||||||||||||||||||||||||||
| 174 | 3219 | my $name = $c->{-xml_name}; | |||||||||||||||||||||||||||||||||
| 175 | 3219 | ▶ | if (!ref($val{$name})) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 176 | 1832 | ▶ | if (exists $val{$name}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 177 | 0 | warn "Collision between an attribute and child-element $name\n"; | |||||||||||||||||||||||||||||||||
| 178 | 0 | $val{'@'.$name} = delete $val{$name} | |||||||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||||||
| 180 | } | ||||||||||||||||||||||||||||||||||
| 181 | 3219 | my $value; | |||||||||||||||||||||||||||||||||
| 182 | 3219 | ▶ | if (my $cont = $opts->{Stringify}{$name}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 183 | 580 | $value = $c->{$cont}; | |||||||||||||||||||||||||||||||||
| 184 | 580 | ▶ | $value='' unless defined $value; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 185 | } else { | ||||||||||||||||||||||||||||||||||
| 186 | 2639 | $value = $c; | |||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||
| 188 | 3219 | ▶ | if ($opts->{Solitary}{$name}) { | ||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||
| 189 | 1165 | ▶ | if (exists $val{$name}) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 190 | 0 | warn "Multiple occurences of the child-element '$name'\n"; | |||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||
| 192 | 1165 | $val{$name} = $value | |||||||||||||||||||||||||||||||||
| 193 | } elsif (my $key = $opts->{KeyAttr}{$name}) { | ||||||||||||||||||||||||||||||||||
| 194 | 1211 | my $val = delete $c->{$key}; | |||||||||||||||||||||||||||||||||
| 195 | 1211 | $c->{-name}=$val; | |||||||||||||||||||||||||||||||||
| 196 | 1211 | $val{$name}{$val} = $value; | |||||||||||||||||||||||||||||||||
| 197 | } else { | ||||||||||||||||||||||||||||||||||
| 198 | 843 | push @{$val{$name}}, $value; | |||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||
| 200 | 3219 | weaken($c->{-parent} = $obj); | |||||||||||||||||||||||||||||||||
| 201 | } | ||||||||||||||||||||||||||||||||||
| 202 | 2381 | $obj->{'-##'} = $i; | |||||||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||||||
| 204 | 2963 | ▶ | if (UNIVERSAL::can($obj,'post_process')) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 205 | 151 | $obj->post_process($opts); | |||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||
| 207 | 2963 | return $obj; | |||||||||||||||||||||||||||||||||
| 208 | } | ||||||||||||||||||||||||||||||||||
| 209 | |||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||
| 211 | 9 | 1; | |||||||||||||||||||||||||||||||||
| 212 | __END__ | ||||||||||||||||||||||||||||||||||