| 1 | package Treex::PML::Schema::XMLNode; | ||||||||||||||||||||||||||||||||||||||||||||||
| 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 | 9 | ▶ | use Scalar::Util qw(weaken isweak); | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 9 | ▶ | use UNIVERSAL::DOES; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 82 | ▶ | sub copy_decl { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
copy_decl: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 82 | my ($self,$t)=@_; | |||||||||||||||||||||||||||||||||||||||||||||
| 18 | 82 | my $copy; | |||||||||||||||||||||||||||||||||||||||||||||
| 19 | 82 | ▶ | if (ref $t->{-schema}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 63 | $copy = Treex::PML::CloneValue($t,[$t->{-parent},$t->{-schema}], [$self,$self->{-schema}]); | |||||||||||||||||||||||||||||||||||||||||||||
| 21 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 19 | $copy = Treex::PML::CloneValue($t,[$t->{-parent}], [$self]); | |||||||||||||||||||||||||||||||||||||||||||||
| 23 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 24 | 82 | ▶ | if (exists $self->{'-##'}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 82 | $copy->{'-#'}=$self->{'-##'}++; | |||||||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 27 | # we must do this here, otherwise any operation | ||||||||||||||||||||||||||||||||||||||||||||||
| 28 | # that rewrites this value will create an unaccessible crircular reference | ||||||||||||||||||||||||||||||||||||||||||||||
| 29 | Treex::PML::Schema::_traverse_data( | ||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 370 | ▶ | $copy => sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.3
| |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 370 | my ($val,$is_hash) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 32 | 370 | ▶ | weaken($val->{-parent}) if ref($val->{-parent}) and not isweak($val->{-parent}); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $val->{"-parent"} and not builtin::is_weak($val->{"-parent"})
MC/DC50%1/2
ref $val->{"-parent"} and not builtin::is_weak($val->{"-parent"})
ref $val->{"-parent"}
not builtin::is_weak($val->{"-parent"})
Truth table66%2/3
A and not(B)
A= ref $val->{"-parent"}B= not builtin::is_weak($val->{"-parent"})
| |||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 370 | ▶ | weaken($val->{-schema}) if ref($val->{-schema}) and not isweak($val->{-schema}); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $val->{"-schema"} and not builtin::is_weak($val->{"-schema"})
MC/DC50%1/2
ref $val->{"-schema"} and not builtin::is_weak($val->{"-schema"})
ref $val->{"-schema"}
not builtin::is_weak($val->{"-schema"})
Truth table66%2/3
A and not(B)
A= ref $val->{"-schema"}B= not builtin::is_weak($val->{"-schema"})
| |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 35 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 82 | $self->{-schema}=>1, $self=> 1 # do not recurse into these | |||||||||||||||||||||||||||||||||||||||||||||
| 37 | }, | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 1, # only hashes | ||||||||||||||||||||||||||||||||||||||||||||||
| 39 | ); | ||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 82 | return $copy; | |||||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 270 | ▶ | sub serialize_attributes { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
serialize_attributes: called CC=7 SCAR=19.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 270 | my ($self,$opts)=@_; | |||||||||||||||||||||||||||||||||||||||||||||
| 45 | 270 | ▶ | my $attributes = $self->{-attributes}||[]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'-attributes'} || []
MC/DC0%0/1
$self->{'-attributes'} || []
$self->{'-attributes'}
Truth table50%1/2
A
A= $self->{'-attributes'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 270 | my @ret; | |||||||||||||||||||||||||||||||||||||||||||||
| 47 | 270 | for my $attr (@$attributes) { | |||||||||||||||||||||||||||||||||||||||||||||
| 48 | 366 | ▶ | next if $attr=~/^xmlns/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 355 | my $value = $self->{$attr}; | |||||||||||||||||||||||||||||||||||||||||||||
| 50 | 355 | ▶ | if (!defined($value) and $attr eq 'name') { # FIXME: THIS IS A HACK | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $value and $attr eq "name"
MC/DC50%1/2
not defined $value and $attr eq "name"
not defined $value
$attr eq "name"
Truth table66%2/3
not(A) and B
A= not defined $valueB= $attr eq "name"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 121 | $value = $self->{'-'.$attr}; | |||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 53 | 355 | ▶ | if (defined $value) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 355 | push @ret, $attr, $value; | |||||||||||||||||||||||||||||||||||||||||||||
| 55 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 270 | return \@ret; | |||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 253 | ▶ | sub serialize_exclude_keys {} | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
serialize_exclude_keys: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 264 | ▶ | sub serialize_get_children { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
serialize_get_children: called CC=7 SCAR=19.6
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 264 | my ($self,$opts)=@_; | |||||||||||||||||||||||||||||||||||||||||||||
| 63 | 264 | my %exclude; | |||||||||||||||||||||||||||||||||||||||||||||
| 64 | @exclude{ | ||||||||||||||||||||||||||||||||||||||||||||||
| 65 | 264 | ▶ | @{$self->{-attributes}||[]}, | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'-attributes'} || []
MC/DC0%0/1
$self->{'-attributes'} || []
$self->{'-attributes'}
Truth table50%1/2
A
A= $self->{'-attributes'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 66 | $self->serialize_exclude_keys($opts) | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | }=(); | ||||||||||||||||||||||||||||||||||||||||||||||
| 68 | my @children = map { | ||||||||||||||||||||||||||||||||||||||||||||||
| 69 | 192 | my $name = $_; | |||||||||||||||||||||||||||||||||||||||||||||
| 70 | 192 | my $val = $self->{$_}; | |||||||||||||||||||||||||||||||||||||||||||||
| 71 | 121 | ▶ | (ref($val) eq 'HASH') ? ( map { [$name,$_] } grep { UNIVERSAL::DOES::does($_,'Treex::PML::Schema::XMLNode') } values(%{$val})) : | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 192 | ▶ | (ref($val) eq 'ARRAY') ? ( map { [$name,$_] } grep { UNIVERSAL::DOES::does($_,'Treex::PML::Schema::XMLNode') } @{$val}) : | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%1/3
UNIVERSAL::DOES::does($val, "Treex::PML::Schema::XMLNode") or not ref $val
MC/DC0%0/2
UNIVERSAL::DOES::does($val, "Treex::PML::Schema::XMLNode") or not ref $val
UNIVERSAL::DOES::does($val, "Treex::PML::Schema::XMLNode")
not ref $val
Truth table33%1/3
A or not(B)
A= UNIVERSAL::DOES::does($val, "Treex::PML::Schema::XMLNode")B= not ref $val
| |||||||||||||||||||||||||||||||||||||||||||||||
| 73 | (UNIVERSAL::DOES::does($val,'Treex::PML::Schema::XMLNode') or !ref($val)) ? [$name,$val] : () | ||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 264 | ▶ | } grep {!/^[-@]/ and !exists($exclude{$_})} keys %$self; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
/^[-\@]/ || exists $exclude{$_}
MC/DC100%2/2
/^[-\@]/ || exists $exclude{$_}
/^[-\@]/
exists $exclude{$_}
Truth table100%3/3
A || B
A= /^[-\@]/B= exists $exclude{$_}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 75 | return ( | ||||||||||||||||||||||||||||||||||||||||||||||
| 76 | 269 | (grep { !ref($_->[1]) } @children), | |||||||||||||||||||||||||||||||||||||||||||||
| 77 | 264 | sort { $a->[1]{'-#'} <=> $b->[1]{'-#'} } grep { ref($_->[1]) } @children | |||||||||||||||||||||||||||||||||||||||||||||
| 78 | ) | ||||||||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 170 | ▶ | sub serialize_children { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
serialize_children: called CC=7 SCAR=19.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 81 | 170 | my ($self,$opts,$children)=@_; | |||||||||||||||||||||||||||||||||||||||||||||
| 82 | 170 | ▶ | my $writer = $opts->{writer} || croak __PACKAGE__."->serialize: missing required option 'writer'!\n"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts->{'writer'} || croak("Treex::PML::Schema::XMLNode->serialize: missing required option 'writer'!\n")
MC/DC0%0/1
$opts->{'writer'} || croak("Treex::PML::Schema::XMLNode->serialize: missing required option 'writer'!\n")
$opts->{'writer'}
Truth table50%1/2
A
A= $opts->{'writer'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 170 | my $ns = $opts->{DefaultNs}; | |||||||||||||||||||||||||||||||||||||||||||||
| 84 | 170 | ▶ | $children ||= [$self->serialize_get_children($opts)]; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$children ||= [$self->serialize_get_children($opts)]
MC/DC0%0/1
$children ||= [$self->serialize_get_children($opts)]
$children
Truth table50%1/2
A
A= $children
| |||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 170 | for my $child (@$children) { | |||||||||||||||||||||||||||||||||||||||||||||
| 86 | 317 | my ($key,$value) = @$child; | |||||||||||||||||||||||||||||||||||||||||||||
| 87 | 317 | ▶ | if (UNIVERSAL::DOES::does($value,'Treex::PML::Schema::XMLNode')) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 88 | 269 | $value->serialize($opts); | |||||||||||||||||||||||||||||||||||||||||||||
| 89 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 48 | my $tag = [$ns,$key]; | |||||||||||||||||||||||||||||||||||||||||||||
| 91 | 48 | ▶ | $writer->startTag($tag) if defined $key; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 48 | $writer->characters($value); | |||||||||||||||||||||||||||||||||||||||||||||
| 93 | 48 | ▶ | $writer->endTag($tag) if defined $key; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 280 | ▶ | sub serialize { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
serialize: called CC=14 SCAR=31.4
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 280 | my ($self,$opts)=@_; | |||||||||||||||||||||||||||||||||||||||||||||
| 99 | 280 | ▶ | my $writer = $opts->{writer} || croak __PACKAGE__."->serialize: missing required option 'writer'!\n"; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$opts->{'writer'} || croak("Treex::PML::Schema::XMLNode->serialize: missing required option 'writer'!\n")
MC/DC0%0/1
$opts->{'writer'} || croak("Treex::PML::Schema::XMLNode->serialize: missing required option 'writer'!\n")
$opts->{'writer'}
Truth table50%1/2
A
A= $opts->{'writer'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 100 | 280 | my $xml_name = $self->{-xml_name}; | |||||||||||||||||||||||||||||||||||||||||||||
| 101 | 280 | ▶ | if ($xml_name =~/^#/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 102 | 10 | ▶ | if ($xml_name =~/^#text/) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 103 | 0 | $writer->characters($self->{-value}); | |||||||||||||||||||||||||||||||||||||||||||||
| 104 | } elsif ($xml_name =~/^#comment/) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 10 | my $value = $self->{-value}; | |||||||||||||||||||||||||||||||||||||||||||||
| 106 | 10 | $value=~s/^ | $//g; # remove a leading and trailing space - XML::Writer addes them | |||||||||||||||||||||||||||||||||||||||||||||
| 107 | 10 | $writer->comment($value); | |||||||||||||||||||||||||||||||||||||||||||||
| 108 | } elsif ($xml_name =~/^#processing-instruction/) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 0 | $writer->pi($self->{-name}, $self->{-value}); | |||||||||||||||||||||||||||||||||||||||||||||
| 110 | } elsif ($xml_name =~/^#other/) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 111 | 0 | $writer->raw($self->{-xml}); | |||||||||||||||||||||||||||||||||||||||||||||
| 112 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 113 | # ignoring | ||||||||||||||||||||||||||||||||||||||||||||||
| 114 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 115 | ▶ | } elsif ($xml_name=~/^{(.*)}(.*)$/ or $xml_name=~/^()([^#].*)$/) { | |||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$xml_name =~ /^{(.*)}(.*)$/ or $xml_name =~ /^()([^#].*)$/
MC/DC0%0/2
$xml_name =~ /^{(.*)}(.*)$/ or $xml_name =~ /^()([^#].*)$/
$xml_name =~ /^{(.*)}(.*)$/
$xml_name =~ /^()([^#].*)$/
Truth table33%1/3
A or B
A= $xml_name =~ /^{(.*)}(.*)$/B= $xml_name =~ /^()([^#].*)$/
| |||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 270 | my ($ns,$name)=($1,$2); | |||||||||||||||||||||||||||||||||||||||||||||
| 117 | 270 | ▶ | my $attrs = $self->serialize_attributes($opts) || []; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->serialize_attributes($opts) || []
MC/DC0%0/1
$self->serialize_attributes($opts) || []
$self->serialize_attributes($opts)
Truth table50%1/2
A
A= $self->serialize_attributes($opts)
| |||||||||||||||||||||||||||||||||||||||||||||||
| 118 | 270 | ▶ | my $prefix = $self->{-xml_prefix} || ''; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{'-xml_prefix'} || ''
MC/DC0%0/1
$self->{'-xml_prefix'} || ''
$self->{'-xml_prefix'}
Truth table50%1/2
A
A= $self->{'-xml_prefix'}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 270 | ▶ | $ns ||= $opts->{DefaultNs}; | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$ns ||= $opts->{"DefaultNs"}
MC/DC0%0/2
$ns ||= $opts->{"DefaultNs"}
$ns
$opts->{"DefaultNs"}
Truth table33%1/3
A ||= B
A= $nsB= $opts->{"DefaultNs"}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 270 | ▶ | if (($ns ne $opts->{DefaultNs})) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | $writer->addPrefix($ns => $prefix); | |||||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 270 | $writer->addPrefix($ns => $prefix); | |||||||||||||||||||||||||||||||||||||||||||||
| 124 | { | ||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 270 | my @children = $self->serialize_get_children($opts); | |||||||||||||||||||||||||||||||||||||||||||||
| 126 | 270 | ▶ | if (@children) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 170 | $writer->startTag([$ns,$name], @$attrs); | |||||||||||||||||||||||||||||||||||||||||||||
| 128 | 170 | $self->serialize_children($opts,\@children); | |||||||||||||||||||||||||||||||||||||||||||||
| 129 | 170 | $writer->endTag([$ns,$name]); | |||||||||||||||||||||||||||||||||||||||||||||
| 130 | } else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 100 | $writer->emptyTag([$ns,$name], @$attrs); | |||||||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 136 | |||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 11 | ▶ | sub write { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
write: called CC=15 SCAR=36.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 11 | my ($self,$opts)=@_; | |||||||||||||||||||||||||||||||||||||||||||||
| 139 | 11 | my $fh; | |||||||||||||||||||||||||||||||||||||||||||||
| 140 | my $have_backup; | ||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 11 | my $filename = $opts->{filename}; | |||||||||||||||||||||||||||||||||||||||||||||
| 142 | 11 | ▶ | if (!defined($opts->{fh}) and | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
not defined $opts->{"fh"} || defined $opts->{"string"} and defined $filename
defined $opts->{'fh'} || defined $opts->{'string'}
MC/DC0%0/3
not defined $opts->{"fh"} || defined $opts->{"string"} and defined $filename
defined $opts->{'fh'}
defined $opts->{'string'}
defined $filename
Truth table25%1/4
not(A || B) and C
A= defined $opts->{'fh'}B= defined $opts->{'string'}C= defined $filename
| |||||||||||||||||||||||||||||||||||||||||||||||
| 143 | !defined($opts->{string}) and | ||||||||||||||||||||||||||||||||||||||||||||||
| 144 | defined($filename)) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 145 | 11 | ▶ | unless ($opts->{no_backups}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 11 | ▶ | eval { Treex::PML::IO::rename_uri($filename,$filename."~"); $have_backup=1; } || carp($@); | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 147 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 11 | ▶ | $fh = Treex::PML::IO::open_backend($filename,'w') | ||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
Treex::PML::IO::open_backend($filename, 'w') || die("Cannot open $filename for writing: $!")
MC/DC0%0/1
Treex::PML::IO::open_backend($filename, 'w') || die("Cannot open $filename for writing: $!")
Treex::PML::IO::open_backend($filename, 'w')
Truth table50%1/2
A
A= Treex::PML::IO::open_backend($filename, 'w')
| |||||||||||||||||||||||||||||||||||||||||||||||
| 149 | || die "Cannot open $filename for writing: $!"; | ||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 11 | binmode $fh; | |||||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 11 | eval { | |||||||||||||||||||||||||||||||||||||||||||||
| 153 | my $writer = XML::Writer->new( | ||||||||||||||||||||||||||||||||||||||||||||||
| 154 | OUTPUT => ($opts->{fh} || $opts->{string} || $fh ), | ||||||||||||||||||||||||||||||||||||||||||||||
| 155 | DATA_MODE => $opts->{no_indent} ? 0 : 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 11 | ▶ | DATA_INDENT => $opts->{no_indent} ? 0 : 1, | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition33%2/6
$opts->{'fh'} || $opts->{'string'} || $fh
$opts->{"fh"} or $opts->{"string"}
MC/DC0%0/3
$opts->{'fh'} || $opts->{'string'} || $fh
$opts->{"fh"}
$opts->{"string"}
$fh
Truth table25%1/4
A or B || C
A= $opts->{"fh"}B= $opts->{"string"}C= $fh
| |||||||||||||||||||||||||||||||||||||||||||||||
| 157 | NAMESPACES => 1, | ||||||||||||||||||||||||||||||||||||||||||||||
| 158 | PREFIX_MAP => { | ||||||||||||||||||||||||||||||||||||||||||||||
| 159 | (Treex::PML::Schema->PML_SCHEMA_NS) => '', | ||||||||||||||||||||||||||||||||||||||||||||||
| 160 | }); | ||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 11 | $self->serialize({ | |||||||||||||||||||||||||||||||||||||||||||||
| 162 | writer => $writer, | ||||||||||||||||||||||||||||||||||||||||||||||
| 163 | DefaultNs => Treex::PML::Schema->PML_SCHEMA_NS, | ||||||||||||||||||||||||||||||||||||||||||||||
| 164 | }); | ||||||||||||||||||||||||||||||||||||||||||||||
| 165 | 11 | $writer->end(); | |||||||||||||||||||||||||||||||||||||||||||||
| 166 | }; | ||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 11 | ▶ | if ($@) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 0 | my $err=$@; | |||||||||||||||||||||||||||||||||||||||||||||
| 169 | 0 | ▶ | $have_backup && eval { Treex::PML::IO::rename_uri($filename."~",$filename) }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | ▶ | $err.=$@ if $@; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 171 | 0 | carp("Error while saving schema: $err\n"); | |||||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 173 | 11 | ▶ | Treex::PML::IO::close_backend($fh) if $fh; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 174 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||||||
| 176 | 2869 | ▶ | sub DESTROY { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
DESTROY: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 177 | 2869 | my ($self)=@_; | |||||||||||||||||||||||||||||||||||||||||||||
| 178 | 2869 | %$self=(); # this should not be needed, but | |||||||||||||||||||||||||||||||||||||||||||||
| 179 | # without it, perl 5.10 leaks on weakened | ||||||||||||||||||||||||||||||||||||||||||||||
| 180 | # structures, try: | ||||||||||||||||||||||||||||||||||||||||||||||
| 181 | # Scalar::Util::weaken({}) while 1 | ||||||||||||||||||||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||||||||||||||||||||
| 183 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||||||
| 186 | 9 | 1; | |||||||||||||||||||||||||||||||||||||||||||||
| 187 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||