lib/XML/Compile/Tester.pm

filter: Statementstmt 29.0% 27 / 93 Branchbran 0.0% 0 / 22 Conditioncond 0.0% 0 / 12 MC/DCmcdc 0.0% 0 / 8 Subroutinesub 33.3% 7 / 21 Podpod 90.9% 10 / 11 totaltotal 26.3% 44 / 167 CC 17 SCAR 27.5
CC
17
Cov
21%
reader_error
42.0
writer_error
30.0
compare_xml
20.0
CRAP 15.6
↑ Summary
1 # Copyrights 2008-2018 by [Mark Overmeer <markov@cpan.org>].
2 # For other contributors see ChangeLog.
3 # See the manual pages for details on the licensing terms.
4 # Pod stripped from pm file by OODoc 2.02.
5 # This code is part of distribution XML-Compile-Tester. Meta-POD processed
6 # with OODoc into POD and HTML manual-pages. See README.md
7 # Copyright Mark Overmeer. Licensed under the same terms as Perl itself.
8  
9 package XML::Compile::Tester;
10 1 ▶use vars '$VERSION';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 1 $VERSION = '0.91';
12  
13 1 ▶use base 'Exporter';
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 1 our @EXPORT = qw/
19 set_compile_defaults
20 set_default_namespace
21 reader_create create_reader
22 writer_create create_writer
23 writer_test
24 reader_error
25 writer_error
26 templ_xml
27 templ_perl
28 templ_tree
29 compare_xml
30 /;
31  
32 1 ▶use Test::More;
Subroutine BEGIN: called CC=1 SCAR=0.0
33 1 ▶use Data::Dumper;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 1 ▶use Log::Report qw/try/;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 1 my $default_namespace;
37 my @compile_defaults;
38  
39  
40 # not using pack_type, which avoids a recursive dependency to XML::Compile
41 sub _reltype_to_abs($)
42 0 ▶{ defined $default_namespace && substr($_[0], 0,1) eq '{'
Subroutine _reltype_to_abs: not called CC=3 SCAR=24.8
Branch: 1 branch
BranchTrueFalseTotal
defined $default_namespace && substr($_[0], 0, 1) eq '{' ? : 0 0 0
Condition0%0/3
defined $default_namespace and substr($_[0], 0, 1) eq "{"
!ll&&!rl&&r
000
MC/DC0%0/2
defined $default_namespace and substr($_[0], 0, 1) eq "{"
defined $default_namespace substr($_[0], 0, 1) eq "{"
Truth table0%0/3
A and B
A= defined $default_namespaceB= substr($_[0], 0, 1) eq "{"
ABresult
0X0
100
111
43 ? "{$default_namespace}$_[0]" : $_[0] }
44  
45 sub reader_create($$$@)
46 0 ▶{ my ($schema, $test, $reltype) = splice @_, 0, 3;
Subroutine reader_create: not called CC=1 SCAR=6.9
Pod documented
47  
48 0 my $type = _reltype_to_abs $reltype;
49 0 my $read_t = $schema->compile
50 ( READER => $type
51 , check_values => 1
52 , include_namespaces => 0
53 , @compile_defaults
54 , @_
55 );
56  
57 0 isa_ok($read_t, 'CODE', "reader element $test");
58 0 $read_t;
59 }
60 1 *create_reader = \&reader_create; # name change in 0.03
61  
62  
63 sub reader_error($$$)
64 0 ▶{ my ($schema, $reltype, $xml) = @_;
Subroutine reader_error: not called CC=6 SCAR=37.4
Pod documented
65 0 my $r = reader_create $schema, "check read error $reltype", $reltype;
66 0 ▶ defined $r or return;
Branch: 1 branch
BranchTrueFalseTotal
defined $r or return 0 0 0
67  
68 0 ▶ my $tree = try { $r->($xml) };
Subroutine __ANON__: not called CC=1 SCAR=6.9
69 my $error = ref $@ && $@->exceptions
70 0 ▶ ? join("\n", map {$_->message} $@->exceptions)
Branch: 1 branch
BranchTrueFalseTotal
ref $@ && $@->exceptions ? : 0 0 0
Condition0%0/3
ref $@ and $@->exceptions
!ll&&!rl&&r
000
MC/DC0%0/2
ref $@ and $@->exceptions
ref $@ $@->exceptions
Truth table0%0/3
A and B
A= ref $@B= $@->exceptions
ABresult
0X0
100
111
71 : '';
72 0 ▶ undef $tree
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 0 0
73 if $error; # there is output if only warnings are produced
74  
75 0 ok(!defined $tree, "no return for $reltype");
76 0 ▶ warn "RETURNED TREE=",Dumper $tree if defined $tree;
Branch: 1 branch
BranchTrueFalseTotal
if defined $tree 0 0 0
77  
78 0 ok(length $error, "ER=$error");
79 0 $error;
80 }
81  
82  
83 sub writer_create($$$@)
84 0 ▶{ my ($schema, $test, $reltype) = splice @_, 0, 3;
Subroutine writer_create: not called CC=1 SCAR=6.9
Pod documented
85 0 my $type = _reltype_to_abs $reltype;
86  
87 0 my $write_t = $schema->compile
88 ( WRITER => $type
89 , check_values => 1
90 , include_namespaces => 0
91 , use_default_namespace => 1
92 , @compile_defaults
93 , @_
94 );
95  
96 0 isa_ok($write_t, 'CODE', "writer element $test");
97 0 $write_t;
98 }
99 1 *create_writer = \&writer_create; # name change in 0.03
100  
101  
102 sub writer_test($$;$)
103 0 ▶{ my ($writer, $data, $doc) = @_;
Subroutine writer_test: not called CC=3 SCAR=24.8
Pod documented
104  
105 0 ▶ $doc ||= XML::LibXML->createDocument('1.0', 'UTF-8');
Condition0%0/3
$doc ||= "XML::LibXML"->createDocument("1.0", "UTF-8")
l!l&&r!l&&!r
000
MC/DC0%0/2
$doc ||= "XML::LibXML"->createDocument("1.0", "UTF-8")
$doc "XML::LibXML"->createDocument("1.0", "UTF-8")
Truth table0%0/3
A ||= B
A= $docB= "XML::LibXML"->createDocument("1.0", "UTF-8")
ABresult
1X1
011
000
106 0 isa_ok($doc, 'XML::LibXML::Document');
107  
108 0 my $tree = $writer->($doc, $data);
109 0 ok(defined $tree);
110 0 ▶ defined $tree or return;
Branch: 1 branch
BranchTrueFalseTotal
defined $tree or return 0 0 0
111  
112 0 isa_ok($tree, 'XML::LibXML::Node');
113 0 $tree;
114 }
115  
116  
117 sub writer_error($$$)
118 0 ▶{ my ($schema, $reltype, $data) = @_;
Subroutine writer_error: not called CC=5 SCAR=34.0
Pod documented
119  
120 0 my $write = writer_create $schema, "writer for $reltype", $reltype;
121  
122 0 my $node;
123 0 ▶ try { my $doc = XML::LibXML->createDocument('1.0', 'UTF-8');
Subroutine __ANON__: not called CC=1 SCAR=6.9
124 0 isa_ok($doc, 'XML::LibXML::Document');
125 0 $node = $write->($doc, $data);
126 0 };
127  
128 0 ▶ my $error
Branch: 1 branch
BranchTrueFalseTotal
ref $@ && $@->exceptions ? : 0 0 0
Condition0%0/3
ref $@ and $@->exceptions
!ll&&!rl&&r
000
MC/DC0%0/2
ref $@ and $@->exceptions
ref $@ $@->exceptions
Truth table0%0/3
A and B
A= ref $@B= $@->exceptions
ABresult
0X0
100
111
129 = ref $@ && $@->exceptions
130 ? join("\n", map $_->message, $@->exceptions)
131 : '';
132 0 ▶ undef $node if $error; # there is output if only warnings are produced
Branch: 1 branch
BranchTrueFalseTotal
if $error 0 0 0
133  
134 # my $error = $@ ? $@->wasFatal->message : '';
135 0 ok(!defined $node, "no return for $reltype expected");
136 0 ▶ warn "RETURNED =", $node->toString if ref $node;
Branch: 1 branch
BranchTrueFalseTotal
if ref $node 0 0 0
137 0 ok(length $error, "EW=$error");
138  
139 0 $error;
140 }
141  
142 #--------------
143  
144 sub templ_xml($$@)
145 0 ▶{ my ($schema, $test, @opts) = @_;
Subroutine templ_xml: not called CC=1 SCAR=6.9
Pod documented
146  
147 0 my $abs = _reltype_to_abs $test;
148  
149 0 $schema->template
150 ( XML => $abs
151 , include_namespaces => 1
152 , @opts
153 ) . "\n";
154 }
155  
156  
157 sub templ_perl($$@)
158 0 ▶{ my ($schema, $test, @opts) = @_;
Subroutine templ_perl: not called CC=1 SCAR=6.9
Pod documented
159  
160 0 my $abs = _reltype_to_abs $test;
161  
162 0 $schema->template
163 ( PERL => $abs
164 , include_namespaces => 0
165 , @opts
166 );
167 }
168  
169  
170 sub templ_tree($$@)
171 0 ▶{ my ($schema, $test, @opts) = @_;
Subroutine templ_tree: not called CC=1 SCAR=6.9
Pod undocumented
172 0 my $abs = _reltype_to_abs($test);
173  
174 0 $schema->template
175 ( TREE => $abs
176 , @opts
177 );
178 }
179  
180  
181  
182 0 ▶sub set_compile_defaults(@) { @compile_defaults = @_ }
Subroutine set_compile_defaults: not called CC=1 SCAR=6.9
Pod documented
183  
184  
185 0 ▶sub set_default_namespace($) { $default_namespace = shift }
Subroutine set_default_namespace: not called CC=1 SCAR=6.9
Pod documented
186  
187  
188 sub compare_xml($$;$)
189 0 ▶{ my ($tree, $expect, $comment) = @_;
Subroutine compare_xml: not called CC=4 SCAR=30.0
Pod documented
190 0 ▶ my $dump = ref $tree ? $tree->toString : $tree;
Branch: 1 branch
BranchTrueFalseTotal
ref $tree ? : 0 0 0
191  
192 0 for($dump, $expect)
193 0 ▶ { defined $_ or next;
Branch: 1 branch
BranchTrueFalseTotal
defined $_ or next 0 0 0
194 0 s/\>\s+/>/gs;
195 0 s/\s+\</</gs;
196 0 s/\>\s+\</></gs;
197 0 s/\s*\n\s*/ /gs;
198 0 s/\s{2,}/ /gs;
199 0 s/\s+\z//gs;
200 }
201 0 is($dump, $expect, $comment);
202 }
203  
204 1 1;
↑ Summary