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 CC 10 SCAR 20.3
CC
10
Cov
35%
serialize
20.0
deserialize
14.3
init
12.0
CRAP 7.6
« lib/Dancer/App.pm ↑ Summary lib/Dancer/Plugin/Ajax.pm »
1 package Dancer::Serializer::XML;
2 177 our $AUTHORITY = 'cpan:SUKRIA';
3 #ABSTRACT: serializer for handling XML data
4 177 $Dancer::Serializer::XML::VERSION = '1.3522';
5 177 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 177 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 177 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 177 ▶use Dancer::ModuleLoader;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 177 ▶use Dancer::Config 'setting';
Subroutine BEGIN: called CC=1 SCAR=0.0
10 177 ▶use base 'Dancer::Serializer::Abstract';
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # singleton for the XML::Simple object
13 177 my $_xs;
14  
15 # helpers
16  
17 0 ▶sub from_xml {
Subroutine from_xml: not called CC=1 SCAR=6.9
Pod undocumented
18 0 my $s = Dancer::Serializer::XML->new;
19 0 $s->deserialize(@_);
20 }
21  
22 0 ▶sub to_xml {
Subroutine to_xml: not called CC=1 SCAR=6.9
Pod undocumented
23 0 my $s = Dancer::Serializer::XML->new;
24 0 $s->serialize(@_);
25 }
26  
27 # class definition
28  
29 0 ▶sub loaded_xmlsimple {
Subroutine loaded_xmlsimple: not called CC=1 SCAR=6.9
Pod undocumented
30 0 Dancer::ModuleLoader->load('XML::Simple');
31 }
32  
33 0 ▶sub loaded_xmlbackends {
Subroutine loaded_xmlbackends: not called CC=2 SCAR=17.9
Pod undocumented
34 # we need either XML::Parser or XML::SAX too
35 0 ▶ Dancer::ModuleLoader->load('XML::Parser') or
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 0 ▶sub init {
Subroutine init: not called CC=3 SCAR=24.8
Pod documented
40 0 my ($self) = @_;
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 0 ▶ ExternEnt => sub {
Subroutine __ANON__: not called CC=1 SCAR=6.9
53 0 return '';
54 }
55 }
56 0 ],
57 );
58 }
59  
60 0 ▶sub serialize {
Subroutine serialize: not called CC=4 SCAR=30.0
Pod documented
61 0 my $self = shift;
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 0 ▶sub deserialize {
Subroutine deserialize: not called CC=4 SCAR=26.6
Pod documented
77 0 my $self = shift;
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 177 ▶ 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 177 ▶ 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 177 1;
106  
107 __END__
« lib/Dancer/App.pm ↑ Summary lib/Dancer/Plugin/Ajax.pm »