[Catalyst-commits] r11289 - in Catalyst-View-PDF-API2-Simple/trunk: . lib lib/Catalyst lib/Catalyst/Helper lib/Catalyst/Helper/View lib/Catalyst/Helper/View/PDF lib/Catalyst/Helper/View/PDF/API2 lib/Catalyst/View lib/Catalyst/View/PDF lib/Catalyst/View/PDF/API2 t t/lib t/lib/TestApp t/lib/TestApp/Controller t/lib/TestApp/View t/lib/TestApp/View/PDF t/lib/TestApp/View/PDF/API2 t/lib/TestApp/root t/lib/TestApp/root/pdf_templates t/lib/script

ferz at dev.catalyst.perl.org ferz at dev.catalyst.perl.org
Tue Sep 1 09:38:18 GMT 2009


Author: ferz
Date: 2009-09-01 09:38:17 +0000 (Tue, 01 Sep 2009)
New Revision: 11289

Added:
   Catalyst-View-PDF-API2-Simple/trunk/Changes
   Catalyst-View-PDF-API2-Simple/trunk/MANIFEST.pdf
   Catalyst-View-PDF-API2-Simple/trunk/Makefile.PL
   Catalyst-View-PDF-API2-Simple/trunk/README
   Catalyst-View-PDF-API2-Simple/trunk/lib/
   Catalyst-View-PDF-API2-Simple/trunk/lib/Catalyst/
   Catalyst-View-PDF-API2-Simple/trunk/lib/Catalyst/Helper/
   Catalyst-View-PDF-API2-Simple/trunk/lib/Catalyst/Helper/View/
   Catalyst-View-PDF-API2-Simple/trunk/lib/Catalyst/Helper/View/PDF/
   Catalyst-View-PDF-API2-Simple/trunk/lib/Catalyst/Helper/View/PDF/API2/
   Catalyst-View-PDF-API2-Simple/trunk/lib/Catalyst/Helper/View/PDF/API2/Simple.pm
   Catalyst-View-PDF-API2-Simple/trunk/lib/Catalyst/View/
   Catalyst-View-PDF-API2-Simple/trunk/lib/Catalyst/View/PDF/
   Catalyst-View-PDF-API2-Simple/trunk/lib/Catalyst/View/PDF/API2/
   Catalyst-View-PDF-API2-Simple/trunk/lib/Catalyst/View/PDF/API2/Simple.pm
   Catalyst-View-PDF-API2-Simple/trunk/lib/Template/
   Catalyst-View-PDF-API2-Simple/trunk/t/
   Catalyst-View-PDF-API2-Simple/trunk/t/00-load.t
   Catalyst-View-PDF-API2-Simple/trunk/t/01-livetest.t
   Catalyst-View-PDF-API2-Simple/trunk/t/lib/
   Catalyst-View-PDF-API2-Simple/trunk/t/lib/TestApp.pm
   Catalyst-View-PDF-API2-Simple/trunk/t/lib/TestApp/
   Catalyst-View-PDF-API2-Simple/trunk/t/lib/TestApp/Controller/
   Catalyst-View-PDF-API2-Simple/trunk/t/lib/TestApp/Controller/Root.pm
   Catalyst-View-PDF-API2-Simple/trunk/t/lib/TestApp/View/
   Catalyst-View-PDF-API2-Simple/trunk/t/lib/TestApp/View/PDF/
   Catalyst-View-PDF-API2-Simple/trunk/t/lib/TestApp/View/PDF/API2/
   Catalyst-View-PDF-API2-Simple/trunk/t/lib/TestApp/View/PDF/API2/Simple.pm
   Catalyst-View-PDF-API2-Simple/trunk/t/lib/TestApp/root/
   Catalyst-View-PDF-API2-Simple/trunk/t/lib/TestApp/root/pdf_templates/
   Catalyst-View-PDF-API2-Simple/trunk/t/lib/TestApp/root/pdf_templates/simple_pdf.tt
   Catalyst-View-PDF-API2-Simple/trunk/t/lib/script/
   Catalyst-View-PDF-API2-Simple/trunk/t/lib/script/testapp_server.pl
   Catalyst-View-PDF-API2-Simple/trunk/t/lib/script/testapp_test.pl
