Catalyst-View-PDF-Reuse-0.04/000755 000765 000024 00000000000 11407633061 015370 5ustar00jjstaff000000 000000 Catalyst-View-PDF-Reuse-0.04/Changes000644 000765 000024 00000000772 11407632714 016675 0ustar00jjstaff000000 000000 Revision history for Catalyst-View-PDF-Reuse 0.04 21-Jun-2010 Fixed bug which prevented templates from being found when using relative paths 0.03 08-Feb-2009 10:06 Added missing prereq for parent.pm (reported by CPAN testers, thanks Chris!) 0.02 07-Feb-2009 12:19 Added option to control the Content-Disposition header Added 'render' method to access the raw PDF data 0.01 Date/time First version, released on an unsuspecting world. Catalyst-View-PDF-Reuse-0.04/lib/000755 000765 000024 00000000000 11407633061 016136 5ustar00jjstaff000000 000000 Catalyst-View-PDF-Reuse-0.04/Makefile.PL000644 000765 000024 00000001270 11245441756 017352 0ustar00jjstaff000000 000000 use strict; use warnings; use ExtUtils::MakeMaker; WriteMakefile( NAME => 'Catalyst::View::PDF::Reuse', AUTHOR => 'Jon Allen ', VERSION_FROM => 'lib/Catalyst/View/PDF/Reuse.pm', ABSTRACT_FROM => 'lib/Catalyst/View/PDF/Reuse.pm', PL_FILES => {}, PREREQ_PM => { 'Test::More' => 0, 'Catalyst::View::TT' => 0, 'PDF::Reuse' => 0, 'File::chdir' => 0, 'Template::Plugin::Procedural' => 0, 'parent' => 0, }, dist => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', }, clean => { FILES => 'Catalyst-View-PDF-Reuse-*' }, ); Catalyst-View-PDF-Reuse-0.04/MANIFEST000644 000765 000024 00000000502 11407633061 016516 0ustar00jjstaff000000 000000 Changes lib/Catalyst/Helper/View/PDF/Reuse.pm lib/Catalyst/View/PDF/Reuse.pm lib/Template/Plugin/Catalyst/View/PDF/Reuse.pm lib/Template/Plugin/Catalyst/View/PDF/Reuse/Barcode.pm Makefile.PL MANIFEST README t/00-load.t t/boilerplate.t t/pod.t META.yml Module meta-data (added by MakeMaker) Catalyst-View-PDF-Reuse-0.04/META.yml000644 000765 000024 00000001363 11407633061 016644 0ustar00jjstaff000000 000000 --- #YAML:1.0 name: Catalyst-View-PDF-Reuse version: 0.04 abstract: Create PDF files from Catalyst using Template Toolkit templates author: - Jon Allen license: unknown distribution_type: module configure_requires: ExtUtils::MakeMaker: 0 build_requires: ExtUtils::MakeMaker: 0 requires: Catalyst::View::TT: 0 File::chdir: 0 parent: 0 PDF::Reuse: 0 Template::Plugin::Procedural: 0 Test::More: 0 no_index: directory: - t - inc generated_by: ExtUtils::MakeMaker version 6.55_02 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: 1.4 Catalyst-View-PDF-Reuse-0.04/README000644 000765 000024 00000003214 11245441756 016260 0ustar00jjstaff000000 000000 NAME Catalyst::View::PDF::Reuse - Create PDF files from Catalyst using Template Toolkit templates VERSION Version 0.01 SYNOPSIS Create a PDF::Reuse view: script/myapp_create.pl view PDF::Reuse PDF::Reuse In MyApp.pm, add a configuration item for the template include path: __PACKAGE__->config('View::PDF::Reuse' => { INCLUDE_PATH => __PACKAGE__->path_to('root','templates') }); In your controller: $c->stash->{pdf_template} = 'hello_pdf.tt'; $c->forward('View::PDF::Reuse'); In root/templates/hello_pdf.tt: [% pdf.prFont('Helvetica-Bold') %] [% pdf.prFontSize(20) %] [% pdf.prText(100,100,'Hello, World!') %] INSTALLATION To install this module, run the following commands: perl Makefile.PL make make test make install SUPPORT AND DOCUMENTATION After installing, you can find documentation for this module with the perldoc command. perldoc Catalyst::View::PDF::Reuse You can also look for information at: RT, CPAN's request tracker http://rt.cpan.org/NoAuth/Bugs.html?Dist=Catalyst-View-PDF-Reuse AnnoCPAN, Annotated CPAN documentation http://annocpan.org/dist/Catalyst-View-PDF-Reuse CPAN Ratings http://cpanratings.perl.org/d/Catalyst-View-PDF-Reuse Search CPAN http://search.cpan.org/dist/Catalyst-View-PDF-Reuse SEE ALSO Penny's Arcade Open Source - http://www.pennysarcade.co.uk/opensource COPYRIGHT AND LICENCE Copyright (C) 2009 Penny's Arcade Limited This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. Catalyst-View-PDF-Reuse-0.04/t/000755 000765 000024 00000000000 11407633061 015633 5ustar00jjstaff000000 000000 Catalyst-View-PDF-Reuse-0.04/t/00-load.t000644 000765 000024 00000000274 11245441756 017167 0ustar00jjstaff000000 000000 #!perl -T use Test::More tests => 1; BEGIN { use_ok( 'Catalyst::View::PDF::Reuse' ); } diag( "Testing Catalyst::View::PDF::Reuse $Catalyst::View::PDF::Reuse::VERSION, Perl $], $^X" ); Catalyst-View-PDF-Reuse-0.04/t/boilerplate.t000644 000765 000024 00000002461 11245441756 020335 0ustar00jjstaff000000 000000 #!perl -T use strict; use warnings; use Test::More tests => 3; sub not_in_file_ok { my ($filename, %regex) = @_; open( my $fh, '<', $filename ) or die "couldn't open $filename for reading: $!"; my %violated; while (my $line = <$fh>) { while (my ($desc, $regex) = each %regex) { if ($line =~ $regex) { push @{$violated{$desc}||=[]}, $.; } } } if (%violated) { fail("$filename contains boilerplate text"); diag "$_ appears on lines @{$violated{$_}}" for keys %violated; } else { pass("$filename contains no boilerplate text"); } } sub module_boilerplate_ok { my ($module) = @_; not_in_file_ok($module => 'the great new $MODULENAME' => qr/ - The great new /, 'boilerplate description' => qr/Quick summary of what the module/, 'stub function definition' => qr/function[12]/, ); } TODO: { local $TODO = "Need to replace the boilerplate text"; not_in_file_ok(README => "The README is used..." => qr/The README is used/, "'version information here'" => qr/to provide version information/, ); not_in_file_ok(Changes => "placeholder date/time" => qr(Date/time) ); module_boilerplate_ok('lib/Catalyst/View/PDF/Reuse.pm'); } Catalyst-View-PDF-Reuse-0.04/t/pod.t000644 000765 000024 00000000350 11245441756 016610 0ustar00jjstaff000000 000000 #!perl -T use strict; use warnings; use Test::More; # Ensure a recent version of Test::Pod my $min_tp = 1.22; eval "use Test::Pod $min_tp"; plan skip_all => "Test::Pod $min_tp required for testing POD" if $@; all_pod_files_ok(); Catalyst-View-PDF-Reuse-0.04/lib/Catalyst/000755 000765 000024 00000000000 11407633061 017722 5ustar00jjstaff000000 000000 Catalyst-View-PDF-Reuse-0.04/lib/Template/000755 000765 000024 00000000000 11407633061 017711 5ustar00jjstaff000000 000000 Catalyst-View-PDF-Reuse-0.04/lib/Template/Plugin/000755 000765 000024 00000000000 11407633061 021147 5ustar00jjstaff000000 000000 Catalyst-View-PDF-Reuse-0.04/lib/Template/Plugin/Catalyst/000755 000765 000024 00000000000 11407633061 022733 5ustar00jjstaff000000 000000 Catalyst-View-PDF-Reuse-0.04/lib/Template/Plugin/Catalyst/View/000755 000765 000024 00000000000 11407633061 023645 5ustar00jjstaff000000 000000 Catalyst-View-PDF-Reuse-0.04/lib/Template/Plugin/Catalyst/View/PDF/000755 000765 000024 00000000000 11407633061 024256 5ustar00jjstaff000000 000000 Catalyst-View-PDF-Reuse-0.04/lib/Template/Plugin/Catalyst/View/PDF/Reuse/000755 000765 000024 00000000000 11407633061 025341 5ustar00jjstaff000000 000000 Catalyst-View-PDF-Reuse-0.04/lib/Template/Plugin/Catalyst/View/PDF/Reuse.pm000644 000765 000024 00000001101 11245441756 025700 0ustar00jjstaff000000 000000 package Template::Plugin::Catalyst::View::PDF::Reuse; use base qw(Template::Plugin::Procedural); use PDF::Reuse; =head1 NAME Template::Plugin::Catalyst::View::PDF::Reuse =head1 SYNOPSYS Template Toolkit plugin for PDF::Reuse =head1 AUTHOR Jon Allen, L =head1 SEE ALSO Penny's Arcade Open Source - L =head1 COPYRIGHT & LICENSE Copyright 2009 Penny's Arcade Limited, all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1; Catalyst-View-PDF-Reuse-0.04/lib/Template/Plugin/Catalyst/View/PDF/Reuse/Barcode.pm000644 000765 000024 00000003271 11260145142 027234 0ustar00jjstaff000000 000000 package Template::Plugin::Catalyst::View::PDF::Reuse::Barcode; use strict; use warnings; use parent 'Template::Plugin'; our $AUTOLOAD; our $target = 'PDF::Reuse::Barcode'; # Adapted from Template::Plugin::Procedural by Mark Fowler sub load { my ($class, $context) = @_; my $proxy = "Template::Plugin::" . $class; eval "use $target"; no strict "refs"; if ($@) { my $error = $@; *{ $proxy . "::AUTOLOAD" } = sub { $AUTOLOAD =~ s!^.*::!!; die "Cannot load $target so unable to execute '$AUTOLOAD' in template - $error" unless ($AUTOLOAD eq 'DESTROY'); }; } else { *{ $proxy . "::AUTOLOAD" } = sub { $AUTOLOAD =~ s!^.*::!!; if (my $method = $target->can($AUTOLOAD)) { shift @_; # Expand hashref arguments for PDF::Reuse::Barcode if (ref $_[0] eq 'HASH') { splice @_,0,1,%{$_[0]}; } goto $method; } else { warn "Cannot find method $AUTOLOAD in $target"; } }; } *{ $proxy . "::new" } = sub { my $this; return bless \$this, $_[0]; }; return $proxy; } =head1 NAME Template::Plugin::Catalyst::View::PDF::Reuse =head1 SYNOPSYS Template Toolkit plugin for PDF::Reuse =head1 AUTHOR Jon Allen, L =head1 SEE ALSO Penny's Arcade Open Source - L =head1 COPYRIGHT & LICENSE Copyright 2009 Penny's Arcade Limited, all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1; Catalyst-View-PDF-Reuse-0.04/lib/Catalyst/Helper/000755 000765 000024 00000000000 11407633061 021141 5ustar00jjstaff000000 000000 Catalyst-View-PDF-Reuse-0.04/lib/Catalyst/View/000755 000765 000024 00000000000 11407633061 020634 5ustar00jjstaff000000 000000 Catalyst-View-PDF-Reuse-0.04/lib/Catalyst/View/PDF/000755 000765 000024 00000000000 11407633061 021245 5ustar00jjstaff000000 000000 Catalyst-View-PDF-Reuse-0.04/lib/Catalyst/View/PDF/Reuse.pm000644 000765 000024 00000014211 11407631666 022676 0ustar00jjstaff000000 000000 package Catalyst::View::PDF::Reuse; use warnings; use strict; use parent 'Catalyst::View::TT'; use File::chdir; use File::Spec::Functions qw/catfile rel2abs/; use File::Temp qw/tmpnam/; use PDF::Reuse; our $VERSION = '0.04'; =head1 NAME Catalyst::View::PDF::Reuse - Create PDF files from Catalyst using Template Toolkit templates =cut =head1 SYNOPSIS Create a PDF::Reuse view: script/myapp_create.pl view PDF::Reuse PDF::Reuse In MyApp.pm, add a configuration item for the template include path: __PACKAGE__->config('View::PDF::Reuse' => { INCLUDE_PATH => __PACKAGE__->path_to('root','templates') }); In your controller: $c->stash->{pdf_template} = 'hello_pdf.tt'; $c->forward('View::PDF::Reuse'); In F: [% pdf.prFont('Helvetica-Bold') %] [% pdf.prFontSize(20) %] [% pdf.prText(100,100,'Hello, World!') %] =head1 DESCRIPTION Catalyst::View::PDF::Reuse provides the facility to generate PDF files from a Catalyst application by embedding L commands within a Template Toolkit template. =head2 Template Syntax Within your template you will have access to a C object which has methods corresponding to all of L's functions. For example, to print the text I at PDF coordinates 100,100, use the following directive in your template: [% pdf.prText(100,100,'Hello, World') %] Data held in the stash can be printed as follows: $c->stash->{list} = ['one', 'two', 'three', 'four']; [% y = 500 %] [% FOREACH item IN list %] [% pdf.prText(100,y,item) %] [% y = y - 13 %] [% END %] Formatting can be defined using the Template Toolkit format plugin: [% USE format %] [% currency = format('£%.2f') %] [% pdf.prText(100,100,currency(10)) %] =head2 Using existing PDF documents The key benefit of L is the ability to load an existing PDF file and use this as the basis for a new document. For example, to produce receipts or shipping labels you could create a blank receipt in Microsoft Word, convert this to PDF, then use PDF::Reuse to add in details such as the order number and customer address. [% pdf.prForm('customer_receipt.pdf') %] [% pdf.prText(123,643,order.number) %] [% pdf.prText(299,643,order.date) %] Note that the PDF document loaded by C must be in the same directory as your Template Toolkit template. =head1 FUNCTIONS =head2 process Render the PDF file, places the contents in C<< $c->response->body >> and sets appropriate HTTP headers. You should normally not need to use this method directly, instead forward to the PDF::Reuse view from your controller: $c->forward('View::PDF::Reuse'); The filename and content disposition (inline or attachment) can be controlled by putting the following values in the stash: $c->stash->{pdf_disposition} = 'attachment'; # Default is 'inline' $c->stash->{pdf_filename} = 'myfile.pdf'; If the PDF filename is not specified, it will be set to the last component of the URL path, appended with '.pdf'. For example, with a URL of L the PDF filename would be set to F<1234.pdf>. =cut sub process { my ($self, $c) = @_; my $output = $self->render_pdf($c); if (UNIVERSAL::isa($output, 'Template::Exception')) { my $error = qq/Couldn't render template "$output"/; $c->log->error($error); $c->error($error); return 0; } my $pdf_filename = $c->stash->{pdf_filename} || (split '/',$c->req->path)[-1] || 'index.pdf'; $pdf_filename .= '.pdf' unless ($pdf_filename =~ /\.pdf$/i); my $pdf_disposition = $c->stash->{pdf_disposition} || 'inline'; $c->response->content_type('application/pdf'); $c->response->headers->header("Content-Disposition" => qq{$pdf_disposition; filename="$pdf_filename"}); $c->response->body($output); } =head2 render_pdf Renders the PDF file and returns the raw PDF data. If you need to capture the PDF data, e.g. to store in a database or for emailing, call C as follows: my $pdf = $c->view("PDF::Reuse")->render_pdf($c); =cut sub render_pdf { my ($self, $c) = @_; my $template = <<'EOT'; [% USE pdf = Catalyst::View::PDF::Reuse %] [% USE barcode = Catalyst::View::PDF::Reuse::Barcode %] [% PROCESS $pdf_template %] EOT my $tempfile = tmpnam(); prInitVars(); prFile($tempfile); # Convert any relative include paths to absolute paths foreach my $path (@{$self->config->{INCLUDE_PATH}}) { $path = rel2abs($path); } my $output; SEARCH: foreach my $path (@{$self->config->{INCLUDE_PATH}}) { if (-e catfile($path,$c->stash->{pdf_template})) { local $CWD = $path; $output = $self->render($c,\$template); last SEARCH; } } prEnd(); my $pdf; local $/ = undef; open PDF,'<',$tempfile; $pdf = (); close PDF; unlink $tempfile; return (UNIVERSAL::isa($output, 'Template::Exception')) ? $output : $pdf; } =head1 AUTHOR Jon Allen, L =head1 BUGS Please report any bugs or feature requests to C, or through the web interface at L. I will be notified, and then you'll automatically be notified of progress on your bug as I make changes. =head1 SUPPORT You can find documentation for this module with the perldoc command. perldoc Catalyst::View::PDF::Reuse You can also look for information at: =over 4 =item * RT: CPAN's request tracker L =item * AnnoCPAN: Annotated CPAN documentation L =item * CPAN Ratings L =item * Search CPAN L =back =head1 SEE ALSO L Penny's Arcade Open Source - L =head1 COPYRIGHT & LICENSE Copyright (C) 2009 Penny's Arcade Limited This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1; # End of Catalyst::View::PDF::Reuse Catalyst-View-PDF-Reuse-0.04/lib/Catalyst/Helper/View/000755 000765 000024 00000000000 11407633061 022053 5ustar00jjstaff000000 000000 Catalyst-View-PDF-Reuse-0.04/lib/Catalyst/Helper/View/PDF/000755 000765 000024 00000000000 11407633061 022464 5ustar00jjstaff000000 000000 Catalyst-View-PDF-Reuse-0.04/lib/Catalyst/Helper/View/PDF/Reuse.pm000644 000765 000024 00000002731 11245441756 024120 0ustar00jjstaff000000 000000 package Catalyst::Helper::View::PDF::Reuse; use strict; =head1 NAME Catalyst::Helper::View::PDF::Reuse - Helper for PDF::Reuse Views =head1 SYNOPSIS To create a PDF::Reuse view in your Catalyst application, enter the following command: script/myapp_create.pl view PDF::Reuse PDF::Reuse Then in MyApp.pm, add a configuration item for the View::PDF::Reuse include path: __PACKAGE__->config('View::PDF::Reuse' => { INCLUDE_PATH => __PACKAGE__->path_to('root','templates') }); =head1 DESCRIPTION Helper for PDF::Reuse Views. =head2 METHODS =head3 mk_compclass =cut sub mk_compclass { my ( $self, $helper ) = @_; my $file = $helper->{file}; $helper->render_file( 'compclass', $file ); } =head1 AUTHOR Jon Allen, L =head1 SEE ALSO L Penny's Arcade Open Source - L =head1 COPYRIGHT & LICENSE Copyright 2009 Penny's Arcade Limited, all rights reserved. This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1; __DATA__ __compclass__ package [% class %]; use strict; use base 'Catalyst::View::PDF::Reuse'; =head1 NAME [% class %] - PDF::Reuse View for [% app %] =head1 DESCRIPTION PDF::Reuse View for [% app %]. =head1 AUTHOR [% author %] =head1 SEE ALSO L<[% app %]> =head1 LICENSE This library is free software, you can redistribute it and/or modify it under the same terms as Perl itself. =cut 1;