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