Log:
First commit of this new view.
I've trouble with utf8 printing but I've not a test ready now for it.


Added: Catalyst-View-PDF-API2-Simple/trunk/Changes
===================================================================
--- Catalyst-View-PDF-API2-Simple/trunk/Changes	                        (rev 0)
+++ Catalyst-View-PDF-API2-Simple/trunk/Changes	2009-09-01 09:38:17 UTC (rev 11289)
@@ -0,0 +1,5 @@
+Revision history for Catalyst-View-PDF-API2-Simple
+
+0.01    2009-08-30
+        First version, to be release.
+

Added: Catalyst-View-PDF-API2-Simple/trunk/MANIFEST.pdf
===================================================================

Added: Catalyst-View-PDF-API2-Simple/trunk/Makefile.PL
===================================================================
--- Catalyst-View-PDF-API2-Simple/trunk/Makefile.PL	                        (rev 0)
+++ Catalyst-View-PDF-API2-Simple/trunk/Makefile.PL	2009-09-01 09:38:17 UTC (rev 11289)
@@ -0,0 +1,22 @@
+use strict;
+use warnings;
+use ExtUtils::MakeMaker;
+
+WriteMakefile(
+    NAME                => 'Catalyst::View::PDF::API2::Simple',
+    AUTHOR              => 'Ferruccio Zamuner <nonsolosoft at diff.org>',
+    VERSION_FROM        => 'lib/Catalyst/View/PDF/API2/Simple.pm',
+    ABSTRACT_FROM       => 'lib/Catalyst/View/PDF/API2/Simple.pm',
+    PL_FILES            => {},
+    PREREQ_PM => {
+        'Test::More' => 0,
+        'Catalyst::View::TT' => 0,
+        'PDF::API2::Simple' => 0,
+        'File::chdir' => 0,
+        'Template::Plugin::Procedural' => 0,
+        'Test::File::Contents' => 0,
+        'parent' => 0,
+    },
+    dist                => { COMPRESS => 'gzip -9f', SUFFIX => 'gz', },
+    clean               => { FILES => 'Catalyst-View-PDF-API2-Simple*' },
+);

Added: Catalyst-View-PDF-API2-Simple/trunk/README
===================================================================
--- Catalyst-View-PDF-API2-Simple/trunk/README	                        (rev 0)
+++ Catalyst-View-PDF-API2-Simple/trunk/README	2009-09-01 09:38:17 UTC (rev 11289)
@@ -0,0 +1,37 @@
+NAME
+       Catalyst::View::PDF::API2::Simple - Create PDF files from Catalyst using
+       Template Toolkit templates
+
+VERSION
+       Version 0.01
+
+SYNOPSIS
+
+       Cloned by Catalyst::View::PDF::Reuse
+
+INSTALLATION
+
+To install this module, run the following commands:
+
+	perl Makefile.PL
+	make
+	make test
+	make install
+
+SUPPORT AND DOCUMENTATION
+
+SEE ALSO
+
+Catalyst::View::PDF::API2
+
+and
+
+Catalyst::View::PDF::Reuse
+
+COPYRIGHT AND LICENCE
+
+Copyright (C) 2009 NonSoLoSoft - http://www.nonsolosoft.com/
+
+This program is free software; you can redistribute it and/or modify it
+under the same terms as Perl itself.
+

