| 1 | package PRANG::Graph::Meta::Class; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 11 | $PRANG::Graph::Meta::Class::VERSION = '0.21'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 11 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 11 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 11 | ▶ | use Moose::Util::TypeConstraints; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 11 | ▶ | use MooseX::Params::Validate; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 11 | ▶ | use XML::LibXML; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | has 'xml_attr' => | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | isa => "HashRef[HashRef[PRANG::Graph::Meta::Attr]]", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | is => "ro", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 39 | ▶ | default => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 39 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 39 | my @attr = grep { $_->does("PRANG::Graph::Meta::Attr") } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | $self->get_all_attributes; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 39 | my $default_xmlns = ""; #eval { $self->name->xmlns }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 39 | my %attr_ns; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 39 | for my $attr (@attr) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 33 | ▶ | my $xmlns = $attr->has_xmlns | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | ? | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | $attr->xmlns | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | : $default_xmlns; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 33 | ▶ | my $xml_name = $attr->has_xml_name | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | ? | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | $attr->xml_name | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | : $attr->name; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 33 | ▶ | $attr_ns{$xmlns//""}{$xml_name} = $attr; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$xmlns // ""
MC/DC0%0/1
$xmlns // ""
$xmlns
Truth table50%1/2
A
A= $xmlns
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 39 | \%attr_ns; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 11 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | has 'xml_elements' => | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | isa => "ArrayRef[PRANG::Graph::Meta::Element]", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | is => "ro", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 41 | ▶ | default => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=23.2
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 41 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | my @elements = grep { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 41 | $_->does("PRANG::Graph::Meta::Element") | |||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | } $self->get_all_attributes; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 41 | my @e_c = map { $_->associated_class->name } @elements; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 41 | my %e_c_does; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 41 | for my $parent (@e_c) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 92 | for my $child (@e_c) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 518 | ▶ | if ( $parent eq $child ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 518 | $e_c_does{$parent}{$child} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | ▶ | my $cdp = $child->does($parent) || | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$child->does($parent) || $child->isa($parent)
MC/DC0%0/2
$child->does($parent) || $child->isa($parent)
$child->does($parent)
$child->isa($parent)
Truth table0%0/3
A || B
A= $child->does($parent)B= $child->isa($parent)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | $child->isa($parent); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | 0 | ▶ | $e_c_does{$parent}{$child} = | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | ( $cdp ? -1 : 1 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 92 | [ map { $elements[$_] } sort { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 41 | ▶ | $e_c_does{$e_c[$a]}{$e_c[$b]} or | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$e_c_does{$e_c[$a]}{$e_c[$b]} || $elements[$a]->insertion_order <=> $elements[$b]->insertion_order
MC/DC0%0/2
$e_c_does{$e_c[$a]}{$e_c[$b]} || $elements[$a]->insertion_order <=> $elements[$b]->insertion_order
$e_c_does{$e_c[$a]}{$e_c[$b]}
$elements[$a]->insertion_order <=> $elements[$b]->insertion_order
Truth table33%1/3
A || B
A= $e_c_does{$e_c[$a]}{$e_c[$b]}B= $elements[$a]->insertion_order <=> $elements[$b]->insertion_order
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | ( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | $elements[$a]->insertion_order | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | <=> $elements[$b]->insertion_order | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } 0..$#elements | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 11 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | has 'graph' => | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | is => "rw", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | isa => "PRANG::Graph::Node", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 41 | ▶ | default => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 41 | $_[0]->build_graph; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 11 | ; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 41 | ▶ | sub build_graph { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
build_graph: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 41 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 41 | my @nodes = map { $_->graph_node } @{ $self->xml_elements }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | 41 | ▶ | if ( @nodes != 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | 12 | PRANG::Graph::Seq->new( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | members => \@nodes, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | elsif (@nodes) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 29 | $nodes[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 1360 | ▶ | sub add_to_list($$) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_to_list: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | 1360 | ▶ | if ( !defined $_[0] ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 1052 | $_[0] = $_[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 308 | ▶ | if ( (ref($_[0])||"") ne "ARRAY" ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%2/2
ref $_[0] || ''
MC/DC100%1/1
ref $_[0] || ''
ref $_[0]
Truth table100%2/2
A
A= ref $_[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 153 | $_[0] = [ $_[0] ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 308 | push @{ $_[0] }, $_[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 107 | ▶ | sub as_listref($) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_listref: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 107 | ▶ | if ( ref($_[0]) eq "ARRAY" ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 51 | $_[0] | |||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 56 | [ $_[0] ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 211 | ▶ | sub as_item($) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_item: called CC=2 SCAR=9.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | 211 | ▶ | if ( ref($_[0]) eq "ARRAY" ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | die scalar(@{$_[0]})." item(s) found where 1 expected"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 211 | $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | 264 | ▶ | sub accept_attributes { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
accept_attributes: called CC=17 SCAR=28.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 264 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 264 | my ( $node_attr, $context, $lax ) = pos_validated_list( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | \@_, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | { isa => 'ArrayRef[XML::LibXML::Attr]' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | { isa => 'PRANG::Graph::Context' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | { isa => 'Bool', optional => 1, default => 0 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | 264 | my $attributes = $self->xml_attr; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 264 | my %rv; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | # process attributes | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | 264 | for my $attr (@$node_attr) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | 100 | my $prefix = $attr->prefix; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | 100 | ▶ | if ( !defined $prefix ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 74 | $prefix = ""; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 100 | ▶ | if ( length $prefix and !exists $context->xsi->{$prefix} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
length $prefix and not exists $context->xsi->{$prefix}
MC/DC0%0/2
length $prefix and not exists $context->xsi->{$prefix}
length $prefix
not exists $context->xsi->{$prefix}
Truth table66%2/3
A and not(B)
A= length $prefixB= not exists $context->xsi->{$prefix}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | 0 | $context->exception("unknown xmlns prefix '$prefix'"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 100 | ▶ | my $xmlns = $context->get_xmlns($prefix) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | if length $prefix; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | 100 | ▶ | $xmlns //= ""; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$xmlns //= ""
MC/DC100%1/1
$xmlns //= ""
$xmlns
Truth table100%2/2
A
A= $xmlns
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | 100 | my $meta_att = $attributes->{$xmlns}{$attr->localname}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | 100 | my $xmlns_att_name; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | 34 | ▶ | my $_xmlns_att_name = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 34 | ▶ | $xmlns_att_name = $meta_att->xmlns_attr | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | or $context->exception( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | "xmlns wildcarded, but no xmlns_attr set on " | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | .$self->name." property '" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | .$meta_att->att_name."'", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | 100 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 100 | ▶ | if ($meta_att) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | # sweet, it's ok | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | 57 | my $att_name = $meta_att->name; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | # check the type constraint | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 57 | ▶ | if ( my $tc = $meta_att->type_constraint | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
my $tc = $meta_att->type_constraint and not $meta_att->xml_isa
MC/DC50%1/2
my $tc = $meta_att->type_constraint and not $meta_att->xml_isa
my $tc = $meta_att->type_constraint
not $meta_att->xml_isa
Truth table66%2/3
A and not(B)
A= my $tc = $meta_att->type_constraintB= not $meta_att->xml_isa
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | and !$meta_att->xml_isa ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | 56 | ▶ | if ( !$tc->check($attr->value) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | 2 | $context->exception( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | "invalid value '" . $attr->value . "' of attribute ".$attr->nodeName, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | $attr->parentNode, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | 55 | add_to_list($rv{$att_name}, $attr->value); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | elsif ( $meta_att = $attributes->{"*"}{$attr->localname} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | # wildcard xmlns only; need to store the xmlns | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | # in another attribute. Also, multiple values | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | # may appear with different xml namespaces. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 6 | my $att_name = $meta_att->name; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | 6 | $_xmlns_att_name->(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | 6 | add_to_list($rv{$att_name}, $attr->value); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 6 | add_to_list($rv{$xmlns_att_name}, $xmlns); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | elsif ( $meta_att = $attributes->{$xmlns}{"*"} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | # wildcard attribute name. This attribute gets | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | # HashRef treatment. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 6 | $rv{$meta_att->name}{$attr->localname} = $attr->value; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | elsif ( $meta_att = $attributes->{"*"}{"*"} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | # wildcard attribute name and namespace. Both | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | # attributes gets the joy of HashRef[ArrayRef[Str]|Str] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 28 | my $att_name = $meta_att->name; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 28 | $_xmlns_att_name->(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | add_to_list( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 28 | $rv{$att_name}{$attr->localname}, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | $attr->value, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | add_to_list( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | 28 | $rv{$xmlns_att_name}{$attr->localname}, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | $xmlns | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | ▶ | elsif ( | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition33%1/3
$xmlns =~ m[^\w+://\w+\.w3\.org/.*schema]i and $attr->localname =~ /schema/i
MC/DC0%0/2
$xmlns =~ m[^\w+://\w+\.w3\.org/.*schema]i and $attr->localname =~ /schema/i
$xmlns =~ m[^\w+://\w+\.w3\.org/.*schema]i
$attr->localname =~ /schema/i
Truth table33%1/3
A and B
A= $xmlns =~ m[^\w+://\w+\.w3\.org/.*schema]iB= $attr->localname =~ /schema/i
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | $xmlns =~ m{^\w+://\w+\.w3\.org/.*schema}i | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | and | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | $attr->localname =~ m{schema}i | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | # they said "schema" twice, they must be mad. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | # ignore their craven input. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | # fail, unless we're in lax mode, in which case do nothing. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | 3 | ▶ | $context->exception("invalid attribute '".$attr->name."'") | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | unless $lax; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 260 | (%rv); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | 11 | ▶ | use JSON; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | 272 | ▶ | sub accept_childnodes { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
accept_childnodes: called CC=24 SCAR=33.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 272 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 272 | my ( $childNodes, $context, $lax ) = pos_validated_list( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | \@_, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | { isa => 'ArrayRef[XML::LibXML::Node]' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | { isa => 'PRANG::Graph::Context' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | { isa => 'Bool', optional => 1, default => 0 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | 272 | my $graph = $self->graph; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | 272 | my (%init_args, %init_arg_names, %init_arg_xmlns, %init_arg_nodes); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | 272 | my @rv; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | my @nodes = grep { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | 272 | ▶ | !( $_->isa("XML::LibXML::Text") | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$_->isa('XML::LibXML::Text') && $_->data =~ /\A\s*\Z/
MC/DC100%2/2
$_->isa('XML::LibXML::Text') && $_->data =~ /\A\s*\Z/
$_->isa('XML::LibXML::Text')
$_->data =~ /\A\s*\Z/
Truth table100%3/3
A && B
A= $_->isa('XML::LibXML::Text')B= $_->data =~ /\A\s*\Z/
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | and $_->data =~ /\A\s*\Z/ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | @$childNodes; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | 272 | ▶ | while ( my $input_node = shift @nodes ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | 410 | ▶ | next if $input_node->nodeType == XML_COMMENT_NODE; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 410 | my ($key, $value, $name, $xmlns) = | |||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | $graph->accept($input_node, $context, $lax); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | 383 | ▶ | if ( !$key ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | 5 | ▶ | next if $lax; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | 2 | my (@what) = $graph->expected($context); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 2 | $context->exception( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | "unexpected node: expecting @what", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | $input_node, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | 378 | my $meta_att = $self->find_attribute_by_name($key); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 378 | ▶ | if ( !$meta_att->_item_tc->check($value) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 4 | $context = $context->next_ctx( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | $input_node->namespaceURI, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | $input_node->localname, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | 4 | $context->exception( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | "bad value '$value'", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | $input_node | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 374 | add_to_list($init_args{$key}, $value); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | 374 | add_to_list($init_arg_nodes{$key}, $input_node); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | 374 | ▶ | if ( defined $name ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | add_to_list( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | 135 | $init_arg_names{$key}, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | $name, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 374 | ▶ | if ( defined $xmlns ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | add_to_list( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | 354 | $init_arg_xmlns{$key}, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | $xmlns, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 239 | ▶ | if ( !$graph->complete($context) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | 6 | my (@what) = $graph->expected($context); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 6 | $context->exception( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | "Node incomplete; expecting: @what", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | # now, we have to take all the values we just got and | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | # collapse them to init args | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | 233 | for my $element ( @{ $self->xml_elements } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | 805 | my $key = $element->name; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 805 | ▶ | next unless exists $init_args{$key}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | 273 | my $expect; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 273 | ▶ | if ( $element->has_xml_max and $element->xml_max == 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$element->has_xml_max and $element->xml_max == 1
MC/DC100%2/2
$element->has_xml_max and $element->xml_max == 1
$element->has_xml_max
$element->xml_max == 1
Truth table100%3/3
A and B
A= $element->has_xml_maxB= $element->xml_max == 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | 202 | $expect = \&as_item; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 71 | $expect = \&as_listref; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | push @rv, eval { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 273 | my $val = $expect->(delete $init_args{$key}); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 273 | ▶ | if ( my $t_c = $element->type_constraint) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 273 | ▶ | if ( !$t_c->check($val) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | ▶ | if ( ref $val ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | $val = encode_json $val; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | die "value '$val' failed type check"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | ( ( ( $element->has_xml_nodeName_attr | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | and | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | exists $init_arg_names{$key} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | ? ( $element->xml_nodeName_attr => | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | $expect->($init_arg_names{$key}) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | : () | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | ), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | ( ( $element->has_xmlns_attr | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | and | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | exists $init_arg_xmlns{$key} | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | ? ( $element->xmlns_attr => | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | 273 | ▶ | $expect->($init_arg_xmlns{$key}) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition66%4/6
$element->has_xml_nodeName_attr and exists $init_arg_names{$key}
$element->has_xmlns_attr and exists $init_arg_xmlns{$key}
MC/DC50%1/2
$element->has_xml_nodeName_attr and exists $init_arg_names{$key}
$element->has_xml_nodeName_attr
exists $init_arg_names{$key}
MC/DC50%1/2
$element->has_xmlns_attr and exists $init_arg_xmlns{$key}
$element->has_xmlns_attr
exists $init_arg_xmlns{$key}
Truth table66%2/3
A and B
A= $element->has_xml_nodeName_attrB= exists $init_arg_names{$key}
Truth table66%2/3
A and B
A= $element->has_xmlns_attrB= exists $init_arg_xmlns{$key}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | : () | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | ), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | $key => $val, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 273 | ▶ | } or do { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | my $err = $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | my $bad = $init_arg_nodes{$key}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | ▶ | if ( ref $bad eq "ARRAY" ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | $bad = $bad->parentNode; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | $context = | |||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | $context->next_ctx($bad->namespaceURI, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | $bad->localname); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | $context->exception( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | "internal error: processing '$key' attribute: $err", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | $bad, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | 233 | ▶ | if (my @leftovers = keys %init_args) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | $context->exception( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | "internal error: ".@leftovers | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | ." init arg(s) left over (@leftovers)", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 233 | return @rv; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | 259 | ▶ | sub marshall_in_element { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
marshall_in_element: called CC=7 SCAR=19.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | 259 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 259 | my ( $node, $ctx, $lax ) = pos_validated_list( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | \@_, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | { isa => 'XML::LibXML::Node' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | { isa => 'PRANG::Graph::Context' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | { isa => 'Bool', optional => 1, default => 0 }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 259 | my @node_attr = grep { $_->isa("XML::LibXML::Attr") } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | $node->attributes; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | 259 | my @ns_attr = $node->getNamespaces; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 259 | ▶ | if (@ns_attr) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | $ctx->add_xmlns($_->declaredPrefix//"" => $_->declaredURI) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | 28 | ▶ | for @ns_attr; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$_->declaredPrefix // ""
MC/DC100%1/1
$_->declaredPrefix // ""
$_->declaredPrefix
Truth table100%2/2
A
A= $_->declaredPrefix
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | 259 | my $new_ctx = $ctx->next_ctx( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | $node->namespaceURI, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | $node->localname, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | 259 | my @init_args = $self->accept_attributes( \@node_attr, $new_ctx, $lax ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | # now process elements | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | my @childNodes = grep { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 257 | ▶ | !( $_->isa("XML::LibXML::Comment") | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition83%5/6
$_->isa('XML::LibXML::Comment') || $_->isa('XML::LibXML::Text') && $_->data =~ /\A\s+\Z/
$_->isa("XML::LibXML::Text") and $_->data =~ /\A\s+\Z/
MC/DC66%2/3
$_->isa('XML::LibXML::Comment') || $_->isa('XML::LibXML::Text') && $_->data =~ /\A\s+\Z/
$_->isa('XML::LibXML::Comment')
$_->isa("XML::LibXML::Text")
$_->data =~ /\A\s+\Z/
Truth table75%3/4
A || B and C
A= $_->isa('XML::LibXML::Comment')B= $_->isa("XML::LibXML::Text")C= $_->data =~ /\A\s+\Z/
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | or | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | $_->isa("XML::LibXML::Text") and $_->data =~ /\A\s+\Z/ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | } $node->childNodes; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | 257 | push @init_args, $self->accept_childnodes( \@childNodes, $new_ctx, $lax ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | 227 | my $value = eval { $self->name->new(@init_args) }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | 227 | ▶ | if ( !$value ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | 0 | my $error = $@; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | $error =~ m|^(.+) at /|; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | 0 | my $msg = $1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | $ctx->exception( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | "Validation error from ".$self->name | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | ." constructor: $1", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | $node, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | 227 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | 144 | ▶ | sub add_xml_attr { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_xml_attr: called CC=14 SCAR=26.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | 144 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | 144 | my ( $item, $node, $ctx ) = pos_validated_list( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | \@_, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | { isa => 'Object' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | { isa => 'XML::LibXML::Element' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | { isa => 'PRANG::Graph::Context' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | 144 | my $attributes = $self->xml_attr; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | 144 | ▶ | while ( my ($xmlns, $att) = each %$attributes ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | 117 | ▶ | while ( my ($attName, $meta_att) = each %$att ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | 97 | my $is_optional; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | 97 | my $obj_att_name = $meta_att->name; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | 97 | ▶ | if ( $meta_att->has_xml_required ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | 48 | $is_optional = !$meta_att->xml_required; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | elsif ( !$meta_att->is_required ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | # it's optional | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | 47 | $is_optional = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | # we /could/ use $meta_att->get_value($item) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | # here, but I consider that to break | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | # encapsulation | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | 97 | my $value = $item->$obj_att_name; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | 97 | my $xml_att_name = $attName; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | 97 | ▶ | if ( $meta_att->has_xml_name ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | 43 | my $method = $meta_att->has_xmlns_attr; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | 43 | $xml_att_name = $attName; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | 97 | ▶ | if ( $meta_att->has_xmlns_attr ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | 24 | my $method = $meta_att->xmlns_attr; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | 24 | $xmlns = $item->$method; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | 97 | ▶ | if ( !defined $value ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | 43 | ▶ | die "could not serialize $item; slot " | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | .$meta_att->name." empty" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | unless $is_optional; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | 43 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | 68 | ▶ | my $emit_att = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | 68 | my ($xmlns, $name, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | 68 | my $prefix; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | 68 | ▶ | if ($xmlns) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | 14 | $prefix = $ctx->get_prefix( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | $xmlns, $item, $node, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | 14 | ▶ | if ( length $prefix ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | 14 | $prefix .= ":"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | 54 | $prefix = ""; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | 68 | $node->setAttribute( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | $prefix.$name, $value, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | 54 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | 5 | ▶ | my $do_array = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | 5 | my $att_name = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | 5 | my $array = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | 5 | my $xmlns = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | 5 | ▶ | for ( my $i = 0; $i <= $#$array; $i++ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | 15 | ▶ | $emit_att->( | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$xmlns && $xmlns->[$i]
MC/DC50%1/2
$xmlns && $xmlns->[$i]
$xmlns
$xmlns->[$i]
Truth table66%2/3
A && B
A= $xmlnsB= $xmlns->[$i]
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | $xmlns&&$xmlns->[$i], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | $att_name, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | $array->[$i], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | 54 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | 54 | ▶ | if ( ref $value eq "HASH" ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | # wildcarded attribute name case | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | 11 | ▶ | while ( my ($att, $val) = each %$value ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | 15 | my $att_xmlns; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | 15 | ▶ | if ($xmlns) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | 12 | $att_xmlns = $xmlns->{$att}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | # now, we can *still* have arrays here.. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | 15 | ▶ | if ( ref $val eq "ARRAY" ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | 4 | $do_array->( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | $att, $val, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | $att_xmlns, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | 11 | $emit_att->( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | $att_xmlns, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | $att, $val, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 514 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 515 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 516 | elsif ( ref $value eq "ARRAY" ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 517 | 1 | $do_array->( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 518 | $xml_att_name, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 519 | $value, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 520 | $xmlns, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 521 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 522 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 523 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 524 | 42 | $emit_att->( $xmlns, $xml_att_name, $value ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 525 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 526 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 527 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 528 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 530 | 142 | ▶ | sub to_libxml { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_libxml: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 531 | 142 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 533 | 142 | my ( $item, $node, $ctx ) = pos_validated_list( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 534 | \@_, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 535 | { isa => 'Object' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 536 | { isa => 'XML::LibXML::Element' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 537 | { isa => 'PRANG::Graph::Context' }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 538 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 540 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 541 | 142 | $self->add_xml_attr($item, $node, $ctx); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 542 | 142 | $self->graph->output($item, $node, $ctx); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 543 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 544 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 545 | package Moose::Meta::Class::Custom::Trait::PRANG; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 546 | 11 | $Moose::Meta::Class::Custom::Trait::PRANG::VERSION = '0.21'; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 547 | 0 | ▶ | sub register_implementation {"PRANG::Graph::Meta::Class"} | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
register_implementation: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 548 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 549 | 11 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 550 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 551 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||