File Coverage

blib/lib/Catalyst/View/XML/Generator.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             package Catalyst::View::XML::Generator;
2 1     1   24627 use Moose;
  0            
  0            
3             BEGIN { extends 'Catalyst::View' }
4              
5             use XML::SAX::Writer;
6             use XML::Generator::PerlData;
7             use namespace::clean;
8              
9             =head1 NAME
10              
11             Catalyst::View::XML::Generator - Serialize the stash as XML using XML::Generator::PerlData
12              
13             =head1 VERSION
14              
15             Version 0.02
16              
17             =cut
18              
19             our $VERSION = '0.02';
20              
21             =head1 SYNOPSIS
22              
23             __PACKAGE__->config(
24             'XML::Generator' => {
25             rootname => 'document',
26             attrmap => {
27             action => [qw( class name )],
28             view => [qw( type )]
29             }
30             }
31             );
32              
33             =head1 DESCRIPTION
34              
35             This Catalyst view renders the context stash as XML using L<XML::Generator::PerlData>. This enables you
36             to quickly render customized XML output using a set of rules to dictate which hash parameters will be stored
37             as attributes, elements, and other configuration options.
38              
39             =cut
40              
41             sub process {
42             my ($self, $c) = @_;
43              
44             my $conf = $c->config->{'View::XML'};
45              
46             my $content = '';
47             my $builder = XML::SAX::Writer->new(Output => \$content);
48             my $generator = XML::Generator::PerlData->new(
49             Handler => $builder,
50             %{ $conf }
51             );
52              
53             my $dom = $generator->parse($c->stash);
54              
55             $c->response->content_type("text/xml");
56             $c->response->body($content);
57             1;
58             }
59              
60             =head1 AUTHOR
61              
62             Michael Nachbaur, C<< <mike@nachbaur.com> >>
63              
64             =head1 BUGS
65              
66             Please report any bugs or feature requests to C<bug-catalyst-view-xml-generator at rt.cpan.org>, or through
67             the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Catalyst-View-XML-Generator>. I will be notified, and then you'll
68             automatically be notified of progress on your bug as I make changes.
69              
70             =head1 SEE ALSO
71              
72             L<Catalyst>, L<Catalyst::View>, L<XML::Generator::PerlData>
73              
74             =head1 SUPPORT
75              
76             You can find documentation for this module with the perldoc command.
77              
78             perldoc Catalyst::View::XML::Generator
79              
80             You can also look for information at:
81              
82             =over 4
83              
84             =item * RT: CPAN's request tracker
85              
86             L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Catalyst-View-XML-Generator>
87              
88             =item * AnnoCPAN: Annotated CPAN documentation
89              
90             L<http://annocpan.org/dist/Catalyst-View-XML-Generator>
91              
92             =item * CPAN Ratings
93              
94             L<http://cpanratings.perl.org/d/Catalyst-View-XML-Generator>
95              
96             =item * Search CPAN
97              
98             L<http://search.cpan.org/dist/Catalyst-View-XML-Generator/>
99              
100             =item * Download the source from Github
101              
102             L<http://github.com/NachoMan/Catalyst-View-XML-Generator/>
103              
104             =back
105              
106             =head1 COPYRIGHT & LICENSE
107              
108             Copyright (c) 2009 Michael Nachbaur
109              
110             This program is free software; you can redistribute it and/or modify it
111             under the same terms as Perl itself.
112              
113             =cut
114              
115             1;