Added: Catalyst-View-PDF-API2-Simple/trunk/lib/Catalyst/Helper/View/PDF/API2/Simple.pm
===================================================================
--- Catalyst-View-PDF-API2-Simple/trunk/lib/Catalyst/Helper/View/PDF/API2/Simple.pm	                        (rev 0)
+++ Catalyst-View-PDF-API2-Simple/trunk/lib/Catalyst/Helper/View/PDF/API2/Simple.pm	2009-09-01 09:38:17 UTC (rev 11289)
@@ -0,0 +1,88 @@
+package Catalyst::Helper::View::PDF::API2::Simple;
+
+use strict;
+
+=head1 NAME
+
+Catalyst::Helper::View::PDF::API2::Simple - Helper for PDF::API2::Simple Views
+
+=head1 SYNOPSIS
+
+To create a PDF::API2::Simple view in your Catalyst application, enter the following command:
+
+ script/myapp_create.pl view PDF::API2::Simple PDF::API2::Simple
+
+Then in MyApp.pm, add a configuration item for the View::PDF::API2::Simple include path:
+
+ __PACKAGE__->config('View::PDF::API2::Simple' => {
+   INCLUDE_PATH => __PACKAGE__->path_to('root','pdf_templates')
+ });
+
+=head1 DESCRIPTION
+
+Helper for PDF::API2::Simple 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<jj at jonallen.info>
+
+=head1 SEE ALSO
+
+L<Catalyst::View::PDF::API2::Simple>
+
+
+=head1 COPYRIGHT & LICENSE
+
+Copyright 2009 NonSoLoSoft, 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::API2::Simple';
+
+=head1 NAME
+
+[% class %] - PDF::API2::Simple View for [% app %]
+
+=head1 DESCRIPTION
+
+PDF::API2::Simple 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;

