| 1 | package XML::Loy::XRD; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 3 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use Mojo::JSON qw/encode_json decode_json/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 3 | ▶ | use Mojo::Util 'quote'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use Carp qw/carp/; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use XML::Loy::Date::RFC3339; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use XML::Loy with => ( | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | mime => 'application/xrd+xml', | ||||||||||||||||||||||||||||||||||||||||||
| 12 | namespace => 'http://docs.oasis-open.org/ns/xri/xrd-1.0', | ||||||||||||||||||||||||||||||||||||||||||
| 13 | prefix => 'xrd', | ||||||||||||||||||||||||||||||||||||||||||
| 14 | 530 | ▶ | on_init => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 15 | shift->namespace( | ||||||||||||||||||||||||||||||||||||||||||
| 16 | 530 | xsi => 'http://www.w3.org/2001/XMLSchema-instance' | |||||||||||||||||||||||||||||||||||||||||
| 17 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 18 | } | ||||||||||||||||||||||||||||||||||||||||||
| 19 | 3 | ); | |||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 3 | our @CARP_NOT; | |||||||||||||||||||||||||||||||||||||||||
| 22 | |||||||||||||||||||||||||||||||||||||||||||
| 23 | # Constructor | ||||||||||||||||||||||||||||||||||||||||||
| 24 | 527 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 25 | 527 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 527 | my $xrd; | |||||||||||||||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||||||||||||||||
| 29 | # Empty | ||||||||||||||||||||||||||||||||||||||||||
| 30 | 527 | ▶ | unless ($_[0]) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 516 | unshift(@_, 'XRD'); | |||||||||||||||||||||||||||||||||||||||||
| 32 | 516 | $xrd = $class->SUPER::new(@_); | |||||||||||||||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | # JRD | ||||||||||||||||||||||||||||||||||||||||||
| 36 | elsif ($_[0] =~ /^\s*\{/) { | ||||||||||||||||||||||||||||||||||||||||||
| 37 | 2 | $xrd = $class->SUPER::new('XRD'); | |||||||||||||||||||||||||||||||||||||||||
| 38 | 2 | $xrd->_to_xml($_[0]); | |||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | # Whatever | ||||||||||||||||||||||||||||||||||||||||||
| 42 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 43 | 9 | $xrd = $class->SUPER::new(@_); | |||||||||||||||||||||||||||||||||||||||||
| 44 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 45 | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 527 | return $xrd; | |||||||||||||||||||||||||||||||||||||||||
| 47 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | # Set subject | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 9 | ▶ | sub subject { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
subject: called CC=5 SCAR=16.6
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 52 | 9 | ▶ | my $self = $_[0]->type eq 'root' ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 53 | shift : shift->root; | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | # Return subject | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 9 | ▶ | unless ($_[0]) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | |||||||||||||||||||||||||||||||||||||||||||
| 58 | # Subject found | ||||||||||||||||||||||||||||||||||||||||||
| 59 | 3 | ▶ | my $sub = $self->at('Subject') or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 60 | 3 | return $sub->text; | |||||||||||||||||||||||||||||||||||||||||
| 61 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 6 | my $new_node = $self->set(Subject => @_); | |||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||
| 65 | # Set subject (only once) | ||||||||||||||||||||||||||||||||||||||||||
| 66 | 6 | ▶ | if (my $np = $self->at('*:root > *')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | # Put in correct order - maybe not effective | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 6 | my $clone = $self->at('Subject'); | |||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | 6 | $self->at('Subject')->remove; | |||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | # return $np->prepend($clone); | ||||||||||||||||||||||||||||||||||||||||||
| 74 | 6 | return $np->prepend($clone->to_string); | |||||||||||||||||||||||||||||||||||||||||
| 75 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||||||||||||||||
| 77 | # Set subject | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | return $new_node; | |||||||||||||||||||||||||||||||||||||||||
| 79 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | # Add alias | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 11 | ▶ | sub alias { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
alias: called CC=5 SCAR=16.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 84 | 11 | ▶ | my $self = $_[0]->type eq 'root' ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 85 | shift : shift->root; | ||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | # Return subject | ||||||||||||||||||||||||||||||||||||||||||
| 88 | 11 | ▶ | unless ($_[0]) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||||||||||||||||
| 90 | # Subject found | ||||||||||||||||||||||||||||||||||||||||||
| 91 | 3 | ▶ | my $sub = $self->find('Alias') or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 92 | 3 | return @{ $sub->map('text') }; | |||||||||||||||||||||||||||||||||||||||||
| 93 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | # Add new alias | ||||||||||||||||||||||||||||||||||||||||||
| 96 | 8 | $self->add(Alias => $_) foreach @_; | |||||||||||||||||||||||||||||||||||||||||
| 97 | |||||||||||||||||||||||||||||||||||||||||||
| 98 | 8 | return 1; | |||||||||||||||||||||||||||||||||||||||||
| 99 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 100 | |||||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | # Add Property | ||||||||||||||||||||||||||||||||||||||||||
| 103 | 32 | ▶ | sub property { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
property: called CC=7 SCAR=19.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 104 | 32 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | 32 | ▶ | return unless $_[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | |||||||||||||||||||||||||||||||||||||||||||
| 108 | 31 | my $type = shift; | |||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | # Returns the first match | ||||||||||||||||||||||||||||||||||||||||||
| 111 | 31 | ▶ | return $self->at( qq{Property[type="$type"]} ) unless scalar @_ >= 1; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | |||||||||||||||||||||||||||||||||||||||||||
| 113 | # Get possible attributes | ||||||||||||||||||||||||||||||||||||||||||
| 114 | 11 | ▶ | my %hash = ($_[0] && ref $_[0] && ref $_[0] eq 'HASH') ? %{ shift(@_) } : (); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$_[0] and ref $_[0] and ref $_[0] eq "HASH"
$_[0] and ref $_[0]
MC/DC66%2/3
$_[0] and ref $_[0] and ref $_[0] eq "HASH"
$_[0]
ref $_[0]
ref $_[0] eq "HASH"
Truth table75%3/4
A and B and C
A= $_[0]B= ref $_[0]C= ref $_[0] eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | # Set type | ||||||||||||||||||||||||||||||||||||||||||
| 117 | 11 | $hash{type} = $type; | |||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | # Set xsi:nil unless there is content | ||||||||||||||||||||||||||||||||||||||||||
| 120 | 11 | ▶ | $hash{'xsi:nil'} = 'true' unless $_[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | # Return element | ||||||||||||||||||||||||||||||||||||||||||
| 123 | 11 | return $self->add(Property => \%hash => @_ ); | |||||||||||||||||||||||||||||||||||||||||
| 124 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 125 | |||||||||||||||||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||||||||||||||||
| 127 | # Add Link | ||||||||||||||||||||||||||||||||||||||||||
| 128 | 36 | ▶ | sub link { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
link: called CC=5 SCAR=16.1
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 129 | 36 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 130 | |||||||||||||||||||||||||||||||||||||||||||
| 131 | # No rel given | ||||||||||||||||||||||||||||||||||||||||||
| 132 | 36 | ▶ | return unless $_[0]; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 133 | |||||||||||||||||||||||||||||||||||||||||||
| 134 | 36 | my $rel = shift; | |||||||||||||||||||||||||||||||||||||||||
| 135 | |||||||||||||||||||||||||||||||||||||||||||
| 136 | # Get link | ||||||||||||||||||||||||||||||||||||||||||
| 137 | 36 | ▶ | unless ($_[0]) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 138 | 24 | return $self->at( qq{Link[rel="$rel"]} ); | |||||||||||||||||||||||||||||||||||||||||
| 139 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | 12 | my %hash; | |||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | # Accept hash reference | ||||||||||||||||||||||||||||||||||||||||||
| 144 | 12 | ▶ | if (ref $_[0] && ref $_[0] eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $_[0] and ref $_[0] eq "HASH"
MC/DC50%1/2
ref $_[0] and ref $_[0] eq "HASH"
ref $_[0]
ref $_[0] eq "HASH"
Truth table66%2/3
A and B
A= ref $_[0]B= ref $_[0] eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | 8 | %hash = %{ $_[0] }; | |||||||||||||||||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||||||||||||||||
| 147 | |||||||||||||||||||||||||||||||||||||||||||
| 148 | # Accept string | ||||||||||||||||||||||||||||||||||||||||||
| 149 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 150 | 4 | $hash{href} = shift; | |||||||||||||||||||||||||||||||||||||||||
| 151 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | # Set relation | ||||||||||||||||||||||||||||||||||||||||||
| 154 | 12 | $hash{rel} = $rel; | |||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | # Return link object | ||||||||||||||||||||||||||||||||||||||||||
| 157 | 12 | return $self->add(Link => \%hash); | |||||||||||||||||||||||||||||||||||||||||
| 158 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||||||||||||||||
| 161 | # Set or get expiration date | ||||||||||||||||||||||||||||||||||||||||||
| 162 | 10 | ▶ | sub expires { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
expires: called CC=5 SCAR=16.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 163 | 10 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 164 | |||||||||||||||||||||||||||||||||||||||||||
| 165 | # Return subject | ||||||||||||||||||||||||||||||||||||||||||
| 166 | 10 | ▶ | unless ($_[0]) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||||||||||||||||
| 168 | # Subject found | ||||||||||||||||||||||||||||||||||||||||||
| 169 | 6 | my $exp = $self->at('Expires'); | |||||||||||||||||||||||||||||||||||||||||
| 170 | |||||||||||||||||||||||||||||||||||||||||||
| 171 | # Return | ||||||||||||||||||||||||||||||||||||||||||
| 172 | 6 | ▶ | return unless $exp; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||||||||||||||||
| 174 | # Return RFC3339 object | ||||||||||||||||||||||||||||||||||||||||||
| 175 | 6 | return XML::Loy::Date::RFC3339->new($exp->text); | |||||||||||||||||||||||||||||||||||||||||
| 176 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||||||||||||||||
| 178 | # New RFC3339 object | ||||||||||||||||||||||||||||||||||||||||||
| 179 | 4 | my $new_time = XML::Loy::Date::RFC3339->new($_[0])->to_string(0); | |||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | # RFC3339 obect undefined | ||||||||||||||||||||||||||||||||||||||||||
| 182 | 4 | ▶ | return unless $new_time; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | 4 | my $new_node = $self->set(Expires => $new_time); | |||||||||||||||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||||||||||||||||
| 186 | # Set subject (only once) | ||||||||||||||||||||||||||||||||||||||||||
| 187 | 4 | ▶ | if (my $np = $self->at('Link, Alias, Property')) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | # Put in correct order - maybe not effective | ||||||||||||||||||||||||||||||||||||||||||
| 190 | 4 | my $clone = $self->at('Expires'); | |||||||||||||||||||||||||||||||||||||||||
| 191 | 4 | $self->at('Expires')->remove; | |||||||||||||||||||||||||||||||||||||||||
| 192 | 4 | return $np->prepend($clone->to_string); | |||||||||||||||||||||||||||||||||||||||||
| 193 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | # Return new node | ||||||||||||||||||||||||||||||||||||||||||
| 196 | 0 | return $new_node; | |||||||||||||||||||||||||||||||||||||||||
| 197 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||||||||||||||||
| 200 | # Check for expiration | ||||||||||||||||||||||||||||||||||||||||||
| 201 | 2 | ▶ | sub expired { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
expired: called CC=4 SCAR=14.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 202 | 2 | ▶ | my $self = $_[0]->type eq 'root' ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 203 | shift : shift->root; | ||||||||||||||||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||||||||||||||||
| 205 | # No expiration date given | ||||||||||||||||||||||||||||||||||||||||||
| 206 | 2 | ▶ | my $exp = $self->expires or return; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||||||||||||||||
| 208 | # Document is expired | ||||||||||||||||||||||||||||||||||||||||||
| 209 | 2 | ▶ | return 1 if $exp->epoch < time; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||
| 211 | # Document is still current | ||||||||||||||||||||||||||||||||||||||||||
| 212 | 1 | return; | |||||||||||||||||||||||||||||||||||||||||
| 213 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | # Filter link relations | ||||||||||||||||||||||||||||||||||||||||||
| 217 | 4 | ▶ | sub filter_rel { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
filter_rel: called CC=6 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 219 | 4 | my $xrd = $self->new( $self->to_string ); | |||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | # No xrd | ||||||||||||||||||||||||||||||||||||||||||
| 222 | 4 | ▶ | return unless $xrd; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | 4 | my @rel; | |||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | # Push valid relations | ||||||||||||||||||||||||||||||||||||||||||
| 227 | 4 | ▶ | if (@_ == 1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||||||||||||||||
| 229 | # Based on array reference | ||||||||||||||||||||||||||||||||||||||||||
| 230 | 2 | ▶ | if (ref $_[0] && ref $_[0] eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $_[0] and ref $_[0] eq "ARRAY"
MC/DC50%1/2
ref $_[0] and ref $_[0] eq "ARRAY"
ref $_[0]
ref $_[0] eq "ARRAY"
Truth table66%2/3
A and B
A= ref $_[0]B= ref $_[0] eq "ARRAY"
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | 1 | @rel = @{ shift() }; | |||||||||||||||||||||||||||||||||||||||||
| 232 | } | ||||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | # Based on string | ||||||||||||||||||||||||||||||||||||||||||
| 235 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 236 | 1 | @rel = split /\s+/, shift; | |||||||||||||||||||||||||||||||||||||||||
| 237 | } | ||||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | # As array | ||||||||||||||||||||||||||||||||||||||||||
| 241 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 242 | 2 | @rel = @_; | |||||||||||||||||||||||||||||||||||||||||
| 243 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||||||||||||||||
| 245 | # Create unwanted link relation query | ||||||||||||||||||||||||||||||||||||||||||
| 246 | my $rel = scalar @rel ? 'Link:' . join(':', map { | ||||||||||||||||||||||||||||||||||||||||||
| 247 | 4 | ▶ | 'not([rel=' . quote($_) . '])' | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 248 | } @rel) : 'Link'; | ||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | # Remove unwanted link relations | ||||||||||||||||||||||||||||||||||||||||||
| 251 | 4 | $xrd->find($rel)->map('remove'); | |||||||||||||||||||||||||||||||||||||||||
| 252 | 4 | return $xrd; | |||||||||||||||||||||||||||||||||||||||||
| 253 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||||||||||||||||
| 255 | |||||||||||||||||||||||||||||||||||||||||||
| 256 | # Convert to xml | ||||||||||||||||||||||||||||||||||||||||||
| 257 | 2 | ▶ | sub _to_xml { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_to_xml: called CC=10 SCAR=23.6
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | 2 | my $xrd = shift; | |||||||||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||||||||||
| 260 | # Parse json document | ||||||||||||||||||||||||||||||||||||||||||
| 261 | 2 | my $jrd; | |||||||||||||||||||||||||||||||||||||||||
| 262 | |||||||||||||||||||||||||||||||||||||||||||
| 263 | # There may be a parsing error | ||||||||||||||||||||||||||||||||||||||||||
| 264 | 2 | ▶ | eval { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 265 | 2 | $jrd = decode_json $_[0]; | |||||||||||||||||||||||||||||||||||||||||
| 266 | } or carp $@; | ||||||||||||||||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||||||||||||||||
| 268 | # Itterate over all XRD elements | ||||||||||||||||||||||||||||||||||||||||||
| 269 | 2 | foreach my $key (keys %$jrd) { | |||||||||||||||||||||||||||||||||||||||||
| 270 | 9 | $key = lc $key; | |||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||
| 272 | # Properties | ||||||||||||||||||||||||||||||||||||||||||
| 273 | 9 | ▶ | if ($key eq 'properties') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 274 | 2 | _to_xml_properties($xrd, $jrd->{$key}); | |||||||||||||||||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||
| 277 | # Links | ||||||||||||||||||||||||||||||||||||||||||
| 278 | elsif ($key eq 'links') { | ||||||||||||||||||||||||||||||||||||||||||
| 279 | 2 | _to_xml_links($xrd, $jrd->{$key}); | |||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||||||||||||||||
| 282 | # Subject or Expires | ||||||||||||||||||||||||||||||||||||||||||
| 283 | ▶ | elsif ($key eq 'subject' || $key eq 'expires') { | |||||||||||||||||||||||||||||||||||||||||
|
Condition100%3/3
$key eq "subject" or $key eq "expires"
MC/DC100%2/2
$key eq "subject" or $key eq "expires"
$key eq "subject"
$key eq "expires"
Truth table100%3/3
A or B
A= $key eq "subject"B= $key eq "expires"
| |||||||||||||||||||||||||||||||||||||||||||
| 284 | 3 | $xrd->set(ucfirst($key), $jrd->{$key}); | |||||||||||||||||||||||||||||||||||||||||
| 285 | } | ||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||
| 287 | # Aliases | ||||||||||||||||||||||||||||||||||||||||||
| 288 | elsif ($key eq 'aliases') { | ||||||||||||||||||||||||||||||||||||||||||
| 289 | 2 | $xrd->alias($_) foreach (@{$jrd->{$key}}); | |||||||||||||||||||||||||||||||||||||||||
| 290 | } | ||||||||||||||||||||||||||||||||||||||||||
| 291 | |||||||||||||||||||||||||||||||||||||||||||
| 292 | # Titles | ||||||||||||||||||||||||||||||||||||||||||
| 293 | elsif ($key eq 'titles') { | ||||||||||||||||||||||||||||||||||||||||||
| 294 | 0 | _to_xml_titles($xrd, $jrd->{$key}); | |||||||||||||||||||||||||||||||||||||||||
| 295 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 296 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 297 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 298 | |||||||||||||||||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||||||||||||||||
| 300 | # Convert From JSON to XML | ||||||||||||||||||||||||||||||||||||||||||
| 301 | 2 | ▶ | sub _to_xml_titles { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_to_xml_titles: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 302 | 2 | my ($node, $hash) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 303 | 2 | foreach (keys %$hash) { | |||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||
| 305 | # Default | ||||||||||||||||||||||||||||||||||||||||||
| 306 | 3 | ▶ | if ($_ eq 'default') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 307 | 2 | $node->add(Title => $hash->{$_}); | |||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||
| 310 | # Language | ||||||||||||||||||||||||||||||||||||||||||
| 311 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 312 | 1 | $node->add(Title => { 'xml:lang' => $_ } => $hash->{$_}); | |||||||||||||||||||||||||||||||||||||||||
| 313 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 314 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 315 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||
| 318 | # Convert from JSON to XML | ||||||||||||||||||||||||||||||||||||||||||
| 319 | 2 | ▶ | sub _to_xml_links { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_to_xml_links: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 320 | 2 | my ($node, $array) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 321 | |||||||||||||||||||||||||||||||||||||||||||
| 322 | # All link objects | ||||||||||||||||||||||||||||||||||||||||||
| 323 | 2 | foreach (@$array) { | |||||||||||||||||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||||||||||||||||
| 325 | # titles and properties | ||||||||||||||||||||||||||||||||||||||||||
| 326 | 4 | my $titles = delete $_->{titles}; | |||||||||||||||||||||||||||||||||||||||||
| 327 | 4 | my $properties = delete $_->{properties}; | |||||||||||||||||||||||||||||||||||||||||
| 328 | |||||||||||||||||||||||||||||||||||||||||||
| 329 | # Add new link object | ||||||||||||||||||||||||||||||||||||||||||
| 330 | 4 | my $link = $node->link(delete $_->{rel}, $_); | |||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||
| 332 | # Add titles and properties | ||||||||||||||||||||||||||||||||||||||||||
| 333 | 4 | ▶ | _to_xml_titles($link, $titles) if $titles; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 334 | 4 | ▶ | _to_xml_properties($link, $properties) if $properties; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 335 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 336 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 337 | |||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||
| 339 | # Convert from JSON to XML | ||||||||||||||||||||||||||||||||||||||||||
| 340 | 3 | ▶ | sub _to_xml_properties { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_to_xml_properties: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 341 | 3 | my ($node, $hash) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||
| 343 | 3 | $node->property($_ => $hash->{$_}) foreach keys %$hash; | |||||||||||||||||||||||||||||||||||||||||
| 344 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||
| 346 | |||||||||||||||||||||||||||||||||||||||||||
| 347 | # Render JRD | ||||||||||||||||||||||||||||||||||||||||||
| 348 | 4 | ▶ | sub to_json { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_json: called CC=8 SCAR=20.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 349 | 4 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||
| 351 | 4 | ▶ | my $root = $self->type eq 'root' ? | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 352 | $self : $self->root; | ||||||||||||||||||||||||||||||||||||||||||
| 353 | |||||||||||||||||||||||||||||||||||||||||||
| 354 | 4 | my %object; | |||||||||||||||||||||||||||||||||||||||||
| 355 | |||||||||||||||||||||||||||||||||||||||||||
| 356 | # Serialize Subject and Expires | ||||||||||||||||||||||||||||||||||||||||||
| 357 | 4 | foreach (qw/Subject Expires/) { | |||||||||||||||||||||||||||||||||||||||||
| 358 | 8 | my $obj = $root->at($_); | |||||||||||||||||||||||||||||||||||||||||
| 359 | 8 | ▶ | $object{lc($_)} = $obj->text if $obj; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 360 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 361 | |||||||||||||||||||||||||||||||||||||||||||
| 362 | # Serialize aliases | ||||||||||||||||||||||||||||||||||||||||||
| 363 | 4 | my @aliases; | |||||||||||||||||||||||||||||||||||||||||
| 364 | $root->children('Alias')->each( | ||||||||||||||||||||||||||||||||||||||||||
| 365 | 6 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 366 | 6 | push(@aliases, shift->text ); | |||||||||||||||||||||||||||||||||||||||||
| 367 | 4 | }); | |||||||||||||||||||||||||||||||||||||||||
| 368 | 4 | ▶ | $object{'aliases'} = \@aliases if @aliases; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 369 | |||||||||||||||||||||||||||||||||||||||||||
| 370 | # Serialize titles | ||||||||||||||||||||||||||||||||||||||||||
| 371 | 4 | my $titles = _to_json_titles($root); | |||||||||||||||||||||||||||||||||||||||||
| 372 | 4 | ▶ | $object{'titles'} = $titles if keys %$titles; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||
| 374 | # Serialize properties | ||||||||||||||||||||||||||||||||||||||||||
| 375 | 4 | my $properties = _to_json_properties($root); | |||||||||||||||||||||||||||||||||||||||||
| 376 | 4 | ▶ | $object{'properties'} = $properties if keys %$properties; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||
| 378 | # Serialize links | ||||||||||||||||||||||||||||||||||||||||||
| 379 | 4 | my @links; | |||||||||||||||||||||||||||||||||||||||||
| 380 | $root->children('Link')->each( | ||||||||||||||||||||||||||||||||||||||||||
| 381 | 8 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||||||||||||||||
| 382 | 8 | my $link = shift; | |||||||||||||||||||||||||||||||||||||||||
| 383 | 8 | my $link_att = $link->attr; | |||||||||||||||||||||||||||||||||||||||||
| 384 | |||||||||||||||||||||||||||||||||||||||||||
| 385 | 8 | my %link_prop; | |||||||||||||||||||||||||||||||||||||||||
| 386 | 8 | foreach (qw/rel template href type/) { | |||||||||||||||||||||||||||||||||||||||||
| 387 | 32 | ▶ | if (exists $link_att->{$_}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 388 | 17 | $link_prop{$_} = $link_att->{$_}; | |||||||||||||||||||||||||||||||||||||||||
| 389 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 390 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 391 | |||||||||||||||||||||||||||||||||||||||||||
| 392 | # Serialize link titles | ||||||||||||||||||||||||||||||||||||||||||
| 393 | 8 | my $link_titles = _to_json_titles($link); | |||||||||||||||||||||||||||||||||||||||||
| 394 | 8 | ▶ | $link_prop{'titles'} = $link_titles if keys %$link_titles; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 395 | |||||||||||||||||||||||||||||||||||||||||||
| 396 | # Serialize link properties | ||||||||||||||||||||||||||||||||||||||||||
| 397 | 8 | my $link_properties = _to_json_properties($link); | |||||||||||||||||||||||||||||||||||||||||
| 398 | 8 | ▶ | $link_prop{'properties'} = $link_properties | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 399 | if keys %$link_properties; | ||||||||||||||||||||||||||||||||||||||||||
| 400 | |||||||||||||||||||||||||||||||||||||||||||
| 401 | 8 | push(@links, \%link_prop); | |||||||||||||||||||||||||||||||||||||||||
| 402 | 4 | }); | |||||||||||||||||||||||||||||||||||||||||
| 403 | 4 | ▶ | $object{'links'} = \@links if @links; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 404 | 4 | return encode_json(\%object); | |||||||||||||||||||||||||||||||||||||||||
| 405 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||
| 407 | |||||||||||||||||||||||||||||||||||||||||||
| 408 | # Serialize node titles | ||||||||||||||||||||||||||||||||||||||||||
| 409 | 12 | ▶ | sub _to_json_titles { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_to_json_titles: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 410 | 12 | my $node = shift; | |||||||||||||||||||||||||||||||||||||||||
| 411 | 12 | my %titles; | |||||||||||||||||||||||||||||||||||||||||
| 412 | $node->children('Title')->each( | ||||||||||||||||||||||||||||||||||||||||||
| 413 | 7 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 414 | 7 | my $val = $_->text; | |||||||||||||||||||||||||||||||||||||||||
| 415 | 7 | ▶ | my $lang = $_->attr->{'xml:lang'} || 'default'; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$_->attr->{'xml:lang'} || 'default'
MC/DC100%1/1
$_->attr->{'xml:lang'} || 'default'
$_->attr->{'xml:lang'}
Truth table100%2/2
A
A= $_->attr->{'xml:lang'}
| |||||||||||||||||||||||||||||||||||||||||||
| 416 | 7 | $titles{$lang} = $val; | |||||||||||||||||||||||||||||||||||||||||
| 417 | 12 | }); | |||||||||||||||||||||||||||||||||||||||||
| 418 | 12 | return \%titles; | |||||||||||||||||||||||||||||||||||||||||
| 419 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 420 | |||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||
| 422 | # Serialize node properties | ||||||||||||||||||||||||||||||||||||||||||
| 423 | 12 | ▶ | sub _to_json_properties { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_to_json_properties: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 424 | 12 | my $node = shift; | |||||||||||||||||||||||||||||||||||||||||
| 425 | 12 | my %property = (); | |||||||||||||||||||||||||||||||||||||||||
| 426 | $node->children('Property')->each( | ||||||||||||||||||||||||||||||||||||||||||
| 427 | 10 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 428 | 10 | my $p = shift; | |||||||||||||||||||||||||||||||||||||||||
| 429 | 10 | ▶ | my $val = $p->text || undef; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$p->text || undef
MC/DC100%1/1
$p->text || undef
$p->text
Truth table100%2/2
A
A= $p->text
| |||||||||||||||||||||||||||||||||||||||||||
| 430 | 10 | my $type = $p->attr->{'type'}; | |||||||||||||||||||||||||||||||||||||||||
| 431 | |||||||||||||||||||||||||||||||||||||||||||
| 432 | 10 | $property{$type} = $val; | |||||||||||||||||||||||||||||||||||||||||
| 433 | 12 | }); | |||||||||||||||||||||||||||||||||||||||||
| 434 | 12 | return \%property; | |||||||||||||||||||||||||||||||||||||||||
| 435 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||
| 437 | |||||||||||||||||||||||||||||||||||||||||||
| 438 | 3 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||
| 440 | |||||||||||||||||||||||||||||||||||||||||||
| 441 | __END__ | ||||||||||||||||||||||||||||||||||||||||||