File Coverage

blib/lib/Catalyst/View/PDFBoxer.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::PDFBoxer;
2             {
3             $Catalyst::View::PDFBoxer::VERSION = '0.001';
4             }
5 1     1   31702 use Moose::Role;
  0            
  0            
6              
7             # ABSTRACT: Runs view output through PDF::Boxer and sets response content-type if not already set.
8              
9             use PDF::Boxer 0.003;
10             use PDF::Boxer::SpecParser;
11              
12             use namespace::clean -except => 'meta';
13              
14             requires 'process';
15              
16             before process => sub {
17             my ($self, $c) = @_;
18             unless ( $c->response->content_type ) {
19             $c->response->content_type('application/pdf; charset=utf-8');
20             }
21             };
22              
23             after process => sub {
24             my ($self, $c) = @_;
25             my $spec = PDF::Boxer::SpecParser->new->parse($c->response->body);
26             my $boxer = PDF::Boxer->new;
27             $boxer->add_to_pdf($spec);
28             $c->response->body($boxer->doc->pdf->stringify);
29             };
30              
31             1;
32              
33              
34              
35             =pod
36              
37             =head1 NAME
38              
39             Catalyst::View::PDFBoxer - Runs view output through PDF::Boxer and sets response content-type if not already set.
40              
41             =head1 VERSION
42              
43             version 0.001
44              
45             =head1 SYNOPSIS
46              
47             package MyApp::View::PDFBoxer;
48              
49             use Moose;
50             use namespace::clean -except => 'meta';
51              
52             extends qw/Catalyst::View::TT/;
53             with qw/Catalyst::View::PDFBoxer/;
54              
55             1;
56              
57             =head1 DESCRIPTION
58              
59             This is a Role which takes the current $c->response->body, runs it through
60             PDF::Boxer as it's "spec" file to get a PDF::API2 object. $c->response->body
61             is then set to the stringified PDF and content-type is set accordingly.
62              
63             =head1 METHOD MODIFIERS
64              
65             =head2 before process
66              
67             Sets content-type to 'application/pdf; charset=utf-8' if not already set.
68              
69             =head2 after process
70              
71             Takes the current $c->response->body, runs it through PDF::Boxer as it's "spec"
72             file to get a PDF::API2 object. $c->response->body is then set to the
73             stringified PDF.
74              
75             =head1 SEE ALSO
76              
77             =over 4
78              
79             =item *
80              
81             L<PDF::Boxer> - PDF generator used by this role.
82              
83             =back
84              
85             =head1 AUTHOR
86              
87             Jason Galea <lecstor@cpan.org>
88              
89             =head1 COPYRIGHT AND LICENSE
90              
91             This software is copyright (c) 2011 by Jason Galea.
92              
93             This is free software; you can redistribute it and/or modify it under
94             the same terms as the Perl 5 programming language system itself.
95              
96             =cut
97              
98              
99             __END__
100              
101              
102              
103              
104