Added: Catalyst-View-PDF-API2-Simple/trunk/lib/Catalyst/View/PDF/API2/Simple.pm
===================================================================
--- Catalyst-View-PDF-API2-Simple/trunk/lib/Catalyst/View/PDF/API2/Simple.pm	                        (rev 0)
+++ Catalyst-View-PDF-API2-Simple/trunk/lib/Catalyst/View/PDF/API2/Simple.pm	2009-09-01 09:38:17 UTC (rev 11289)
@@ -0,0 +1,239 @@
+package Catalyst::View::PDF::API2::Simple;
+
+use warnings;
+use strict;
+use parent 'Catalyst::View::TT';
+use File::chdir;
+use File::Spec::Functions qw/catfile/;
+use File::Temp qw/tmpnam/;
+use PDF::API2::Simple;
+
+=head1 NAME
+
+Catalyst::View::PDF::API2::Simple - Create PDF files from Catalyst using Template Toolkit templates
+
+=head1 VERSION
+
+Version 0.01
+
+=cut
+
+our $VERSION = '0.01';
+
+=head1 SYNOPSIS
+
+Create a PDF::API2::Simple view:
+
+ script/myapp_create.pl view PDF PDF::API2::Simple
+
+In MyApp.pm, add a configuration item for the template include path:
+
+ __PACKAGE__->config('View::PDF::API2::Simple' => {
+   INCLUDE_PATH => __PACKAGE__->path_to('root','pdf_templates')
+ });
+
+In your controller:
+
+ $c->stash->{pdf_template} = 'hello_pdf.tt';
+ $c->forward('View::PDF::API2::Simple');
+
+In F<root/pdf_templates/hello_pdf.tt>:
+
+ [% pdf.corefont('Helvetica-Bold') %]
+
+=head1 DESCRIPTION
+
+Catalyst::View::PDF::API2::Simple provides the facility to generate PDF files from
+a Catalyst application by embedding L<PDF::API2::Simple> commands within a Template
+Toolkit template.
+
+=head2 Template Syntax
+
+Within your template you will have access to a C<pdf> object which has
+methods corresponding to all of L<PDF::API2::Simple>'s functions.
+
+For example, to print the text I<Hello, World> at PDF coordinates 100,100,
+use the following directive in your template:
+
+ [% f1 = pdf->corefont('Helvetica') %]
+ [% page = pdf.page %]
+ [% page.mediabox(595,842) %]
+ [% text = page.text %]
+ [% text.textlabel(50,800,$f1,20,'Hello, World',-hspace=>75) %]
+
+
+Data held in the stash can be printed as follows:
+
+ $c->stash->{list} = ['one', 'two', 'three', 'four'];
+
+ [% y = 500 %]
+ [% FOREACH item IN list %]
+   [% page.textlabel(100,y,$f1,20,item) %]  ###### to fix
+   [% y = y - 13 %]
+ [% END %]
+dav
+Formatting can be defined using the Template Toolkit format plugin:
+
+ [% USE format %]
+ [% currency = format('£%.2f') %]
+ [% page.textlabel(100,100,$f1,20,currency(10)) %]
+
+=head2 Using existing PDF documents
+
+The key benefit of L<PDF::API2> 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::API2::Simple
+to add in details such as the order number and customer address.
+
+ [% page.textlabel(123,643,$f1,12,order.number) %]
+ [% page.textlabel(299,643,$f1,12,order.date) %]
+
+Note that the PDF document loaded by C<pdf.prForm> 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::API2::Simple view from your controller:
+
+ $c->forward('View::PDF::API2::Simple');
+
+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<http://localhost/view/order/pdf/1234> the PDF filename would be set to
+F<1234.pdf>.
+
+=cut
+
+sub process {
+    my ($self, $c) = @_;
+    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($self->render_pdf($c));
+}
+
+
+=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<render_pdf> as follows:
+
+ my $pdf = $c->view("PDF::API2::Simple")->render_pdf($c);
+
+=cut
+
+sub render_pdf {
+    my ($self, $c) = @_;
+
+    my $tempfile = tmpnam();
+    #$c->stash->{tempfile} = $tempfile;
+    
+    my $template = <<'EOT';
+    [% USE Dumper %]
+    [% USE pdf2 = Catalyst::View::PDF::API2::Simple %]
+    [% Catalyst.log.debug(Dumper.dump($pdf_template)) %]
+    [% PROCESS $pdf_template %]
+EOT
+
+    $c->stash->{pdf} = PDF::API2::Simple->new('file'=>$tempfile);
+
+    SEARCH: foreach my $path (@{$self->config->{INCLUDE_PATH}}) {
+        if (-e catfile($path,$c->stash->{pdf_template})) {
+            local $CWD = $path;
+            my $output = $self->render($c,\$template);
+	    $DB::single=1;
+	    $c->log->debug("render: $output") if ($self->config->{PDFAPI2_DEBUG});
+            last SEARCH;
+        }
+	$DB::single=1;
+	$c->log->debug("pdf_template non trovato") if ($self->config->{PDFAPI2_DEBUG});
+    }
+
+    my $pdfout = $c->stash->{pdf}->stringify;
+    unlink($tempfile);
+    return $pdfout;
+}
+
+=head1 AUTHOR
+
+Ferruccio Zamuner, L<nonsolosoft at diff.org>
+
+
+=head1 BUGS
+
+Please report any bugs or feature requests to C<bug-catalyst-view-pdf-api2 at rt.cpan.org>, or through
+the web interface at L<http://rt.cpan.org/NoAuth/ReportBug.html?Queue=Catalyst-View-PDF-API2>.  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::API2::Simple
+
+=over 4
+
+=item * RT: CPAN's request tracker
+
+L<http://rt.cpan.org/NoAuth/Bugs.html?Dist=Catalyst-View-PDF-API2::Simple>
+
+=item * AnnoCPAN: Annotated CPAN documentation
+
+L<http://annocpan.org/dist/Catalyst-View-PDF-API2::Simple>
+
+=item * CPAN Ratings
+
+L<http://cpanratings.perl.org/d/Catalyst-View-PDF-API2::Simple>
+
+=item * Search CPAN
+
+L<http://search.cpan.org/dist/Catalyst-View-PDF-API2::Simple>
+
+=back
+
+
+=head1 SEE ALSO
+
+L<PDF::API::Simple|http://search.cpan.org/~redtree/PDF-API2-Simple/lib/PDF/API2/Simple.pm>
+
+NonSoLoSoft - L<http://www.nonsolosoft.com/>
+
+L<Catalyst::View::PDF::Reuse|http://search.cpan.org/~jonallen/Catalyst-View-PDF-Reuse/lib/Catalyst/View/PDF/Reuse.pm>
+
+=ACKNOWLEDGEMENTS
+
+To every Catalyst developer that has written this framework or its manuals and to any CPAN contributors.
+
+=cut
+
+=head1 COPYRIGHT & LICENSE
+
+Copyright (C) 2009 NonSoLoSoft
+
+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::API2::Simple

