blib/lib/auto/share/dist/Cmd-Dwarf/app/lib/Dwarf/Plugin/XML/Simple.pm untested

filter: Statementstmt 0.0% 0 / 31 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 2 MC/DCmcdc 0.0% 0 / 1 Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 45 CC 4 SCAR 25.1
CC
4
Cov
0%
init
20.0
BEGIN
2.0
BEGIN
2.0
CRAP 12.3
1 package Dwarf::Plugin::XML::Simple;
2 use Dwarf::Pragma;
3 use Dwarf::Util qw/encode_utf8 add_method/;
4 use XML::Simple;
5  
6 sub init {
7 my ($class, $c, $conf) = @_;
8 $conf ||= {};
9  
10 $c->{'dwarf.xml'} = XML::Simple->new(%$conf);
11  
12 add_method($c, xml => sub {
13 my $self = shift;
14 if (@_ == 1) {
15 $self->{'dwarf.xml'} = $_[0];
16 }
17 return $self->{'dwarf.xml'};
18 });
19  
20 add_method($c, decode_xml => sub {
21 my ($self, $data, @opts) = @_;
22 return $self->{'dwarf.xml'}->XMLin($data, @opts);
23 });
24  
25 add_method($c, encode_xml => sub {
26 my ($self, $data, @opts) = @_;
27 return $self->{'dwarf.xml'}->XMLout($data, @opts);
28 });
29  
30 $c->add_trigger(AFTER_DISPATCH => sub {
31 my ($self, $res) = @_;
32 return unless ref $res->body;
33  
34 if ($res->content_type =~ /(application|text)\/xml/) {
35 $self->call_trigger(BEFORE_RENDER => $self->handler, $self, $res->body);
36 my $encoded = $self->encode_xml($res->body);
37 $self->call_trigger(AFTER_RENDER => $self->handler, $self, \$encoded);
38 $res->body(encode_utf8($encoded));
39 }
40 });
41 }
42  
43 1;