| 1 | # Copyrights 2008-2016 by [Mark Overmeer]. | ||||||||||||||||||||||||||||||
| 2 | # For other contributors see ChangeLog. | ||||||||||||||||||||||||||||||
| 3 | # See the manual pages for details on the licensing terms. | ||||||||||||||||||||||||||||||
| 4 | # Pod stripped from pm file by OODoc 2.02. | ||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||
| 8 | package XML::Compile::Cache; | ||||||||||||||||||||||||||||||
| 9 | 3 | ▶ | use vars '$VERSION'; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 10 | 3 | $VERSION = '1.05'; | |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use base 'XML::Compile::Schema'; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||
| 14 | 3 | ▶ | use Log::Report 'xml-compile-cache', syntax => 'SHORT'; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||||
| 16 | 3 | ▶ | use XML::Compile::Util qw/pack_type unpack_type/; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 17 | 3 | ▶ | use List::Util qw/first/; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 18 | 3 | ▶ | use Scalar::Util qw/weaken/; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 19 | 3 | ▶ | use XML::LibXML::Simple qw/XMLin/; | ||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||
| 21 | |||||||||||||||||||||||||||||||
| 22 | sub init($) | ||||||||||||||||||||||||||||||
| 23 | 2 | ▶ | { my ($self, $args) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
init: called CC=6 SCAR=18.3
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 24 | 2 | $self->addPrefixes($args->{prefixes}); | |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||
| 26 | 2 | $self->SUPER::init($args); | |||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||
| 28 | 2 | ▶ | $self->{XCC_opts} = delete $args->{opts_rw} || []; | ||||||||||||||||||||||||||||
|
Condition50%1/2
delete $args->{'opts_rw'} || []
MC/DC0%0/1
delete $args->{'opts_rw'} || []
delete $args->{'opts_rw'}
Truth table50%1/2
A
A= delete $args->{'opts_rw'}
| |||||||||||||||||||||||||||||||
| 29 | 2 | ▶ | $self->{XCC_ropts} = delete $args->{opts_readers} || []; | ||||||||||||||||||||||||||||
|
Condition50%1/2
delete $args->{'opts_readers'} || []
MC/DC0%0/1
delete $args->{'opts_readers'} || []
delete $args->{'opts_readers'}
Truth table50%1/2
A
A= delete $args->{'opts_readers'}
| |||||||||||||||||||||||||||||||
| 30 | 2 | ▶ | $self->{XCC_wopts} = delete $args->{opts_writers} || []; | ||||||||||||||||||||||||||||
|
Condition50%1/2
delete $args->{'opts_writers'} || []
MC/DC0%0/1
delete $args->{'opts_writers'} || []
delete $args->{'opts_writers'}
Truth table50%1/2
A
A= delete $args->{'opts_writers'}
| |||||||||||||||||||||||||||||||
| 31 | 2 | ▶ | $self->{XCC_undecl} = delete $args->{allow_undeclared} || 0; | ||||||||||||||||||||||||||||
|
Condition50%1/2
delete $args->{'allow_undeclared'} || 0
MC/DC0%0/1
delete $args->{'allow_undeclared'} || 0
delete $args->{'allow_undeclared'}
Truth table50%1/2
A
A= delete $args->{'allow_undeclared'}
| |||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||
| 33 | 2 | $self->{XCC_dropts} = {}; # declared opts | |||||||||||||||||||||||||||||
| 34 | 2 | $self->{XCC_dwopts} = {}; | |||||||||||||||||||||||||||||
| 35 | 2 | $self->{XCC_uropts} = {}; # undeclared opts | |||||||||||||||||||||||||||||
| 36 | 2 | $self->{XCC_uwopts} = {}; | |||||||||||||||||||||||||||||
| 37 | |||||||||||||||||||||||||||||||
| 38 | 2 | $self->{XCC_readers} = {}; # compiled code refs; | |||||||||||||||||||||||||||||
| 39 | 2 | $self->{XCC_writers} = {}; | |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||
| 41 | 2 | $self->typemap($args->{typemap}); | |||||||||||||||||||||||||||||
| 42 | 2 | $self->xsiType($args->{xsi_type}); | |||||||||||||||||||||||||||||
| 43 | 2 | ▶ | $self->anyElement($args->{any_element} || 'ATTEMPT'); | ||||||||||||||||||||||||||||
|
Condition50%1/2
$args->{'any_element'} || 'ATTEMPT'
MC/DC0%0/1
$args->{'any_element'} || 'ATTEMPT'
$args->{'any_element'}
Truth table50%1/2
A
A= $args->{'any_element'}
| |||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||
| 45 | 2 | $self; | |||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||||
| 48 | #---------------------- | ||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||
| 51 | sub typemap(@) | ||||||||||||||||||||||||||||||
| 52 | 2 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||
|
Subroutine
typemap: called CC=6 SCAR=24.2
Pod
documented
| |||||||||||||||||||||||||||||||
| 53 | 2 | ▶ | my $t = $self->{XCC_typemap} ||= {}; | ||||||||||||||||||||||||||||
|
Condition50%1/2
$self->{"XCC_typemap"} ||= {}
MC/DC0%0/1
$self->{"XCC_typemap"} ||= {}
$self->{"XCC_typemap"}
Truth table50%1/2
A
A= $self->{"XCC_typemap"}
| |||||||||||||||||||||||||||||||
| 54 | my @d = @_ > 1 ? @_ : !defined $_[0] ? () | ||||||||||||||||||||||||||||||
| 55 | 2 | ▶ | : ref $_[0] eq 'HASH' ? %{$_[0]} : @{$_[0]}; | ||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||
| 56 | 2 | ▶ | while(@d) { my $k = $self->findName(shift @d); $t->{$k} = shift @d } | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 57 | 2 | $t; | |||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||
| 61 | sub addXsiType(@) | ||||||||||||||||||||||||||||||
| 62 | 3 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||
|
Subroutine
addXsiType: called CC=9 SCAR=23.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 63 | 3 | ▶ | my $x = $self->{XCC_xsi_type} ||= {}; | ||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"XCC_xsi_type"} ||= {}
MC/DC100%1/1
$self->{"XCC_xsi_type"} ||= {}
$self->{"XCC_xsi_type"}
Truth table100%2/2
A
A= $self->{"XCC_xsi_type"}
| |||||||||||||||||||||||||||||||
| 64 | my @d = @_ > 1 ? @_ : !defined $_[0] ? () | ||||||||||||||||||||||||||||||
| 65 | 3 | ▶ | : ref $_[0] eq 'HASH' ? %{$_[0]} : @{$_[0]}; | ||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||
| 67 | 3 | ▶ | while(@d) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 68 | 1 | { my $k = $self->findName(shift @d); | |||||||||||||||||||||||||||||
| 69 | 1 | my $a = shift @d; | |||||||||||||||||||||||||||||
| 70 | 1 | ▶ | $a = $self->namespaces->autoexpand_xsi_type($k) || [] | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%1/2
$self->namespaces->autoexpand_xsi_type($k) || []
MC/DC0%0/1
$self->namespaces->autoexpand_xsi_type($k) || []
$self->namespaces->autoexpand_xsi_type($k)
Truth table50%1/2
A
A= $self->namespaces->autoexpand_xsi_type($k)
| |||||||||||||||||||||||||||||||
| 71 | if $a eq 'AUTO'; | ||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||
| 73 | 1 | ▶ | push @{$x->{$k}} | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 74 | , ref $a eq 'ARRAY' ? (map $self->findName($_), @$a) | ||||||||||||||||||||||||||||||
| 75 | : $self->findName($a); | ||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||
| 78 | 3 | $x; | |||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||
| 80 | 3 | *xsiType = \&addXsiType; | |||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||
| 83 | sub allowUndeclared(;$) | ||||||||||||||||||||||||||||||
| 84 | 7 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||
|
Subroutine
allowUndeclared: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 85 | 7 | ▶ | @_ ? ($self->{XCC_undecl} = shift) : $self->{XCC_undecl}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||
| 88 | |||||||||||||||||||||||||||||||
| 89 | sub anyElement($) | ||||||||||||||||||||||||||||||
| 90 | 2 | ▶ | { my ($self, $anyelem) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
anyElement: called CC=3 SCAR=13.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||
| 92 | # the "$self" in XCC_ropts would create a ref-cycle, causing a | ||||||||||||||||||||||||||||||
| 93 | # memory leak. | ||||||||||||||||||||||||||||||
| 94 | 2 | my $s = $self; weaken $s; | |||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||
| 96 | my $code | ||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | = $anyelem eq 'ATTEMPT' ? sub {$s->_convertAnyTyped(@_)} | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | : $anyelem eq 'SLOPPY' ? sub {$s->_convertAnySloppy(@_)} | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 99 | 2 | ▶ | : $anyelem; | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||
| 101 | 2 | $self->addCompileOptions(READERS => any_element => $code); | |||||||||||||||||||||||||||||
| 102 | 2 | $code; | |||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||
| 105 | #---------------------- | ||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||
| 108 | sub addPrefixes(@) | ||||||||||||||||||||||||||||||
| 109 | 4 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||
|
Subroutine
addPrefixes: called CC=12 SCAR=25.1
Pod
documented
| |||||||||||||||||||||||||||||||
| 110 | 4 | ▶ | my $p = $self->{XCC_namespaces} ||= {}; | ||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"XCC_namespaces"} ||= {}
MC/DC100%1/1
$self->{"XCC_namespaces"} ||= {}
$self->{"XCC_namespaces"}
Truth table100%2/2
A
A= $self->{"XCC_namespaces"}
| |||||||||||||||||||||||||||||||
| 111 | 4 | my $first = shift; | |||||||||||||||||||||||||||||
| 112 | 4 | ▶ | @_ or defined $first | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
@_ or defined $first
MC/DC100%2/2
@_ or defined $first
@_
defined $first
Truth table100%3/3
A or B
A= @_B= defined $first
| |||||||||||||||||||||||||||||||
| 113 | or return $p; | ||||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||||
| 115 | my @pairs | ||||||||||||||||||||||||||||||
| 116 | 3 | ▶ | = @_ ? ($first, @_) | ||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||
| 117 | : ref $first eq 'ARRAY' ? @$first | ||||||||||||||||||||||||||||||
| 118 | : ref $first eq 'HASH' ? %$first | ||||||||||||||||||||||||||||||
| 119 | : error __x"prefixes() expects list of PAIRS, an ARRAY or a HASH"; | ||||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||||
| 121 | 3 | ▶ | my $a = $self->{XCC_prefixes} ||= {}; | ||||||||||||||||||||||||||||
|
Condition100%2/2
$self->{"XCC_prefixes"} ||= {}
MC/DC100%1/1
$self->{"XCC_prefixes"} ||= {}
$self->{"XCC_prefixes"}
Truth table100%2/2
A
A= $self->{"XCC_prefixes"}
| |||||||||||||||||||||||||||||||
| 122 | 3 | ▶ | while(@pairs) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 123 | 3 | { my ($prefix, $ns) = (shift @pairs, shift @pairs); | |||||||||||||||||||||||||||||
| 124 | 3 | ▶ | $p->{$ns} ||= { uri => $ns, prefix => $prefix, used => 0 }; | ||||||||||||||||||||||||||||
|
Condition100%2/2
$p->{$ns} ||= {"uri", $ns, "prefix", $prefix, "used", 0}
MC/DC100%1/1
$p->{$ns} ||= {"uri", $ns, "prefix", $prefix, "used", 0}
$p->{$ns}
Truth table100%2/2
A
A= $p->{$ns}
| |||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||
| 126 | 3 | ▶ | if(my $def = $a->{$prefix}) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 127 | 1 | ▶ | { if($def->{uri} ne $ns) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 128 | { error __x"prefix `{prefix}' already refers to {uri}, cannot use it for {ns}" | ||||||||||||||||||||||||||||||
| 129 | 0 | , prefix => $prefix, uri => $def->{uri}, ns => $ns; | |||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||||
| 132 | else | ||||||||||||||||||||||||||||||
| 133 | 2 | { $a->{$prefix} = $p->{$ns}; | |||||||||||||||||||||||||||||
| 134 | 2 | trace "register prefix $prefix for '$ns'"; | |||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||
| 137 | 3 | $p; | |||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||
| 139 | |||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||
| 142 | sub prefixes(@) | ||||||||||||||||||||||||||||||
| 143 | 3 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||
|
Subroutine
prefixes: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||||||||||
| 144 | 3 | ▶ | return $self->addPrefixes(@_) if @_; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 145 | 2 | ▶ | $self->{XCC_namespaces} || {}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||
| 149 | 1 | ▶ | sub prefix($) { $_[0]->{XCC_prefixes}{$_[1]} } | ||||||||||||||||||||||||||||
|
Subroutine
prefix: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||
| 151 | # [0.995] should this be public? | ||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | sub byPrefixTable() { shift->{XCC_prefixes} } | ||||||||||||||||||||||||||||
|
Subroutine
byPrefixTable: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||
| 155 | sub prefixFor($) | ||||||||||||||||||||||||||||||
| 156 | 0 | ▶ | { my $def = $_[0]->{XCC_namespaces}{$_[1]} or return (); | ||||||||||||||||||||||||||||
|
Subroutine
prefixFor: not called CC=2 SCAR=17.9
Pod
documented
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 157 | 0 | $def->{used}++; | |||||||||||||||||||||||||||||
| 158 | 0 | $def->{prefix}; | |||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||||
| 162 | sub addNicePrefix($$) | ||||||||||||||||||||||||||||||
| 163 | 0 | ▶ | { my ($self, $base, $ns) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
addNicePrefix: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||
| 164 | 0 | ▶ | if(my $def = $self->prefix($base)) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 165 | 0 | ▶ | { return $base if $def->{uri} eq $ns; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 166 | } | ||||||||||||||||||||||||||||||
| 167 | else | ||||||||||||||||||||||||||||||
| 168 | 0 | { $self->addPrefixes($base => $ns); | |||||||||||||||||||||||||||||
| 169 | 0 | return $base; | |||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||
| 172 | 0 | ▶ | $base .= '01' if $base !~ m/[0-9]$/; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 173 | 0 | ▶ | while(my $def = $self->prefix($base)) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 174 | 0 | ▶ | { return $base if $def->{uri} eq $ns; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 175 | 0 | $base++; | |||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||||
| 177 | 0 | $self->addPrefixes($base => $ns); | |||||||||||||||||||||||||||||
| 178 | 0 | $base; | |||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||
| 181 | |||||||||||||||||||||||||||||||
| 182 | sub learnPrefixes($) | ||||||||||||||||||||||||||||||
| 183 | 2 | ▶ | { my ($self, $node) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
learnPrefixes: called CC=8 SCAR=27.2
Pod
documented
| |||||||||||||||||||||||||||||||
| 184 | 2 | my $namespaces = $self->prefixes; | |||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||
| 186 | PREFIX: | ||||||||||||||||||||||||||||||
| 187 | 2 | foreach my $ns ($node->getNamespaces) # learn preferred ns | |||||||||||||||||||||||||||||
| 188 | 4 | { my ($prefix, $uri) = ($ns->getLocalName, $ns->getData); | |||||||||||||||||||||||||||||
| 189 | 4 | ▶ | next if !defined $prefix || $namespaces->{$uri}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
not defined $prefix or $namespaces->{$uri}
MC/DC100%2/2
not defined $prefix or $namespaces->{$uri}
not defined $prefix
$namespaces->{$uri}
Truth table100%3/3
not(A) or B
A= not defined $prefixB= $namespaces->{$uri}
| |||||||||||||||||||||||||||||||
| 190 | |||||||||||||||||||||||||||||||
| 191 | 1 | ▶ | if(my $def = $self->prefix($prefix)) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 192 | 0 | ▶ | { next PREFIX if $def->{uri} eq $uri; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 193 | } | ||||||||||||||||||||||||||||||
| 194 | else | ||||||||||||||||||||||||||||||
| 195 | 1 | { $self->addPrefixes($prefix => $uri); | |||||||||||||||||||||||||||||
| 196 | 1 | next PREFIX; | |||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||
| 199 | 0 | $prefix =~ s/0?$/0/; | |||||||||||||||||||||||||||||
| 200 | 0 | ▶ | while(my $def = $self->prefix($prefix)) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 201 | 0 | ▶ | { next PREFIX if $def->{uri} eq $uri; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 202 | 0 | $prefix++; | |||||||||||||||||||||||||||||
| 203 | } | ||||||||||||||||||||||||||||||
| 204 | 0 | $self->addPrefixes($prefix => $uri); | |||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||
| 208 | sub addSchemas($@) | ||||||||||||||||||||||||||||||
| 209 | 2 | ▶ | { my ($self, $xml) = (shift, shift); | ||||||||||||||||||||||||||||
|
Subroutine
addSchemas: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 210 | 2 | $self->learnPrefixes($xml); | |||||||||||||||||||||||||||||
| 211 | 2 | $self->SUPER::addSchemas($xml, @_); | |||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||
| 215 | sub prefixed($;$) | ||||||||||||||||||||||||||||||
| 216 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||
|
Subroutine
prefixed: not called CC=5 SCAR=34.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | my ($ns, $local) = @_==2 ? @_ : unpack_type(shift); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 218 | 0 | ▶ | $ns or return $local; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 219 | 0 | my $prefix = $self->prefixFor($ns); | |||||||||||||||||||||||||||||
| 220 | 0 | ▶ | defined $prefix | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 221 | or error __x"no prefix known for namespace `{ns}', use addPrefixes()" | ||||||||||||||||||||||||||||||
| 222 | , ns => $ns; | ||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||
| 224 | 0 | ▶ | length $prefix ? "$prefix:$local" : $local; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||
| 227 | #---------------------- | ||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||
| 230 | sub compileAll(;$$) | ||||||||||||||||||||||||||||||
| 231 | 0 | ▶ | { my ($self, $need, $usens) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
compileAll: not called CC=10 SCAR=47.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 232 | 0 | ▶ | my ($need_r, $need_w) = $self->_need($need || 'RW'); | ||||||||||||||||||||||||||||
|
Condition0%0/2
$need || 'RW'
MC/DC0%0/1
$need || 'RW'
$need
Truth table0%0/2
A
A= $need
| |||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||
| 234 | 0 | ▶ | if($need_r) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 235 | 0 | { foreach my $type (keys %{$self->{XCC_dropts}}) | |||||||||||||||||||||||||||||
| 236 | 0 | ▶ | { if(defined $usens) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 237 | 0 | { my ($myns, $local) = unpack_type $type; | |||||||||||||||||||||||||||||
| 238 | 0 | ▶ | next if $usens eq $myns; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||||
| 240 | 0 | $self->reader($type); | |||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||
| 243 | |||||||||||||||||||||||||||||||
| 244 | 0 | ▶ | if($need_w) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 245 | 0 | { foreach my $type (keys %{$self->{XCC_dwopts}}) | |||||||||||||||||||||||||||||
| 246 | 0 | ▶ | { if(defined $usens) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 247 | 0 | { my ($myns, $local) = unpack_type $type; | |||||||||||||||||||||||||||||
| 248 | 0 | ▶ | next if $usens eq $myns; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 249 | } | ||||||||||||||||||||||||||||||
| 250 | 0 | $self->writer($type); | |||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||
| 256 | sub _same_params($$) | ||||||||||||||||||||||||||||||
| 257 | 2 | ▶ | { my ($f, $s) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
_same_params: called CC=6 SCAR=26.2
| |||||||||||||||||||||||||||||||
| 258 | 2 | ▶ | @$f==@$s or return 0; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 259 | 2 | ▶ | for(my $i=0; $i<@$f; $i++) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 260 | 0 | ▶ | { return 0 if !defined $f->[$i] ? defined $s->[$i] | ||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||
| 261 | : !defined $s->[$i] ? 1 : $f->[$i] ne $s->[$i]; | ||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||
| 263 | 2 | 1; | |||||||||||||||||||||||||||||
| 264 | } | ||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||
| 266 | sub reader($@) | ||||||||||||||||||||||||||||||
| 267 | 8 | ▶ | { my ($self, $name) = (shift, shift); | ||||||||||||||||||||||||||||
|
Subroutine
reader: called CC=11 SCAR=24.6
Pod
documented
| |||||||||||||||||||||||||||||||
| 268 | 8 | my %args = @_; | |||||||||||||||||||||||||||||
| 269 | 8 | my $type = $self->findName($name); | |||||||||||||||||||||||||||||
| 270 | 8 | my $readers = $self->{XCC_readers}; | |||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||
| 272 | 8 | ▶ | if(exists $self->{XCC_dropts}{$type}) | ||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||
| 273 | 4 | ▶ | { trace __x"ignoring options to pre-declared reader {name}" | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 274 | , name => $name if @_; | ||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||
| 276 | return $readers->{$type} | ||||||||||||||||||||||||||||||
| 277 | 4 | ▶ | if $readers->{$type}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 278 | } | ||||||||||||||||||||||||||||||
| 279 | elsif($self->allowUndeclared) | ||||||||||||||||||||||||||||||
| 280 | 2 | ▶ | { if(my $ur = $self->{XCC_uropts}{$type}) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 281 | { # do not use cached version when options differ | ||||||||||||||||||||||||||||||
| 282 | _same_params $ur, \@_ | ||||||||||||||||||||||||||||||
| 283 | or return $args{is_type} | ||||||||||||||||||||||||||||||
| 284 | 1 | ▶ | ? $self->compileType(READER => $type, @_) | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 285 | : $self->compile(READER => $type, @_); | ||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||
| 287 | else | ||||||||||||||||||||||||||||||
| 288 | 1 | { $self->{XCC_uropts}{$type} = \@_; | |||||||||||||||||||||||||||||
| 289 | } | ||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||
| 291 | elsif(exists $self->{XCC_dwopts}{$type}) | ||||||||||||||||||||||||||||||
| 292 | 1 | { error __x"type {name} is only declared as writer", name => $name } | |||||||||||||||||||||||||||||
| 293 | 1 | else { error __x"type {name} is not declared", name => $name } | |||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||
| 295 | $readers->{$type} ||= $args{is_type} | ||||||||||||||||||||||||||||||
| 296 | 4 | ▶ | ? $self->compileType(READER => $type, @_) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$readers->{$type} ||= $args{"is_type"} ? $self->compileType("READER", $type, @_) : $self->compile("READER", $type, @_)
MC/DC0%0/2
$readers->{$type} ||= $args{"is_type"} ? $self->compileType("READER", $type, @_) : $self->compile("READER", $type, @_)
$readers->{$type}
$args{"is_type"} ? $self->compileType("READER", $type, @_) : $self->compile("READER", $type, @_)
Truth table66%2/3
A ||= B
A= $readers->{$type}B= $args{"is_type"} ? $self->compileType("READER", $type, @_) : $self->compile("READER", $type, @_)
| |||||||||||||||||||||||||||||||
| 297 | : $self->compile(READER => $type, @_); | ||||||||||||||||||||||||||||||
| 298 | } | ||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||
| 301 | sub writer($%) | ||||||||||||||||||||||||||||||
| 302 | 8 | ▶ | { my ($self, $name) = (shift, shift); | ||||||||||||||||||||||||||||
|
Subroutine
writer: called CC=11 SCAR=24.6
Pod
documented
| |||||||||||||||||||||||||||||||
| 303 | 8 | my %args = @_; | |||||||||||||||||||||||||||||
| 304 | 8 | my $type = $self->findName($name); | |||||||||||||||||||||||||||||
| 305 | 8 | my $writers = $self->{XCC_writers}; | |||||||||||||||||||||||||||||
| 306 | |||||||||||||||||||||||||||||||
| 307 | 8 | ▶ | if(exists $self->{XCC_dwopts}{$type}) | ||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||
| 308 | 4 | ▶ | { trace __x"ignoring options to pre-declared writer {name}" | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 309 | , name => $name if @_; | ||||||||||||||||||||||||||||||
| 310 | |||||||||||||||||||||||||||||||
| 311 | return $writers->{$type} | ||||||||||||||||||||||||||||||
| 312 | 4 | ▶ | if $writers->{$type}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||
| 314 | elsif($self->{XCC_undecl}) | ||||||||||||||||||||||||||||||
| 315 | 2 | ▶ | { if(my $ur = $self->{XCC_uwopts}{$type}) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 316 | { # do not use cached version when options differ | ||||||||||||||||||||||||||||||
| 317 | _same_params $ur, \@_ | ||||||||||||||||||||||||||||||
| 318 | or return $args{is_type} | ||||||||||||||||||||||||||||||
| 319 | 1 | ▶ | ? $self->compileType(WRITER => $type, @_) | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 320 | : $self->compile(WRITER => $type, @_); | ||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||
| 322 | else | ||||||||||||||||||||||||||||||
| 323 | 1 | { $self->{XCC_uwopts}{$type} = \@_; | |||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||
| 325 | } | ||||||||||||||||||||||||||||||
| 326 | elsif(exists $self->{XCC_dropts}{$type}) | ||||||||||||||||||||||||||||||
| 327 | 1 | { error __x"type {name} is only declared as reader", name => $name; | |||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||
| 329 | else | ||||||||||||||||||||||||||||||
| 330 | 1 | { error __x"type {name} is not declared", name => $name; | |||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||
| 332 | |||||||||||||||||||||||||||||||
| 333 | $writers->{$type} ||= $args{is_type} | ||||||||||||||||||||||||||||||
| 334 | 4 | ▶ | ? $self->compileType(WRITER => $type, @_) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$writers->{$type} ||= $args{"is_type"} ? $self->compileType("WRITER", $type, @_) : $self->compile("WRITER", $type, @_)
MC/DC0%0/2
$writers->{$type} ||= $args{"is_type"} ? $self->compileType("WRITER", $type, @_) : $self->compile("WRITER", $type, @_)
$writers->{$type}
$args{"is_type"} ? $self->compileType("WRITER", $type, @_) : $self->compile("WRITER", $type, @_)
Truth table66%2/3
A ||= B
A= $writers->{$type}B= $args{"is_type"} ? $self->compileType("WRITER", $type, @_) : $self->compile("WRITER", $type, @_)
| |||||||||||||||||||||||||||||||
| 335 | : $self->compile(WRITER => $type, @_); | ||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||
| 337 | } | ||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||
| 339 | sub template($$@) | ||||||||||||||||||||||||||||||
| 340 | 0 | ▶ | { my ($self, $action, $name) = (shift, shift, shift); | ||||||||||||||||||||||||||||
|
Subroutine
template: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 341 | 0 | ▶ | $action =~ m/^[A-Z]*$/ | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 342 | or error __x"missing or illegal action parameter to template()"; | ||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||
| 344 | 0 | my $type = $self->findName($name); | |||||||||||||||||||||||||||||
| 345 | 0 | my @opts = $self->mergeCompileOptions($action, $type, \@_); | |||||||||||||||||||||||||||||
| 346 | 0 | $self->SUPER::template($action, $type, @opts); | |||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||
| 348 | |||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||
| 350 | sub addCompileOptions(@) | ||||||||||||||||||||||||||||||
| 351 | 2 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||
|
Subroutine
addCompileOptions: called CC=7 SCAR=26.4
Pod
documented
| |||||||||||||||||||||||||||||||
| 352 | 2 | ▶ | my $need = @_%2 ? shift : 'RW'; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||
| 354 | my $set | ||||||||||||||||||||||||||||||
| 355 | = $need eq 'RW' ? $self->{XCC_opts} | ||||||||||||||||||||||||||||||
| 356 | : $need eq 'READERS' ? $self->{XCC_ropts} | ||||||||||||||||||||||||||||||
| 357 | : $need eq 'WRITERS' ? $self->{XCC_wopts} | ||||||||||||||||||||||||||||||
| 358 | 2 | ▶ | : error __x"addCompileOptions() requires option set name, not {got}" | ||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||
| 359 | , got => $need; | ||||||||||||||||||||||||||||||
| 360 | |||||||||||||||||||||||||||||||
| 361 | 2 | ▶ | if(ref $set eq 'HASH') | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 362 | 0 | ▶ | { while(@_) { my $k = shift; $set->{$k} = shift } } | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 363 | 2 | else { push @$set, @_ } | |||||||||||||||||||||||||||||
| 364 | 2 | $set; | |||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||
| 366 | |||||||||||||||||||||||||||||||
| 367 | # Create a list with options for X::C::Schema::compile(), from a list of ARRAYs | ||||||||||||||||||||||||||||||
| 368 | # and HASHES with options. The later options overrule the older, but in some | ||||||||||||||||||||||||||||||
| 369 | # cases, the new values are added. This method knows how some of the options | ||||||||||||||||||||||||||||||
| 370 | # of ::compile() behave. [last update X::C v0.98] | ||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||
| 372 | sub mergeCompileOptions($$$) | ||||||||||||||||||||||||||||||
| 373 | 6 | ▶ | { my ($self, $action, $type, $opts) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
mergeCompileOptions: called CC=24 SCAR=49.8
Pod
undocumented
| |||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||
| 375 | my @action_opts | ||||||||||||||||||||||||||||||
| 376 | = ($action eq 'READER' || $action eq 'PERL') | ||||||||||||||||||||||||||||||
| 377 | ? ($self->{XCC_ropts}, $self->{XCC_dropts}{$type}) | ||||||||||||||||||||||||||||||
| 378 | 6 | ▶ | : ($self->{XCC_wopts}, $self->{XCC_dwopts}{$type}); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$action eq "READER" or $action eq "PERL"
MC/DC50%1/2
$action eq "READER" or $action eq "PERL"
$action eq "READER"
$action eq "PERL"
Truth table66%2/3
A or B
A= $action eq "READER"B= $action eq "PERL"
| |||||||||||||||||||||||||||||||
| 379 | |||||||||||||||||||||||||||||||
| 380 | 6 | my %p = %{$self->{XCC_namespaces}}; | |||||||||||||||||||||||||||||
| 381 | 6 | my %t = %{$self->{XCC_typemap}}; | |||||||||||||||||||||||||||||
| 382 | 6 | my %x = %{$self->{XCC_xsi_type}}; | |||||||||||||||||||||||||||||
| 383 | 6 | my %opts = (prefixes => \%p, hooks => [], typemap => \%t, xsi_type => \%x); | |||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||
| 385 | # flatten list of parameters | ||||||||||||||||||||||||||||||
| 386 | 24 | ▶ | my @take = map {!defined $_ ? () : ref $_ eq 'ARRAY' ? @$_ : %$_ } | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 387 | 6 | $self->{XCC_opts}, @action_opts, $opts; | |||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||
| 389 | 6 | ▶ | while(@take) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 390 | 3 | { my ($opt, $val) = (shift @take, shift @take); | |||||||||||||||||||||||||||||
| 391 | 3 | ▶ | defined $val or next; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 392 | |||||||||||||||||||||||||||||||
| 393 | 3 | ▶ | if($opt eq 'prefixes') | ||||||||||||||||||||||||||||
|
Branch: 6 branches
| |||||||||||||||||||||||||||||||
| 394 | 0 | { my $t = $self->_namespaceTable($val, 1, 0); # expand | |||||||||||||||||||||||||||||
| 395 | 0 | @p{keys %$t} = values %$t; # overwrite old def if exists | |||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||
| 397 | ▶ | elsif($opt eq 'hooks' || $opt eq 'hook') | |||||||||||||||||||||||||||||
|
Condition33%1/3
$opt eq "hooks" or $opt eq "hook"
MC/DC0%0/2
$opt eq "hooks" or $opt eq "hook"
$opt eq "hooks"
$opt eq "hook"
Truth table33%1/3
A or B
A= $opt eq "hooks"B= $opt eq "hook"
| |||||||||||||||||||||||||||||||
| 398 | 0 | { my $hooks = $self->_cleanup_hooks($val); | |||||||||||||||||||||||||||||
| 399 | 0 | ▶ | unshift @{$opts{hooks}}, ref $hooks eq 'ARRAY' ? @$hooks : $hooks | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 400 | if $hooks; | ||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||
| 402 | elsif($opt eq 'typemap') | ||||||||||||||||||||||||||||||
| 403 | 0 | ▶ | { $val ||= {}; | ||||||||||||||||||||||||||||
|
Condition0%0/2
$val ||= {}
MC/DC0%0/1
$val ||= {}
$val
Truth table0%0/2
A
A= $val
| |||||||||||||||||||||||||||||||
| 404 | 0 | ▶ | if(ref $val eq 'ARRAY') | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 405 | 0 | ▶ | { while(@$val) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 406 | 0 | { my $k = $self->findName(shift @$val); | |||||||||||||||||||||||||||||
| 407 | 0 | $t{$k} = shift @$val; | |||||||||||||||||||||||||||||
| 408 | } | ||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||
| 410 | else | ||||||||||||||||||||||||||||||
| 411 | 0 | ▶ | { while(my($k, $v) = each %$val) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 412 | 0 | { $t{$self->findName($k)} = $v; | |||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||
| 414 | } | ||||||||||||||||||||||||||||||
| 415 | } | ||||||||||||||||||||||||||||||
| 416 | elsif($opt eq 'key_rewrite') | ||||||||||||||||||||||||||||||
| 417 | 0 | ▶ | { unshift @{$opts{key_rewrite}}, ref $val eq 'ARRAY' ? @$val : $val; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 418 | } | ||||||||||||||||||||||||||||||
| 419 | elsif($opt eq 'xsi_type') | ||||||||||||||||||||||||||||||
| 420 | 0 | ▶ | { while(my ($t, $a) = each %$val) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 421 | 0 | ▶ | { my @a = ref $a eq 'ARRAY' ? map($self->findName($_), @$a) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 422 | : $self->findName($a); | ||||||||||||||||||||||||||||||
| 423 | 0 | push @{$x{$self->findName($t)}}, @a; | |||||||||||||||||||||||||||||
| 424 | } | ||||||||||||||||||||||||||||||
| 425 | } | ||||||||||||||||||||||||||||||
| 426 | elsif($opt eq 'ignore_unused_tags') | ||||||||||||||||||||||||||||||
| 427 | 0 | ▶ | { $opts{$opt} = defined $opts{$opt} ? qr/$opts{$opt}|$val/ : $val; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 428 | } | ||||||||||||||||||||||||||||||
| 429 | else | ||||||||||||||||||||||||||||||
| 430 | 3 | { $opts{$opt} = $val; | |||||||||||||||||||||||||||||
| 431 | } | ||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||
| 434 | 6 | %opts; | |||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||
| 437 | # rewrite hooks | ||||||||||||||||||||||||||||||
| 438 | sub _cleanup_hooks($) | ||||||||||||||||||||||||||||||
| 439 | 0 | ▶ | { my ($self, $hooks) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
_cleanup_hooks: not called CC=8 SCAR=42.8
| |||||||||||||||||||||||||||||||
| 440 | 0 | ▶ | $hooks or return; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 441 | |||||||||||||||||||||||||||||||
| 442 | # translate prefixed type names into full names | ||||||||||||||||||||||||||||||
| 443 | 0 | ▶ | foreach my $hook (ref $hooks eq 'ARRAY' ? @$hooks : $hooks) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 444 | 0 | ▶ | { if(my $types = $hook->{type}) | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 445 | { $hook->{type} = | ||||||||||||||||||||||||||||||
| 446 | 0 | ▶ | [ map {ref $_ eq 'Regexp' ? $_ : $self->findName($_)} | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 447 | ref $types eq 'ARRAY' ? @$types : $types ]; | ||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||
| 449 | elsif(my $ext = $hook->{extends}) | ||||||||||||||||||||||||||||||
| 450 | 0 | { $hook->{extends} = $self->findName($ext); | |||||||||||||||||||||||||||||
| 451 | } | ||||||||||||||||||||||||||||||
| 452 | } | ||||||||||||||||||||||||||||||
| 453 | 0 | $hooks; | |||||||||||||||||||||||||||||
| 454 | } | ||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||
| 456 | 3 | my %need = (READER => [1,0], WRITER => [0,1], RW => [1,1]); | |||||||||||||||||||||||||||||
| 457 | 3 | $need{READERS} = $need{READER}; | |||||||||||||||||||||||||||||
| 458 | 3 | $need{WRITERS} = $need{WRITER}; | |||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||
| 460 | sub _need($) | ||||||||||||||||||||||||||||||
| 461 | 3 | ▶ | { my $need = $need{$_[1]} | ||||||||||||||||||||||||||||
|
Subroutine
_need: called CC=2 SCAR=7.2
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 462 | or error __x"use READER, WRITER or RW, not {dir}", dir => $_[1]; | ||||||||||||||||||||||||||||||
| 463 | 3 | @$need; | |||||||||||||||||||||||||||||
| 464 | } | ||||||||||||||||||||||||||||||
| 465 | |||||||||||||||||||||||||||||||
| 466 | # support prefixes on types | ||||||||||||||||||||||||||||||
| 467 | sub addHook(@) | ||||||||||||||||||||||||||||||
| 468 | 0 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||
|
Subroutine
addHook: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 469 | 0 | ▶ | my $hook = @_ > 1 ? {@_} : shift; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 470 | 0 | $self->_cleanup_hooks($hook); | |||||||||||||||||||||||||||||
| 471 | 0 | $self->SUPER::addHook($hook); | |||||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||
| 474 | sub compile($$@) | ||||||||||||||||||||||||||||||
| 475 | 6 | ▶ | { my ($self, $action, $elem) = splice @_, 0, 3; | ||||||||||||||||||||||||||||
|
Subroutine
compile: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||||
| 476 | 6 | ▶ | defined $elem | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 477 | or error __x"compile() requires action and type parameters"; | ||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||
| 479 | 6 | $self->SUPER::compile | |||||||||||||||||||||||||||||
| 480 | ( $action => $self->findName($elem) | ||||||||||||||||||||||||||||||
| 481 | , $self->mergeCompileOptions($action, $elem, \@_) | ||||||||||||||||||||||||||||||
| 482 | ); | ||||||||||||||||||||||||||||||
| 483 | } | ||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||
| 485 | sub compileType($$@) | ||||||||||||||||||||||||||||||
| 486 | 0 | ▶ | { my ($self, $action, $type) = splice @_, 0, 3; | ||||||||||||||||||||||||||||
|
Subroutine
compileType: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||
| 487 | 0 | ▶ | defined $type | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 488 | or error __x"compileType() requires action and type parameters"; | ||||||||||||||||||||||||||||||
| 489 | |||||||||||||||||||||||||||||||
| 490 | 0 | $self->SUPER::compileType | |||||||||||||||||||||||||||||
| 491 | ( $action => $self->findName($type) | ||||||||||||||||||||||||||||||
| 492 | , $self->mergeCompileOptions($action, $type, \@_) | ||||||||||||||||||||||||||||||
| 493 | ); | ||||||||||||||||||||||||||||||
| 494 | } | ||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||
| 496 | #---------------------- | ||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||
| 499 | sub declare($$@) | ||||||||||||||||||||||||||||||
| 500 | 3 | ▶ | { my ($self, $need, $names, @opts) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
declare: called CC=9 SCAR=22.5
Pod
documented
| |||||||||||||||||||||||||||||||
| 501 | 3 | ▶ | my $opts = @opts==1 ? shift @opts : \@opts; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 502 | 3 | ▶ | $opts = [ %$opts ] if ref $opts eq 'HASH'; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 503 | |||||||||||||||||||||||||||||||
| 504 | 3 | my ($need_r, $need_w) = $self->_need($need); | |||||||||||||||||||||||||||||
| 505 | |||||||||||||||||||||||||||||||
| 506 | 3 | ▶ | foreach my $name (ref $names eq 'ARRAY' ? @$names : $names) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 507 | 3 | { my $type = $self->findName($name); | |||||||||||||||||||||||||||||
| 508 | 3 | trace "declare $type $need"; | |||||||||||||||||||||||||||||
| 509 | |||||||||||||||||||||||||||||||
| 510 | 3 | ▶ | if($need_r) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 511 | 2 | ▶ | { defined $self->{XCC_dropts}{$type} | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 512 | and warning __x"reader {name} declared again", name => $name; | ||||||||||||||||||||||||||||||
| 513 | 2 | $self->{XCC_dropts}{$type} = $opts; | |||||||||||||||||||||||||||||
| 514 | } | ||||||||||||||||||||||||||||||
| 515 | |||||||||||||||||||||||||||||||
| 516 | 3 | ▶ | if($need_w) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 517 | 2 | ▶ | { defined $self->{XCC_dwopts}{$type} | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 518 | and warning __x"writer {name} declared again", name => $name; | ||||||||||||||||||||||||||||||
| 519 | 2 | $self->{XCC_dwopts}{$type} = $opts; | |||||||||||||||||||||||||||||
| 520 | } | ||||||||||||||||||||||||||||||
| 521 | } | ||||||||||||||||||||||||||||||
| 522 | |||||||||||||||||||||||||||||||
| 523 | 3 | $self; | |||||||||||||||||||||||||||||
| 524 | } | ||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||
| 527 | sub findName($) | ||||||||||||||||||||||||||||||
| 528 | 28 | ▶ | { my ($self, $name) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
findName: called CC=7 SCAR=24.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 529 | 28 | ▶ | defined $name | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 530 | or panic "findName called without name"; | ||||||||||||||||||||||||||||||
| 531 | |||||||||||||||||||||||||||||||
| 532 | 28 | ▶ | return $name | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 533 | if substr($name, 0, 1) eq '{'; | ||||||||||||||||||||||||||||||
| 534 | |||||||||||||||||||||||||||||||
| 535 | 18 | ▶ | my ($prefix,$local) = $name =~ m/^([\w-]*)\:(\S*)$/ ? ($1,$2) : ('',$name); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 536 | 18 | my $def = $self->{XCC_prefixes}{$prefix}; | |||||||||||||||||||||||||||||
| 537 | 18 | ▶ | unless($def) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 538 | 0 | ▶ | { return $name if $prefix eq ''; # namespace-less | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 539 | trace __x"known prefixes: {prefixes}" | ||||||||||||||||||||||||||||||
| 540 | 0 | , prefixes => [ sort keys %{$self->{XCC_prefixes}} ]; | |||||||||||||||||||||||||||||
| 541 | 0 | error __x"unknown name prefix `{prefix}' for `{name}'" | |||||||||||||||||||||||||||||
| 542 | , prefix => $prefix, name => $name; | ||||||||||||||||||||||||||||||
| 543 | } | ||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||
| 545 | 18 | ▶ | length $local ? pack_type($def->{uri}, $local) : $def->{uri}; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 546 | } | ||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||
| 549 | sub printIndex(@) | ||||||||||||||||||||||||||||||
| 550 | 3 | ▶ | { my $self = shift; | ||||||||||||||||||||||||||||
|
Subroutine
printIndex: called CC=11 SCAR=24.0
Pod
documented
| |||||||||||||||||||||||||||||||
| 551 | 3 | ▶ | my $fh = @_ % 2 ? shift : select; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 552 | 3 | my %args = @_; | |||||||||||||||||||||||||||||
| 553 | 3 | ▶ | my $decl = exists $args{show_declared} ? delete $args{show_declared} : 1; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 554 | |||||||||||||||||||||||||||||||
| 555 | 3 | ▶ | return $self->SUPER::printIndex($fh, %args) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 556 | unless $decl; | ||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||
| 558 | 3 | my $output = ''; | |||||||||||||||||||||||||||||
| 559 | 3 | open my($out), '>', \$output; | |||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||||
| 561 | 3 | $self->SUPER::printIndex($out, %args); | |||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||
| 563 | 3 | close $out; | |||||||||||||||||||||||||||||
| 564 | 3 | my @output = split /(?<=\n)/, $output; | |||||||||||||||||||||||||||||
| 565 | 3 | my $ns = ''; | |||||||||||||||||||||||||||||
| 566 | 3 | foreach (@output) | |||||||||||||||||||||||||||||
| 567 | 18 | ▶ | { $ns = $1 if m/^namespace\:\s+(\S+)/; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 568 | 18 | ▶ | my $local = m/^\s+(\S+)\s*$/ ? $1 : next; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 569 | 12 | my $type = pack_type $ns, $local; | |||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||||
| 571 | substr($_, 1, 1) | ||||||||||||||||||||||||||||||
| 572 | = $self->{XCC_readers}{$type} ? 'R' | ||||||||||||||||||||||||||||||
| 573 | 12 | ▶ | : $self->{XCC_dropts}{$type} ? 'r' : ' '; | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||||
| 575 | substr($_, 2, 1) | ||||||||||||||||||||||||||||||
| 576 | = $self->{XCC_writers}{$type} ? 'W' | ||||||||||||||||||||||||||||||
| 577 | 12 | ▶ | : $self->{XCC_dwopts}{$type} ? 'w' : ' '; | ||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||
| 578 | } | ||||||||||||||||||||||||||||||
| 579 | 3 | $fh->print(@output); | |||||||||||||||||||||||||||||
| 580 | } | ||||||||||||||||||||||||||||||
| 581 | |||||||||||||||||||||||||||||||
| 582 | #--------------- | ||||||||||||||||||||||||||||||
| 583 | # Convert ANY elements and attributes | ||||||||||||||||||||||||||||||
| 584 | |||||||||||||||||||||||||||||||
| 585 | sub _convertAnyTyped(@) | ||||||||||||||||||||||||||||||
| 586 | 0 | ▶ | { my ($self, $type, $nodes, $path, $read) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
_convertAnyTyped: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||
| 588 | 0 | my $key = $read->keyRewrite($type); | |||||||||||||||||||||||||||||
| 589 | 0 | ▶ | my $reader = try { $self->reader($type) }; | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 590 | 0 | ▶ | if($@) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 591 | 0 | { trace "cannot auto-convert 'any': ".$@->wasFatal->message; | |||||||||||||||||||||||||||||
| 592 | 0 | return ($key => $nodes); | |||||||||||||||||||||||||||||
| 593 | } | ||||||||||||||||||||||||||||||
| 594 | 0 | trace "auto-convert known type for 'any': $type"; | |||||||||||||||||||||||||||||
| 595 | |||||||||||||||||||||||||||||||
| 596 | 0 | ▶ | my @nodes = ref $nodes eq 'ARRAY' ? @$nodes : $nodes; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 597 | 0 | my @convert = map $reader->($_), @nodes; | |||||||||||||||||||||||||||||
| 598 | 0 | ▶ | ($key => (@convert==1 ? $convert[0] : \@convert) ); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 599 | } | ||||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||||
| 601 | sub _convertAnySloppy(@) | ||||||||||||||||||||||||||||||
| 602 | 0 | ▶ | { my ($self, $type, $nodes, $path, $read) = @_; | ||||||||||||||||||||||||||||
|
Subroutine
_convertAnySloppy: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||
| 603 | |||||||||||||||||||||||||||||||
| 604 | 0 | my $key = $read->keyRewrite($type); | |||||||||||||||||||||||||||||
| 605 | 0 | ▶ | my $reader = try { $self->reader($type) }; | ||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||
| 606 | 0 | ▶ | if($@) | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 607 | { # unknown type or untyped... | ||||||||||||||||||||||||||||||
| 608 | 0 | my @convert = map XMLin($_), @$nodes; | |||||||||||||||||||||||||||||
| 609 | 0 | ▶ | return ($key => @convert==1 ? $convert[0] : \@convert); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 610 | } | ||||||||||||||||||||||||||||||
| 611 | else | ||||||||||||||||||||||||||||||
| 612 | 0 | { trace "auto-convert known 'any' $type"; | |||||||||||||||||||||||||||||
| 613 | 0 | ▶ | my @nodes = ref $nodes eq 'ARRAY' ? @$nodes : $nodes; | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 614 | 0 | my @convert = map $reader->($_), @nodes; | |||||||||||||||||||||||||||||
| 615 | |||||||||||||||||||||||||||||||
| 616 | 0 | ▶ | ($key => @convert==1 ? $convert[0] : \@convert); | ||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||
| 617 | } | ||||||||||||||||||||||||||||||
| 618 | } | ||||||||||||||||||||||||||||||
| 619 | |||||||||||||||||||||||||||||||
| 620 | 3 | 1; | |||||||||||||||||||||||||||||