Added: Catalyst-View-PDF-API2-Simple/trunk/t/00-load.t
===================================================================
--- Catalyst-View-PDF-API2-Simple/trunk/t/00-load.t	                        (rev 0)
+++ Catalyst-View-PDF-API2-Simple/trunk/t/00-load.t	2009-09-01 09:38:17 UTC (rev 11289)
@@ -0,0 +1,6 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use Test::More tests => 1;
+use ok 'Catalyst::View::PDF::API2::Simple';

Added: Catalyst-View-PDF-API2-Simple/trunk/t/01-livetest.t
===================================================================
--- Catalyst-View-PDF-API2-Simple/trunk/t/01-livetest.t	                        (rev 0)
+++ Catalyst-View-PDF-API2-Simple/trunk/t/01-livetest.t	2009-09-01 09:38:17 UTC (rev 11289)
@@ -0,0 +1,19 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+use Test::More tests => 4;
+
+# setup library path
+use FindBin qw($Bin);
+use lib "$Bin/lib";
+
+# make sure testapp works
+use ok 'TestApp';
+
+# a live test against TestApp, the test application
+use Test::WWW::Mechanize::Catalyst 'TestApp';
+my $mech = Test::WWW::Mechanize::Catalyst->new;
+$mech->get_ok('http://localhost/', 'get main page');
+$mech->content_like(qr/it works/i, 'see if it has our text');
+$mech->get_ok('http://localhost/pdf_test/', 'pdf test');

Added: Catalyst-View-PDF-API2-Simple/trunk/t/lib/TestApp/Controller/Root.pm
===================================================================
--- Catalyst-View-PDF-API2-Simple/trunk/t/lib/TestApp/Controller/Root.pm	                        (rev 0)
+++ Catalyst-View-PDF-API2-Simple/trunk/t/lib/TestApp/Controller/Root.pm	2009-09-01 09:38:17 UTC (rev 11289)
@@ -0,0 +1,25 @@
+package TestApp::Controller::Root;
+use strict;
+use warnings;
+
+__PACKAGE__->config(namespace => q{});
+
+use base 'Catalyst::Controller';
+
+use TestApp::View::PDF::API2::Simple;
+
+sub main :Path { $_[1]->res->body('<h1>It works</h1>') }
+
+sub pdf_test : Global {
+  my ($self, $c) = @_;
+
+  $c->stash( {
+    data => "This is a test page",
+    pdf_template=>'simple_pdf.tt',
+    pdf_filename=>'test_pdf.pdf',    
+  } );
+
+  $c->forward('View::PDF::API2::Simple');
+}
+
+1;

Added: Catalyst-View-PDF-API2-Simple/trunk/t/lib/TestApp/View/PDF/API2/Simple.pm
===================================================================
--- Catalyst-View-PDF-API2-Simple/trunk/t/lib/TestApp/View/PDF/API2/Simple.pm	                        (rev 0)
+++ Catalyst-View-PDF-API2-Simple/trunk/t/lib/TestApp/View/PDF/API2/Simple.pm	2009-09-01 09:38:17 UTC (rev 11289)
@@ -0,0 +1,7 @@
+package TestApp::View::PDF::API2::Simple;
+
+use FindBin;
+use lib "$FindBin::Bin/../../../../lib";
+use base 'Catalyst::View::PDF::API2::Simple';
+
+1;

