| 1 | 4 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 2 | 4 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 4 | package XML::BindData; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 5 | 4 | $XML::BindData::VERSION = '0.3.2'; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 6 | 4 | ▶ | use XML::LibXML; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 8 | 52 | ▶ | sub bind { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
bind: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 9 | 52 | my ($class, $xml_string, $data) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 11 | 52 | my $xml = XML::LibXML->load_xml(string => $xml_string); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 12 | 52 | parse_node($xml->documentElement, $data); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 14 | 52 | return $xml->toStringC14N(1); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 17 | 134 | ▶ | sub parse_node { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_node: called CC=21 SCAR=30.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 18 | 134 | my ($node, $context) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 20 | 134 | ▶ | if (my $if_key = _strip_attr($node, 'tmpl-if')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 16 | my $unless = $if_key =~ s/^!//; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 22 | 16 | my $val = _get($context, $if_key); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 23 | 16 | ▶ | if ( (!$unless && ! defined $val) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%9/9
not $unless || defined $val or $unless and defined $val
$unless || defined $val
$unless and defined $val
MC/DC100%4/4
not $unless || defined $val or $unless and defined $val
$unless
defined $val
$unless
defined $val
Truth table57%4/7
not(A || B) or C and D
A= $unlessB= defined $valC= $unlessD= defined $val
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 24 | || ( $unless && defined $val)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 25 | 6 | $node->unbindNode; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 29 | 134 | ▶ | if (my $each_key = _strip_attr($node, 'tmpl-each')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 30 | 20 | my $parent = $node->parentNode; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 32 | 20 | my $to_add = _get($context, $each_key); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 33 | 20 | ▶ | if (!$to_add || ref $to_add ne 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
not $to_add or ref $to_add ne "ARRAY"
MC/DC0%0/2
not $to_add or ref $to_add ne "ARRAY"
not $to_add
ref $to_add ne "ARRAY"
Truth table33%1/3
not(A) or B
A= not $to_addB= ref $to_add ne "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 0 | $to_add = []; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 35 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 37 | 20 | foreach my $subcontext ( reverse @$to_add ) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 42 | my $new = $node->cloneNode(1); # deep clone | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 42 | parse_node($new, $subcontext); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 40 | 42 | $parent->insertAfter( $new, $node ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 42 | 20 | $node->unbindNode; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 20 | return; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 46 | 114 | ▶ | if (my $binding = _strip_attr($node, 'tmpl-bind')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 47 | 48 | my $val = _get($context, $binding); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 48 | my $default = _strip_attr($node, 'tmpl-default'); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 50 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 48 | ▶ | unless (defined $val) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 52 | 4 | ▶ | $val = defined $default ? $default : ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 55 | 48 | $node->appendTextNode($val); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 56 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 58 | 114 | ▶ | if (my $attr_map = _strip_attr($node, 'tmpl-attr-map')) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 59 | 14 | my @attributes = map { [ split qr/:/ ] } split qr/,/, $attr_map; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 61 | 14 | foreach (@attributes) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 34 | my $value = _get( $context, $_->[1] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 34 | ▶ | $node->setAttribute( $_->[0], $value ) if defined $value; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 114 | ▶ | if ( my $attr_defaults = _strip_attr( $node, 'tmpl-attr-defaults' ) ) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 68 | my @attributes | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 69 | = map { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 70 | 8 | [ map { s/\\([:,])/$1/g; $_ } # remove backslash escaping | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 71 | split qr/(?<!\\):/ # split on non-backslashed colons | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 72 | ] | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 74 | split qr/(?<!\\),/, # split on non-backslashed commas | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 75 | $attr_defaults; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 77 | 8 | foreach (@attributes) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 78 | 20 | my $value = $node->getAttribute( $_->[0] ); | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 20 | ▶ | $node->setAttribute( $_->[0], $_->[1] ) | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $value or $value eq ""
MC/DC50%1/2
not defined $value or $value eq ""
not defined $value
$value eq ""
Truth table66%2/3
not(A) or B
A= not defined $valueB= $value eq ""
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 80 | if ! defined $value || $value eq ''; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 81 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 84 | my @children = grep { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 85 | 114 | $_->nodeType eq XML_ELEMENT_NODE | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 86 | } $node->childNodes; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 87 | 114 | parse_node($_, $context) foreach @children; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 90 | 116 | ▶ | sub _get { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_get: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 91 | 116 | my ($context, $key) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 93 | 116 | ▶ | return '' if !defined $key; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 95 | 116 | ▶ | return $context if $key eq 'this'; | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 97 | 84 | my @parts = split qr/\./, $key; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 98 | 84 | foreach (@parts) { | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 99 | 88 | $context = $context->{$_}; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 101 | 84 | return $context; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 104 | 658 | ▶ | sub _strip_attr { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_strip_attr: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 105 | 658 | my ($node, $attr_name) = @_; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 107 | 658 | ▶ | if (my $attributes = $node->attributes) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 108 | 658 | ▶ | if (my $attr = $attributes->removeNamedItem($attr_name)) { | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 109 | 110 | return $attr->nodeValue; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 111 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 114 | 4 | 1; | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| 116 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||