Deserialize/XML/Hash/LX.pm

filter: Statementstmt 83.3% 10 / 12 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod n/a totaltotal 87.5% 14 / 16 CC 1 SCAR 0.7
CC
1
Cov
83%
BEGIN
1.3
BEGIN
1.0
BEGIN
1.0
CRAP 1.1
↑ Summary Serialize/XML/Hash/LX.pm »
1 #
2 # Catlyst::Action::Deserialize::XML::Hash::LX.pm
3 # Created by: Mons Anderson, <mons@cpan.org>
4 #
5 # $Id$
6  
7 package Catalyst::Action::Deserialize::XML::Hash::LX;
8  
9 =head1 NAME
10  
11 Catalyst::Action::Deserialize::XML::Hash::LX - XML::Hash::LX deserializer for Catalyst
12  
13 =head1 SYNOPSIS
14  
15 package Foo::Controller::Bar;
16  
17 __PACKAGE__->config(
18 default => 'text/xml',
19 map => {
20 'text/xml' => 'XML::Hash::LX',
21 # or
22 'text/xml' => [ 'XML::Hash::LX', { XML::Hash::LX options } ],
23 },
24 )
25 sub begin : ActionClass('Deserialize') {}
26  
27 =head1 DESCRIPTION
28  
29 L<XML::Hash::LX> deserializer for L<Catalyst::Action::Deserialize>
30  
31 =cut
32  
33 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
34 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 1 ▶use base 'Catalyst::Action';
Subroutine BEGIN: called CC=1 SCAR=0.0
37 0 ▶use XML::Hash::LX 'xml2hash';
Subroutine BEGIN: called CC=1 SCAR=2.6
38  
39 our $VERSION = '0.06';
40  
41 sub execute {
42 my $self = shift;
43 my ( $controller, $c, $opts ) = @_;
44  
45 my $body = $c->request->body;
46 my $rbody;
47  
48 if ($body) {
49 while (my $line = <$body>) {
50 $rbody .= $line;
51 }
52 }
53  
54 if ( $rbody ) {
55 warn "Hash::LX deserialize";
56 my $rdata = eval { xml2hash( $rbody, $opts ? ( ref $opts eq 'ARRAY' ? @$opts : %$opts ) : () ) };
57 return $@ if $@;
58 $c->request->data($rdata);
59 } else {
60 $c->log->debug('I would have deserialized, but there was nothing in the body!') if $c->debug;
61 }
62 return 1;
63 }
64  
65 =head1 SEE ALSO
66  
67 =over 4
68  
69 =item * L<Catalyst::Action::Deserialize>
70  
71 =item * L<XML::Hash::LX>
72  
73 =back
74  
75 =head1 AUTHOR
76  
77 Mons Anderson, C<< <mons at cpan.org> >>
78  
79 =head1 COPYRIGHT & LICENSE
80  
81 Copyright 2009 Mons Anderson, all rights reserved.
82  
83 This program is free software; you can redistribute it and/or modify it
84 under the same terms as Perl itself.
85  
86 =cut
87  
88 1;
↑ Summary Serialize/XML/Hash/LX.pm »