Added: Catalyst-View-PDF-API2-Simple/trunk/t/lib/TestApp/root/pdf_templates/simple_pdf.tt
===================================================================
--- Catalyst-View-PDF-API2-Simple/trunk/t/lib/TestApp/root/pdf_templates/simple_pdf.tt	                        (rev 0)
+++ Catalyst-View-PDF-API2-Simple/trunk/t/lib/TestApp/root/pdf_templates/simple_pdf.tt	2009-09-01 09:38:17 UTC (rev 11289)
@@ -0,0 +1,15 @@
+[%# PDF::API2::Simple %]
+[% rawpdf2 = pdf.pdf # get raw pdf::api2 object %]
+[% rawpdf2.mediabox(421,595) %]
+
+[% pdf.add_font('Helvetica') %]
+[% pdf.add_page() %]
+
+[% pdf.x(50) ; pdf.y(420) %]
+[% pdf.text('Hello, World', 'autoflow','on') %]
+[% pdf.text( 'Please align me left, Please align me left. Please align me left, Please align me left. Please align me left, Please align me left. Please align me left, Please align me left. Please align me left, Please align me left. Please align me left, Please align me left. Please align me left, Please align me left. Please align me left, Please align me left. Please align me left, Please align me left. Please align me left, Please align me left. Please align me left, Please align me left. Please align me left, Please align me left.', 'x', 25, 'y',400, 'align','left', 'autoflow','on') %]
+
+[% pdf.x(50) ; pdf.y(100) %]
+[% pdf.text("Questa è una linea particolarmente lunga, vediamo se va a capo e come, o se non va a capo cerco un'altra primitiva che lo faccia.", 'autoflow','on') %]
+
+

Added: Catalyst-View-PDF-API2-Simple/trunk/t/lib/TestApp.pm
===================================================================
--- Catalyst-View-PDF-API2-Simple/trunk/t/lib/TestApp.pm	                        (rev 0)
+++ Catalyst-View-PDF-API2-Simple/trunk/t/lib/TestApp.pm	2009-09-01 09:38:17 UTC (rev 11289)
@@ -0,0 +1,23 @@
+package TestApp;
+use strict;
+use warnings;
+
+use Catalyst;
+
+$DB::single=1;
+
+__PACKAGE__->config(
+   'View::PDF::API2::Simple' => 
+		    {
+		     INCLUDE_PATH => __PACKAGE__->path_to('root','pdf_templates'),
+		     COMPILE_EXT  => 'c',
+		     TEMPLATE_EXTENSION => '.tt',
+		     CATALYST_VAR => 'Catalyst',  
+		    }
+);
+
+
+
+__PACKAGE__->setup;
+
+1;

Added: Catalyst-View-PDF-API2-Simple/trunk/t/lib/script/testapp_server.pl
===================================================================
--- Catalyst-View-PDF-API2-Simple/trunk/t/lib/script/testapp_server.pl	                        (rev 0)
+++ Catalyst-View-PDF-API2-Simple/trunk/t/lib/script/testapp_server.pl	2009-09-01 09:38:17 UTC (rev 11289)
@@ -0,0 +1,160 @@
+#!/usr/bin/env perl
+
+BEGIN {
+    $ENV{CATALYST_ENGINE} ||= 'HTTP';
+    $ENV{CATALYST_SCRIPT_GEN} = 39;
+    require Catalyst::Engine::HTTP;
+}
+
+use strict;
+use warnings;
+use Getopt::Long;
+use Pod::Usage;
+use FindBin;
+use lib "$FindBin::Bin/../";
+
+my $debug             = 0;
+my $fork              = 0;
+my $help              = 0;
+my $host              = undef;
+my $port              = $ENV{TESTAPP_PORT} || $ENV{CATALYST_PORT} || 3000;
+my $keepalive         = 0;
+my $restart           = $ENV{TESTAPP_RELOAD} || $ENV{CATALYST_RELOAD} || 0;
+my $background        = 0;
+my $pidfile           = undef;
+
+my $check_interval;
+my $file_regex;
+my $watch_directory;
+my $follow_symlinks;
+
+my @argv = @ARGV;
+
+GetOptions(
+    'debug|d'             => \$debug,
+    'fork|f'              => \$fork,
+    'help|?'              => \$help,
+    'host=s'              => \$host,
+    'port|p=s'            => \$port,
+    'keepalive|k'         => \$keepalive,
+    'restart|r'           => \$restart,
+    'restartdelay|rd=s'   => \$check_interval,
+    'restartregex|rr=s'   => \$file_regex,
+    'restartdirectory=s@' => \$watch_directory,
+    'followsymlinks'      => \$follow_symlinks,
+    'background'          => \$background,
+    'pidfile=s'           => \$pidfile,
+);
+
+pod2usage(1) if $help;
+
+if ( $debug ) {
+    $ENV{CATALYST_DEBUG} = 1;
+}
+
+# If we load this here, then in the case of a restarter, it does not
+# need to be reloaded for each restart.
+require Catalyst;
+
+# If this isn't done, then the Catalyst::Devel tests for the restarter
+# fail.
+$| = 1 if $ENV{HARNESS_ACTIVE};
+
+my $runner = sub {
+    # This is require instead of use so that the above environment
+    # variables can be set at runtime.
+    require TestApp;
+
+    TestApp->run(
+        $port, $host,
+        {
+            argv       => \@argv,
+            'fork'     => $fork,
+            keepalive  => $keepalive,
+            background => $background,
+            pidfile    => $pidfile,
+        }
+    );
+};
+
+if ( $restart ) {
+    die "Cannot run in the background and also watch for changed files.\n"
+        if $background;
+
+    require Catalyst::Restarter;
+
+    my $subclass = Catalyst::Restarter->pick_subclass;
+
+    my %args;
+    $args{follow_symlinks} = 1
+        if $follow_symlinks;
+    $args{directories} = $watch_directory
+        if defined $watch_directory;
+    $args{sleep_interval} = $check_interval
+        if defined $check_interval;
+    $args{filter} = qr/$file_regex/
+        if defined $file_regex;
+
+    my $restarter = $subclass->new(
+        %args,
+        start_sub => $runner,
+        argv      => \@argv,
+    );
+
+    $restarter->run_and_watch;
+}
+else {
+    $runner->();
+}
+
+1;
+
+=head1 NAME
+
+testapp_server.pl - Catalyst Testserver
+
+=head1 SYNOPSIS
+
+testapp_server.pl [options]
+
+ Options:
+   -d -debug          force debug mode
+   -f -fork           handle each request in a new process
+                      (defaults to false)
+   -? -help           display this help and exits
+      -host           host (defaults to all)
+   -p -port           port (defaults to 3000)
+   -k -keepalive      enable keep-alive connections
+   -r -restart        restart when files get modified
+                      (defaults to false)
+   -rd -restartdelay  delay between file checks
+                      (ignored if you have Linux::Inotify2 installed)
+   -rr -restartregex  regex match files that trigger
+                      a restart when modified
+                      (defaults to '\.yml$|\.yaml$|\.conf|\.pm$')
+   -restartdirectory  the directory to search for
+                      modified files, can be set mulitple times
+                      (defaults to '[SCRIPT_DIR]/..')
+   -follow_symlinks   follow symlinks in search directories
+                      (defaults to false. this is a no-op on Win32)
+   -background        run the process in the background
+   -pidfile           specify filename for pid file
+
+ See also:
+   perldoc Catalyst::Manual
+   perldoc Catalyst::Manual::Intro
+
+=head1 DESCRIPTION
+
+Run a Catalyst Testserver for this application.
+
+=head1 AUTHORS
+
+Catalyst Contributors, see Catalyst.pm
+
+=head1 COPYRIGHT
+
+This library is free software. You can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut


Property changes on: Catalyst-View-PDF-API2-Simple/trunk/t/lib/script/testapp_server.pl
___________________________________________________________________
Name: svn:executable
   + *

Added: Catalyst-View-PDF-API2-Simple/trunk/t/lib/script/testapp_test.pl
===================================================================
--- Catalyst-View-PDF-API2-Simple/trunk/t/lib/script/testapp_test.pl	                        (rev 0)
+++ Catalyst-View-PDF-API2-Simple/trunk/t/lib/script/testapp_test.pl	2009-09-01 09:38:17 UTC (rev 11289)
@@ -0,0 +1,12 @@
+#!/usr/bin/env perl
+
+use strict;
+use warnings;
+
+use FindBin;
+use lib "$FindBin::Bin/..";
+use Catalyst::Test 'TestApp';
+
+print request($ARGV[0])->content . "\n";
+
+1;




More information about the Catalyst-commits mailing list