XSD.pm

filter: Statementstmt 75.0% 54 / 72 Branchbran 64.2% 9 / 14 Conditioncond 16.6% 1 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 87.5% 14 / 16 Podpod 0.0% 0 / 4 totaltotal 67.2% 78 / 116 CC 12 SCAR 17.0
CC
12
Cov
70%
__ANON__
20.0
__ANON__
6.5
__ANON__
5.6
CRAP 5.5
↑ Summary Importer/XSD.pm »
1 package Catmandu::XSD;
2  
3 3 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use Catmandu::Util;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use XML::Compile;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use XML::Compile::Cache;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use XML::Compile::Util 'pack_type';
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 our $VERSION = '0.05';
10  
11 3 has 'root' => (is => 'ro' , required => 1);
12 11 ▶has 'schemas' => (is => 'ro' , required => 1 , coerce => sub {
Subroutine __ANON__: called CC=3 SCAR=11.6
13 11 my ($value) = @_;
14 11 ▶ if (Catmandu::Util::is_array_ref($value)) {
Branch: 2 branches
BranchTrueFalseTotal
if (Catmandu::Util::is_array_ref($value)) { } 3 8 11
elsif ($value =~ /\*/) { } 8 0 8
15 3 return $value;
16 }
17 elsif ($value =~ /\*/) {
18 8 my @files = glob($value);
19 8 \@files;
20 }
21 else {
22 0 my @files = split(/,/,$value);
23 0 \@files;
24 }
25 3 });
26  
27 5 ▶has 'mixed' => (is => 'ro' , default => sub { 'ATTRIBUTES' });
Subroutine __ANON__: called CC=1 SCAR=0.0
28 9 ▶has 'any_element' => (is => 'ro' , default => sub { 'TAKE_ALL' } , coerce => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine __ANON__: called CC=3 SCAR=18.7
29 11 my $val = $_[0];
30 11 ▶ if (defined $val && $val eq 'XML_STRING') {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $val and $val eq 'XML_STRING') { } 0 11 11
Condition33%1/3
defined $val and $val eq "XML_STRING"
!ll&&!rl&&r
0110
MC/DC0%0/2
defined $val and $val eq "XML_STRING"
defined $val $val eq "XML_STRING"
Truth table33%1/3
A and B
A= defined $valB= $val eq "XML_STRING"
ABresult
0X0
100
111
31 0 ▶ return sub {
Subroutine __ANON__: not called CC=4 SCAR=30.0
32 0 my ($path, $node , $handler) = @_;
33 0 ▶ if ($node && ref($node)) {
Branch: 1 branch
BranchTrueFalseTotal
if ($node and ref $node) { } 0 0 0
Condition0%0/3
$node and ref $node
!ll&&!rl&&r
000
MC/DC0%0/2
$node and ref $node
$node ref $node
Truth table0%0/3
A and B
A= $nodeB= ref $node
ABresult
0X0
100
111
34 0 my $str = '';
35 0 for (@$node) {
36 0 $str .= $_->toString;
37 }
38 0 ('_',$str);
39 }
40 else {
41 0 $node;
42 }
43 0 };
44 }
45 else {
46 11 $val;
47 }
48 3 });
49 6 ▶has 'prefixes' => (is => 'ro' , coerce => sub {
Subroutine __ANON__: called CC=4 SCAR=17.2
50 6 my ($value) = @_;
51 6 ▶ if (Catmandu::Util::is_array_ref($value)) {
Branch: 2 branches
BranchTrueFalseTotal
if (Catmandu::Util::is_array_ref($value)) { } 3 3 6
elsif (defined $value) { } 0 3 3
52 3 return $value;
53 }
54 elsif (defined($value)) {
55 0 my $ret = [];
56 0 for (split(/,/,$value)) {
57 0 my ($ns,$url) = split(/:/,$_,2);
58 0 push @$ret , { $ns => $url };
59 }
60 0 return $ret;
61 }
62 else {
63 3 undef;
64 }
65 3 });
66  
67 3 has '_reader' => (is => 'ro');
68 3 has '_writer' => (is => 'ro');
69  
70 11 ▶sub BUILD {
Subroutine BUILD: called CC=1 SCAR=0.0
Pod undocumented
71 11 my ($self) = @_;
72  
73 11 my $schema = XML::Compile::Cache->new($self->schemas);
74  
75 $schema->addHook(
76 action => 'READER' ,
77 2327 ▶ after => sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
78 2327 my ($xml, $data, $path) = @_;
79 2327 ▶ delete $data->{_MIXED_ELEMENT_MODE} if Catmandu::Util::is_hash_ref($data);
Branch: 1 branch
BranchTrueFalseTotal
if Catmandu::Util::is_hash_ref($data) 2258 69 2327
80 2327 $data;
81 }
82 11 );
83  
84 11 $self->{_reader} = $schema->compile(
85 READER => $self->root,
86 mixed_elements => $self->mixed ,
87 any_element => $self->any_element ,
88 sloppy_floats => 'true',
89 sloppy_integers => 'true' ,
90 );
91  
92 11 $self->{_writer} = $schema->compile(
93 WRITER => $self->root,
94 prefixes => $self->prefixes,
95 sloppy_floats => 'true',
96 sloppy_integers => 'true' ,
97 );
98  
99 11 $schema = undef;
100 }
101  
102 0 ▶sub template {
Subroutine template: not called CC=1 SCAR=6.9
Pod undocumented
103 0 my ($self) = @_;
104 0 my $schema = XML::Compile::Cache->new($self->schemas);
105 0 $schema->template('PERL', $self->root , show => 'ALL');
106 }
107  
108 10 ▶sub parse {
Subroutine parse: called CC=1 SCAR=0.0
Pod undocumented
109 10 my ($self,$input) = @_;
110 10 $self->_reader->($input);
111 }
112  
113 5 ▶sub to_xml {
Subroutine to_xml: called CC=1 SCAR=0.0
Pod undocumented
114 5 my ($self,$data) = @_;
115 5 my $doc = XML::LibXML::Document->new('1.0', 'UTF-8');
116 5 my $xml = $self->_writer->($doc, $data);
117 5 $doc->setDocumentElement($xml);
118 5 $doc->toString(1);
119 }
120  
121 3 1;
122  
123 __END__
↑ Summary Importer/XSD.pm »