AnnoCPAN::XMLCGI - Read XML input through a CGI.pm-like interface


AnnoCPAN documentation Contained in the AnnoCPAN distribution.

Index


Code Index:

NAME

Top

AnnoCPAN::XMLCGI - Read XML input through a CGI.pm-like interface

SYNOPSYS

Top

    use AnnoCPAN::XMLCGI;

    my $cgi = AnnoCPAN::XMLCGI->new;

    my $name = $cgi->param('name');
    print $cgi->header;
    print "Hello, $name!\n";    # Hello, Bob!

    # In STDIN...
    <data>
        <name>Bob</name>
        <age>123</age>
    <data>

DESCRIPTION

Top

This module reads XML from STDIN and makes it available through and interface that is compatible with a subset of that for CGI. Its purpose is to be used as a drop-in replacement for CGI for JavaScript XMLHttpRequest handlers that receive their input in XML instead of the typical CGI form encoding.

Note that only a very minimal subset of CGI is implemented, but it is the only part that is required for most simple uses.

The input stream is expected to be a very simple XML structure with only one level of depth, and with no duplicate keys. The root element (<data> in the example above) can be have any tag name.

METHODS

Top

AnnoCPAN::XMLCGI->new

Create an AnnoCPAN::XMLCGI object. Doesn't take any parameters. When called, it slurps everything in STDIN; therefore it's not a very good idea to call it more than once.

Returns false if there was a parsing error.

$cgi->param($name)

Return the value of the parameter $name. Note that, unlike CGI, it doesn't handle multiple values.

$cgi->header

Returns a very simple header ("Content-type: text/html; charset=UTF-8\n\n").

SEE ALSO

Top

CGI, XML::Simple

AUTHOR

Top

Ivan Tubert-Brohman <itub@cpan.org>

COPYRIGHT

Top


AnnoCPAN documentation Contained in the AnnoCPAN distribution.
package AnnoCPAN::XMLCGI;

$VERSION = '0.22';

use strict;
use warnings;
use XML::Simple qw(XMLin);

sub new {
    my $self = bless {}, shift;
    $self->init;
}

sub init {
    my ($self) = @_;
    eval {$self->{data} = XMLin('-', suppressEmpty => "") };
    if ($@) {
        $self->{error} = $@;
    }
    $self;
}

sub param {
    my ($self, $name) = @_;
    $self->{data}{$name};
}

sub header {
    "Content-type: text/html; charset=UTF-8\n\n";
}

1;