blib/lib/Dancer/Serializer/XML.pm

filter: Statementstmt 45.9% 28 / 61 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 10 MC/DCmcdc 0.0% 0 / 6 Subroutinesub 44.4% 8 / 18 Podpod 50.0% 4 / 8 totaltotal 35.4% 40 / 113 SCAR 36.4
CC
10
Cov
35%
serialize
20.0
deserialize
14.3
init
12.0
CRAP 38.0
« blib/lib/Dancer/App.pm ↑ Summary blib/lib/Dancer/Error.pm »
1 package Dancer::Serializer::XML;
2 170 our $AUTHORITY = 'cpan:SUKRIA';
3 #ABSTRACT: serializer for handling XML data
4 170 $Dancer::Serializer::XML::VERSION = '1.3520';
5 170 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 170 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 170 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 170 ▶use Dancer::ModuleLoader;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 170 ▶use Dancer::Config 'setting';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 170 ▶use base 'Dancer::Serializer::Abstract';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # singleton for the XML::Simple object
13 170 my $_xs;
14  
15 # helpers
16  
17 sub from_xml {
18 0 ▶ my $s = Dancer::Serializer::XML->new;
Subroutine from_xml: not called CC=1 SCAR=6.9
Pod undocumented
19 0 $s->deserialize(@_);
20 }
21  
22 sub to_xml {
23 0 ▶ my $s = Dancer::Serializer::XML->new;
Subroutine to_xml: not called CC=1 SCAR=6.9
Pod undocumented
24 0 $s->serialize(@_);
25 }
26  
27 # class definition
28  
29 sub loaded_xmlsimple {
30 0 ▶ Dancer::ModuleLoader->load('XML::Simple');
Subroutine loaded_xmlsimple: not called CC=1 SCAR=6.9
Pod undocumented
31 }
32  
33 sub loaded_xmlbackends {
34 # we need either XML::Parser or XML::SAX too
35 0 ▶ Dancer::ModuleLoader->load('XML::Parser') or
Subroutine loaded_xmlbackends: not called CC=2 SCAR=17.9
Pod undocumented
Branch: 1 branch
BranchTrueFalseTotal
"Dancer::ModuleLoader"->load("XML::Parser") or "Dancer::ModuleLoader"->load("XML::SAX") 0 0 0
36 Dancer::ModuleLoader->load('XML::SAX');
37 }
38  
39 sub init {
40 0 ▶ my ($self) = @_;
Subroutine init: not called CC=3 SCAR=24.8
Pod documented
41 0 ▶ die 'XML::Simple is needed and is not installed'
Branch: 1 branch
BranchTrueFalseTotal
unless $self->loaded_xmlsimple 0 0 0
42 unless $self->loaded_xmlsimple;
43 0 ▶ die 'XML::Simple needs XML::Parser or XML::SAX and neither is installed'
Branch: 1 branch
BranchTrueFalseTotal
unless $self->loaded_xmlbackends 0 0 0
44 unless $self->loaded_xmlbackends;
45 # Disable fetching external entities, as that's a security hole: this allows
46 # someone to fetch remote websites from the server, or to read local files.
47 # This only works for XML::Parser when called directly from XML::Simple;
48 # for XML::SAX we'll need to do some even *more* horrible stuff later on.
49 $_xs = XML::Simple->new(
50 ParserOpts => [
51 Handlers => {
52 ExternEnt => sub {
53 0 ▶ return '';
Subroutine __ANON__: not called CC=1 SCAR=6.9
54 }
55 }
56 0 ],
57 );
58 }
59  
60 sub serialize {
61 0 ▶ my $self = shift;
Subroutine serialize: not called CC=4 SCAR=30.0
Pod documented
62 0 my $entity = shift;
63 0 my %options = (RootName => 'data');
64  
65 0 ▶ my $s = setting('engines') || {};
Condition0%0/2
setting('engines') || {}
l!l
00
MC/DC0%0/1
setting('engines') || {}
setting('engines')
Truth table0%0/2
A
A= setting('engines')
Aresult
11
00
66 0 ▶ if (exists($s->{XMLSerializer}) && exists($s->{XMLSerializer}{serialize})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $s->{"XMLSerializer"} and exists $s->{"XMLSerializer"}{"serialize"}) 0 0 0
Condition0%0/3
exists $s->{"XMLSerializer"} and exists $s->{"XMLSerializer"}{"serialize"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $s->{"XMLSerializer"} and exists $s->{"XMLSerializer"}{"serialize"}
exists $s->{"XMLSerializer"} exists $s->{"XMLSerializer"}{"serialize"}
Truth table0%0/3
A and B
A= exists $s->{"XMLSerializer"}B= exists $s->{"XMLSerializer"}{"serialize"}
ABresult
0X0
100
111
67 0 %options = (%options, %{$s->{XMLSerializer}{serialize}});
68 }
69  
70 0 %options = (%options, @_);
71  
72  
73 0 $_xs->XMLout($entity, %options);
74 }
75  
76 sub deserialize {
77 0 ▶ my $self = shift;
Subroutine deserialize: not called CC=4 SCAR=26.6
Pod documented
78 0 my $xml = shift;
79 0 my %options = ();
80  
81 0 ▶ my $s = setting('engines') || {};
Condition0%0/2
setting('engines') || {}
l!l
00
MC/DC0%0/1
setting('engines') || {}
setting('engines')
Truth table0%0/2
A
A= setting('engines')
Aresult
11
00
82 0 ▶ if (exists($s->{XMLSerializer}) && exists($s->{XMLSerializer}{deserialize})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $s->{"XMLSerializer"} and exists $s->{"XMLSerializer"}{"deserialize"}) 0 0 0
Condition0%0/3
exists $s->{"XMLSerializer"} and exists $s->{"XMLSerializer"}{"deserialize"}
!ll&&!rl&&r
000
MC/DC0%0/2
exists $s->{"XMLSerializer"} and exists $s->{"XMLSerializer"}{"deserialize"}
exists $s->{"XMLSerializer"} exists $s->{"XMLSerializer"}{"deserialize"}
Truth table0%0/3
A and B
A= exists $s->{"XMLSerializer"}B= exists $s->{"XMLSerializer"}{"deserialize"}
ABresult
0X0
100
111
83 0 %options = (%options, %{$s->{XMLSerializer}{deserialize}});
84 }
85  
86 0 %options = (%options, @_);
87 # This is the promised terrible hack: claim that the LWP-talking code has
88 # already been loaded, and make sure that the handler that's called when
89 # we're dealing with an external entity does nothing.
90 # For whichever reason, this handler is called despite XML::Parser
91 # (which on my machine is the only XML::SAX backend that can handle
92 # external entities) having a ParseParamEnt option which is off by default,
93 # but appears to only be used deep in the XML::Parser XS guts.
94 170 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
95 0 ▶ local *XML::Parser::lwp_ext_ent_handler = sub { return };
Subroutine __ANON__: not called CC=1 SCAR=6.9
96 0 local $INC{'XML/Parser/LWPExternEnt.pl'}
97 = 'Dancer::Serializer::XML disabled loading this to patch around '
98 . 'XXE vulnerabilities';
99 0 $_xs->XMLin($xml, %options);
100 170 ▶ use warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
101 }
102  
103 0 ▶sub content_type {'text/xml'}
Subroutine content_type: not called CC=1 SCAR=6.9
Pod documented
104  
105 170 1;
106  
107 __END__
« blib/lib/Dancer/App.pm ↑ Summary blib/lib/Dancer/Error.pm »