Catalyst::View::Download::XML - Catalyst::View::Download::XML documentation


Catalyst-View-Download documentation Contained in the Catalyst-View-Download distribution.

Index


Code Index:

NAME

Top

Catalyst::View::Download::XML

VERSION

Top

0.01

SYNOPSIS

Top

  # lib/MyApp/View/Download/XML.pm
  package MyApp::View::Download::XML;
  use base qw( Catalyst::View::Download::XML );
  1;

  # lib/MyApp/Controller/SomeController.pm
  sub example_action_1 : Local {
    my ($self, $c) = @_;

    # supported content can be an xml document 
		my $content = "<?xml version="1.0"?>\n<root>\n<text>Some Text\n</text>\n</root>";

    # supported content can also be a hashref which will converted into xml using XMLout from L<XML::Simple>
    $content = {
      'root' => {
        'text' => 'Some Text'
      }
    };

    # To output your data just pass your content into the 'xml' key of the stash
    $c->stash->{'xml'} = {
			data => $content
		};

		# Or into the body of the response for this action
		$c->response->body($content);

    # Finally forward processing to the XML View
    $c->forward('MyApp::View::Download::XML');
  }

DESCRIPTION

Top

Takes content and outputs the content as html text.

SUBROUTINES

Top

process

This method will be called by Catalyst if it is asked to forward to a component without a specified action.

render

Allows others to use this view for much more fine-grained content generation.

XMLout

If a hashref is passed as content it will be converted using the XMLout function from the XML::Simple module. The following options are used to instantiate the XML::Simple object.

keeproot => 1
XMLDecl => "<?xml version='1.0' ?>"

CONFIG

Top

stash_key

Determines the key in the stash this view will look for when attempting to retrieve content to process. If this key isn't found it will then look at $c->response->body for content. Content when passed via the stash must be passed in a hashref in the key labeled 'data'

  $c->view('MyApp::View::Download::XML')->config->{'stash_key'} = 'content';

AUTHOR

Top

Travis Chase, <gaudeon at cpan.org>

SEE ALSO

Top

Catalyst Catalyst::View Catalyst::View::Download XML::Simple

COPYRIGHT & LICENSE

Top


Catalyst-View-Download documentation Contained in the Catalyst-View-Download distribution.
package Catalyst::View::Download::XML;

use strict;
use warnings;
use base qw( Catalyst::View );

use XML::Simple;

our $VERSION = "0.01";

__PACKAGE__->config( 'stash_key' => 'xml' );

sub process {
    my $self = shift;
    my ($c) = @_;

    my $template = $c->stash->{template};
    my $content = $self->render( $c, $template, $c->stash );

    $c->res->headers->header( "Content-Type" => "text/xml" )
      if ( $c->res->headers->header("Content-Type") eq "" );
    $c->res->body($content);
}

sub render {
    my $self = shift;
    my ( $c, $template, $args ) = @_;

    my $content;

    my $stash_key = $self->config->{'stash_key'};

    $content = $c->stash->{$stash_key}{'data'} || $c->response->body;

    if(ref($content) =~ /HASH/) {
      my $xs = new XML::Simple(keeproot => 1, XMLDecl => "<?xml version='1.0' ?>");
      $content = $xs->XMLout($content);
    }

    return $content;
}

1;
__END__