| 1 | package PRANG::Graph::Meta::Class; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use MooseX::Method::Signatures; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Moose::Util::TypeConstraints; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | ▶ | 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 | default => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=5 SCAR=34.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | 0 | my @attr = grep { $_->does("PRANG::Graph::Meta::Attr") } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | $self->get_all_attributes; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 0 | my $default_xmlns = ""; #eval { $self->name->xmlns }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | 0 | my %attr_ns; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 0 | for my $attr ( @attr ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 0 | ▶ | my $xmlns = $attr->has_xmlns ? | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | $attr->xmlns : $default_xmlns; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 0 | ▶ | my $xml_name = $attr->has_xml_name ? | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | $attr->xml_name : $attr->name; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 0 | ▶ | $attr_ns{$xmlns//""}{$xml_name} = $attr; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$xmlns // ""
MC/DC0%0/1
$xmlns // ""
$xmlns
Truth table0%0/2
A
A= $xmlns
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 0 | \%attr_ns; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | has 'xml_elements' => | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | isa => "ArrayRef[PRANG::Graph::Meta::Element]", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | is => "ro", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | default => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | 0 | ▶ | my $self = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=7 SCAR=40.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | my @elements = grep { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 0 | $_->does("PRANG::Graph::Meta::Element") | |||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | } $self->get_all_attributes; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 0 | my @e_c = map { $_->associated_class->name } @elements; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | my %e_c_does; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | for my $parent ( @e_c ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | for my $child ( @e_c ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | ▶ | if ( $parent eq $child ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | $e_c_does{$parent}{$child} = 0; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 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)
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | $child->isa($parent); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | $e_c_does{$parent}{$child} = | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | ( $cdp ? -1 : 1 ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | [ map { $elements[$_] } sort { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | ▶ | $e_c_does{$e_c[$a]}{$e_c[$b]} or | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | ($elements[$a]->insertion_order | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | <=> $elements[$b]->insertion_order) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } 0..$#elements ]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | 1 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | has 'graph' => | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | is => "rw", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | isa => "PRANG::Graph::Node", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | lazy => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | required => 1, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | default => sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | 0 | ▶ | $_[0]->build_graph; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | }, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 1 | ; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | 1 | ▶ | method build_graph( ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
Subroutine
__ANON__: not called CC=3 SCAR=23.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | my @nodes = map { $_->graph_node } @{ $self->xml_elements }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | ▶ | if ( @nodes != 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | 0 | PRANG::Graph::Seq->new( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | members => \@nodes, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | elsif ( @nodes ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | 0 | $nodes[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | 1 | } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | sub add_to_list($$) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | ▶ | if ( !defined $_[0] ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
add_to_list: not called CC=4 SCAR=30.0
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | $_[0] = $_[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | ▶ | if ( (ref($_[0])||"") ne "ARRAY" ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/2
ref $_[0] || ''
MC/DC0%0/1
ref $_[0] || ''
ref $_[0]
Truth table0%0/2
A
A= ref $_[0]
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | $_[0] = [ $_[0] ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | 0 | push @{ $_[0] }, $_[1]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | sub as_listref($) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 0 | ▶ | if ( ref($_[0]) eq "ARRAY" ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_listref: not called CC=2 SCAR=17.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | $_[0] | |||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | [ $_[0] ]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | sub as_item($) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | if ( ref($_[0]) eq "ARRAY" ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
as_item: not called CC=2 SCAR=17.9
Pod
undocumented
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 0 | die scalar(@{$_[0]})." item(s) found where 1 expected"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | 0 | $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 1 | ▶ | method accept_attributes( ArrayRef[XML::LibXML::Attr] $node_attr, PRANG::Graph::Context $context ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
Subroutine
__ANON__: not called CC=13 SCAR=51.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | 0 | my $attributes = $self->xml_attr; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 117 | 0 | my %rv; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 118 | # process attributes | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | for my $attr ( @$node_attr ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | my $prefix = $attr->prefix; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | ▶ | if ( !defined $prefix ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | $prefix = ""; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 123 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | if ( length $prefix and !exists $context->xsi->{$prefix} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/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 table0%0/3
A and not(B)
A= length $prefixB= not exists $context->xsi->{$prefix}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | $context->exception("unknown xmlns prefix '$prefix'"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | ▶ | my $xmlns = $context->get_xmlns($prefix) | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 128 | if length $prefix; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 129 | 0 | ▶ | $xmlns //= ""; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$xmlns //= ""
MC/DC0%0/1
$xmlns //= ""
$xmlns
Truth table0%0/2
A
A= $xmlns
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 130 | 0 | my $meta_att = $attributes->{$xmlns}{$attr->localname}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | my $xmlns_att_name; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 132 | my $_xmlns_att_name = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 133 | 0 | ▶ | $xmlns_att_name = $meta_att->xmlns_attr | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 134 | or $context->exception( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 135 | "xmlns wildcarded, but no xmlns_attr set on " | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 136 | .$self->name." property '" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 137 | .$meta_att->att_name."'", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 138 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 139 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 141 | 0 | ▶ | if ( $meta_att ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 142 | # sweet, it's ok | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | my $att_name = $meta_att->name; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | add_to_list($rv{$att_name}, $attr->value); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 146 | elsif ( $meta_att = $attributes->{"*"}{$attr->localname} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 147 | # wildcard xmlns only; need to store the xmlns | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 148 | # in another attribute. Also, multiple values | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 149 | # may appear with different xml namespaces. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 150 | 0 | my $att_name = $meta_att->name; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | $_xmlns_att_name->(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | add_to_list($rv{$att_name}, $attr->value); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | add_to_list($rv{$xmlns_att_name}, $xmlns); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 155 | elsif ( $meta_att = $attributes->{$xmlns}{"*"} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 156 | # wildcard attribute name. This attribute gets | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 157 | # HashRef treatment. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 158 | 0 | $rv{$meta_att->name}{$attr->localname} = $attr->value; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 159 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 160 | elsif ( $meta_att = $attributes->{"*"}{"*"} ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 161 | # wildcard attribute name and namespace. Both | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 162 | # attributes gets the joy of HashRef[ArrayRef[Str]|Str] | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | my $att_name = $meta_att->name; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | $_xmlns_att_name->(); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 165 | add_to_list( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | $rv{$att_name}{$attr->localname}, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 167 | $attr->value, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 168 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 169 | add_to_list( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 170 | 0 | $rv{$xmlns_att_name}{$attr->localname}, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 171 | $xmlns | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 172 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 174 | ▶ | elsif ( $xmlns =~ m{^\w+://\w+\.w3\.org/.*schema}i and | |||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/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 table0%0/3
A and B
A= $xmlns =~ m[^\w+://\w+\.w3\.org/.*schema]iB= $attr->localname =~ /schema/i
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 175 | $attr->localname =~ m{schema}i ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 176 | # they said "schema" twice, they must be mad. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 177 | # ignore their craven input. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 178 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 179 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 180 | # fail. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | $context->exception("invalid attribute '".$attr->name."'"); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 183 | }; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 184 | 0 | (%rv); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 185 | 1 | } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 187 | 1 | ▶ | method accept_childnodes( ArrayRef[XML::LibXML::Node] $childNodes, PRANG::Graph::Context $context ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
Subroutine
__ANON__: not called CC=18 SCAR=57.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | my $graph = $self->graph; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 189 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | my (%init_args, %init_arg_names, %init_arg_xmlns); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 191 | 0 | my @rv; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | ▶ | my @nodes = grep { !( $_->isa("XML::LibXML::Text") | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$_->isa('XML::LibXML::Text') && $_->data =~ /\A\s*\Z/
MC/DC0%0/2
$_->isa('XML::LibXML::Text') && $_->data =~ /\A\s*\Z/
$_->isa('XML::LibXML::Text')
$_->data =~ /\A\s*\Z/
Truth table0%0/3
A && B
A= $_->isa('XML::LibXML::Text')B= $_->data =~ /\A\s*\Z/
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 193 | and $_->data =~ /\A\s*\Z/) } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 194 | @$childNodes; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 195 | 0 | ▶ | while ( my $input_node = shift @nodes ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | ▶ | next if $input_node->nodeType == XML_COMMENT_NODE; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 197 | 0 | my ($key, $value, $name, $xmlns) = | |||||||||||||||||||||||||||||||||||||||||||||||||
| 198 | $graph->accept($input_node, $context); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 199 | 0 | ▶ | if ( !$key ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | my (@what) = $graph->expected($context); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | $context->exception( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 202 | "unexpected node: expecting @what", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 203 | $input_node, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 204 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 205 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | add_to_list($init_args{$key}, $value); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | ▶ | if ( defined $name ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 208 | add_to_list( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | $init_arg_names{$key}, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 210 | $name, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 211 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | ▶ | if ( defined $xmlns ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 214 | add_to_list( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | $init_arg_xmlns{$key}, | |||||||||||||||||||||||||||||||||||||||||||||||||
| 216 | $xmlns, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 217 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 218 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 219 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 221 | 0 | ▶ | if ( !$graph->complete($context) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | my (@what) = $graph->expected($context); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | $context->exception( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 224 | "Node incomplete; expecting: @what", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 225 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 227 | # now, we have to take all the values we just got and | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 228 | # collapse them to init args | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | for my $element ( @{ $self->xml_elements } ) { | |||||||||||||||||||||||||||||||||||||||||||||||||
| 230 | 0 | my $key = $element->name; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 231 | 0 | ▶ | next unless exists $init_args{$key}; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | my $expect; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 233 | 0 | ▶ | if ( $element->has_xml_max and $element->xml_max == 1 ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$element->has_xml_max and $element->xml_max == 1
MC/DC0%0/2
$element->has_xml_max and $element->xml_max == 1
$element->has_xml_max
$element->xml_max == 1
Truth table0%0/3
A and B
A= $element->has_xml_maxB= $element->xml_max == 1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | $expect = \&as_item; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 236 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | $expect = \&as_listref; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | ▶ | push @rv, eval { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 240 | ( ( ( $element->has_xml_nodeName_attr and | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 241 | exists $init_arg_names{$key} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 242 | ? ( $element->xml_nodeName_attr => | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 243 | $expect->($init_arg_names{$key})) : () | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 244 | ), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 245 | ( ( $element->has_xmlns_attr and | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 246 | exists $init_arg_xmlns{$key} ) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 247 | ? ( $element->xmlns_attr => | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 248 | $expect->($init_arg_xmlns{$key})) : () | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 249 | ), | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 250 | 0 | ▶ | $key => $expect->(delete $init_args{$key}), | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
Condition0%0/6
$element->has_xml_nodeName_attr and exists $init_arg_names{$key}
$element->has_xmlns_attr and exists $init_arg_xmlns{$key}
MC/DC0%0/2
$element->has_xml_nodeName_attr and exists $init_arg_names{$key}
$element->has_xml_nodeName_attr
exists $init_arg_names{$key}
MC/DC0%0/2
$element->has_xmlns_attr and exists $init_arg_xmlns{$key}
$element->has_xmlns_attr
exists $init_arg_xmlns{$key}
Truth table0%0/3
A and B
A= $element->has_xml_nodeName_attrB= exists $init_arg_names{$key}
Truth table0%0/3
A and B
A= $element->has_xmlns_attrB= exists $init_arg_xmlns{$key}
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 251 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 252 | } or $context->exception( | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 253 | "internal error: processing '$key' attribute: $@", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 254 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 255 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 256 | 0 | ▶ | if (my @leftovers = keys %init_args) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | $context->exception( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 258 | "internal error: ".@leftovers | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 259 | ." init arg(s) left over (@leftovers)", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 260 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 261 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 262 | 0 | return @rv; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 263 | 1 | } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 265 | 1 | ▶ | method marshall_in_element( XML::LibXML::Node $node, PRANG::Graph::Context $ctx ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
Subroutine
__ANON__: not called CC=7 SCAR=39.3
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 266 | 0 | my @node_attr = grep { $_->isa("XML::LibXML::Attr") } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 267 | $node->attributes; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | my @ns_attr = $node->getNamespaces; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | ▶ | if ( @ns_attr ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 271 | $ctx->add_xmlns($_->declaredPrefix//"" => $_->declaredURI) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | for @ns_attr; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/2
$_->declaredPrefix // ""
MC/DC0%0/1
$_->declaredPrefix // ""
$_->declaredPrefix
Truth table0%0/2
A
A= $_->declaredPrefix
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 273 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 274 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | my $new_ctx = $ctx->next_ctx( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 276 | $node->namespaceURI, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 277 | $node->localname, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 278 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | my @init_args = $self->accept_attributes( \@node_attr, $new_ctx ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 282 | # now process elements | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 283 | my @childNodes = grep { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 284 | 0 | ▶ | !($_->isa("XML::LibXML::Comment") or | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/6
$_->isa('XML::LibXML::Comment') || $_->isa('XML::LibXML::Text') && $_->data =~ /\A\s+\Z/
$_->isa("XML::LibXML::Text") and $_->data =~ /\A\s+\Z/
MC/DC0%0/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 table0%0/4
A || B and C
A= $_->isa('XML::LibXML::Comment')B= $_->isa("XML::LibXML::Text")C= $_->data =~ /\A\s+\Z/
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 285 | $_->isa("XML::LibXML::Text") and $_->data =~ /\A\s+\Z/) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 286 | } $node->childNodes; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | push @init_args, $self->accept_childnodes( \@childNodes, $new_ctx ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | my $value = eval { $self->name->new( @init_args ) }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | ▶ | if ( !$value ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 292 | 0 | $ctx->exception( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 293 | "Validation error from ".$self->name | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 294 | ." constructor: $@)", | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 295 | $node, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 296 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 298 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 299 | 0 | return $value; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 301 | 1 | } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 303 | 1 | ▶ | method add_xml_attr( Object $item, XML::LibXML::Element $node, PRANG::Graph::Context $ctx ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
Subroutine
__ANON__: not called CC=14 SCAR=53.1
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 304 | 0 | my $attributes = $self->xml_attr; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 305 | 0 | ▶ | while ( my ($xmlns, $att) = each %$attributes ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | ▶ | while ( my ($attName, $meta_att) = each %$att ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | my $is_optional; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | my $obj_att_name = $meta_att->name; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | ▶ | if ( $meta_att->has_xml_required ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | $is_optional = !$meta_att->xml_required; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 312 | elsif ( ! $meta_att->is_required ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 313 | # it's optional | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | $is_optional = 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 315 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 316 | # we /could/ use $meta_att->get_value($item) | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 317 | # here, but I consider that to break | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 318 | # encapsulation | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | my $value = $item->$obj_att_name; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | my $xml_att_name = $attName; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | ▶ | if ( $meta_att->has_xml_name ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 322 | 0 | my $method = $meta_att->has_xmlns_attr; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | $xml_att_name = $attName; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | ▶ | if ( $meta_att->has_xmlns_attr ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | my $method = $meta_att->xmlns_attr; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 327 | 0 | $xmlns = $item->$method; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 328 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | ▶ | if ( !defined $value ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | ▶ | die "could not serialize $item; slot " | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 331 | .$meta_att->name." empty" | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 332 | unless $is_optional; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | next; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 336 | my $emit_att = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | ▶ | my ($xmlns, $name, $value) = @_; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | my $prefix; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | ▶ | if ( $xmlns ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 340 | 0 | $prefix = $ctx->get_prefix( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 341 | $xmlns, $item, $node, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 342 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 343 | 0 | ▶ | if ( length $prefix ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | $prefix .= ":"; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 345 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 346 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 347 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | $prefix = ""; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 350 | 0 | $node->setAttribute( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 351 | $prefix.$name, $value, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 352 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 354 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 355 | my $do_array = sub { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 356 | 0 | ▶ | my $att_name = shift; | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 357 | 0 | my $array = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | my $xmlns = shift; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | ▶ | for ( my $i = 0; $i <= $#$array; $i++ ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 360 | 0 | ▶ | $emit_att->( | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$xmlns && $xmlns->[$i]
MC/DC0%0/2
$xmlns && $xmlns->[$i]
$xmlns
$xmlns->[$i]
Truth table0%0/3
A && B
A= $xmlnsB= $xmlns->[$i]
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 361 | $xmlns&&$xmlns->[$i], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 362 | $att_name, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 363 | $array->[$i], | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 364 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 365 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 366 | 0 | }; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 367 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 368 | 0 | ▶ | if ( ref $value eq "HASH" ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 369 | # wildcarded attribute name case | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 370 | 0 | ▶ | while ( my ($att, $val) = each %$value ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 371 | 0 | my $att_xmlns; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 372 | 0 | ▶ | if ( $xmlns ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 373 | 0 | $att_xmlns = $xmlns->{$att}; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 374 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 375 | # now, we can *still* have arrays here.. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 376 | 0 | ▶ | if ( ref $val eq "ARRAY" ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | $do_array->( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 378 | $att, $val, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 379 | $att_xmlns, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 380 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 381 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 382 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 383 | 0 | $emit_att->( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 384 | $att_xmlns, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 385 | $att, $val, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 386 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 387 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 389 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 390 | elsif ( ref $value eq "ARRAY" ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | $do_array->( | |||||||||||||||||||||||||||||||||||||||||||||||||
| 392 | $xml_att_name, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 393 | $value, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 394 | $xmlns, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 395 | ); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 396 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 397 | else { | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | $emit_att->( $xmlns, $xml_att_name, $value ); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 399 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 400 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 401 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 402 | 1 | } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 404 | 1 | ▶ | method to_libxml( Object $item, XML::LibXML::Element $node, PRANG::Graph::Context $ctx ) { | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=1.2
Subroutine
__ANON__: not called CC=1 SCAR=3.5
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 405 | 0 | $self->add_xml_attr($item, $node, $ctx); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | $self->graph->output($item, $node, $ctx); | |||||||||||||||||||||||||||||||||||||||||||||||||
| 407 | 1 | } | |||||||||||||||||||||||||||||||||||||||||||||||||
| 408 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 409 | package Moose::Meta::Class::Custom::Trait::PRANG; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 410 | 0 | ▶ | sub register_implementation { "PRANG::Graph::Meta::Class" } | ||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
register_implementation: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||
| 411 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 412 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||
| 413 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 414 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 416 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 418 | PRANG::Graph::Meta::Class - metaclass metarole for PRANG-enabled classes | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 420 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 422 | package MyClass; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 423 | use Moose; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 424 | use PRANG::Graph; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 425 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 426 | # - or - | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 427 | package MyClass; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 428 | use Moose -traits => ["PRANG"]; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 430 | # - or - | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 431 | package MyClass; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 432 | use Moose; | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 433 | PRANG::Graph::Meta::Class->meta->apply(__PACKAGE__->meta); | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 434 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 435 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 437 | This role defines class properties and methods for PRANG classes' meta | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 438 | objects. ie, the methods it defines are all to be found in | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 439 | C<YourClass-E<gt>meta>, not C<YourClass>. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 441 | The L<PRANG::Graph::Meta::Class> object is the centre of the state | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 442 | machine which defines the parsing and emitting rules for your classes. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 443 | In other words, the I<XML Graph> (see L<PRANG>). Each one corresponds | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 444 | to an XML element (though not all XML elements will require a full | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 445 | object class), and via these objects can be found the lists of | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 446 | elements and attributes which define the XML structure. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 448 | =head1 ATTRIBUTES | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 449 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 450 | =over | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 451 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 452 | =item B<HashRef[HashRef[PRANG::Graph::Meta::Attr]] xml_attr> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 453 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 454 | This read-only property maps from XML namespace and localname to a | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 455 | L<PRANG::Graph::Meta::Attr> object, defining the type of that | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 456 | attribute and other things described on its perldoc. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 458 | The first time it is accessed, it is built - so be sure to carry out | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 459 | any run-time meta magic before parsing or emitting objects of that | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 460 | type. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 462 | =item B<ArrayRef[PRANG::Graph::Meta::Element] xml_elements> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 463 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 464 | This contains an ordered list of all of the XML elements which exist | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 465 | in this class. See L<PRANG::Graph::Meta::Element>. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 466 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 467 | Like C<xml_attr>, the first time it is accessed it is built. There | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 468 | are currently some problems with ordering and role composition; as the | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 469 | ordering of elements is returned from a moose accessor, but when | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 470 | composing roles into classes, they are applied in any order. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 471 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 472 | =item B<PRANG::Graph::Node graph> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 473 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 474 | The C<graph> property is the acceptor and emitter for the child nodes | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 475 | of this class. See L<PRANG::Graph::Node> for the low-down. This is | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 476 | constructed by a transform on the B<xml_elements> property. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 478 | =back | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 480 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 482 | =head2 B<accept_attributes(\@node_attr, $ctx)> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 483 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 484 | =head2 B<accept_childnodes(\@childNodes, $ctx)> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 485 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 486 | =head2 B<marshall_in_element($node, $ctx)> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 487 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 488 | These methods are the parsing machinery, their API is quite subject to | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 489 | change; the methods provided by the L<PRANG::Graph> role are what you | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 490 | should be using, unless you are writing a PRANG extension. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 491 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 492 | =head2 B<add_xml_attr($item, $node, $ctx)> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 493 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 494 | =head2 B<to_libxml($item, $node, $ctx)> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 495 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 496 | Similarly, these are the emitting methods. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 497 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 498 | =head1 SEE ALSO | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 499 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 500 | L<PRANG::Graph::Meta::Attr>, L<PRANG::Graph::Meta::Element>, | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 501 | L<PRANG::Graph::Node> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 502 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 503 | =head1 AUTHOR AND LICENCE | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 505 | Development commissioned by NZ Registry Services, and carried out by | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 506 | Catalyst IT - L<http://www.catalyst.net.nz/> | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 507 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 508 | Copyright 2009, 2010, NZ Registry Services. This module is licensed | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 509 | under the Artistic License v2.0, which permits relicensing under other | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 510 | Free Software licenses. | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 511 | |||||||||||||||||||||||||||||||||||||||||||||||||||
| 512 | =cut | ||||||||||||||||||||||||||||||||||||||||||||||||||
| 513 | |||||||||||||||||||||||||||||||||||||||||||||||||||