Catalyst::Action::Deserialize::XML::Hash::LX - XML::Hash::LX deserializer for Catalyst


Catalyst-Action-Serialize-XML-Hash-LX documentation Contained in the Catalyst-Action-Serialize-XML-Hash-LX distribution.

Index


Code Index:

NAME

Top

Catalyst::Action::Deserialize::XML::Hash::LX - XML::Hash::LX deserializer for Catalyst

SYNOPSIS

Top

    package Foo::Controller::Bar;

    __PACKAGE__->config(
        default => 'text/xml',
        map => {
            'text/xml' => 'XML::Hash::LX',
            # or 
            'text/xml' => [ 'XML::Hash::LX', { XML::Hash::LX options } ],
        },
    )
    sub begin : ActionClass('Deserialize') {}

DESCRIPTION

Top

XML::Hash::LX deserializer for Catalyst::Action::Deserialize

SEE ALSO

Top

* Catalyst::Action::Deserialize
* XML::Hash::LX

AUTHOR

Top

Mons Anderson, <mons at cpan.org>

COPYRIGHT & LICENSE

Top


Catalyst-Action-Serialize-XML-Hash-LX documentation Contained in the Catalyst-Action-Serialize-XML-Hash-LX distribution.
#
# Catlyst::Action::Deserialize::XML::Hash::LX.pm
# Created by: Mons Anderson, <mons@cpan.org>
#
# $Id$

package Catalyst::Action::Deserialize::XML::Hash::LX;

use strict;
use warnings;

use base 'Catalyst::Action';
use XML::Hash::LX 'xml2hash';

our $VERSION = '0.06';

sub execute {
	my $self = shift;
	my ( $controller, $c, $opts ) = @_;

	my $body = $c->request->body;
	my $rbody;

	if ($body) {
		while (my $line = <$body>) {
			$rbody .= $line;
		}
	}

	if ( $rbody ) {
		warn "Hash::LX deserialize";
		my $rdata = eval { xml2hash( $rbody, $opts ? ( ref $opts eq 'ARRAY' ? @$opts : %$opts ) : () ) };
		return $@ if $@;
		$c->request->data($rdata);
	} else {
		$c->log->debug('I would have deserialized, but there was nothing in the body!') if $c->debug;
	}
	return 1;
}

1;