Added PAR support
Sebastian Riedel [Thu, 17 Nov 2005 01:11:09 +0000 (01:11 +0000)]
Build.PL
Changes
lib/Catalyst.pm
lib/Catalyst/Helper.pm
lib/Catalyst/PAR.pm [new file with mode: 0644]

index 3926b92..10ec7e8 100644 (file)
--- a/Build.PL
+++ b/Build.PL
@@ -36,7 +36,8 @@ my $build = Module::Build->new(
     recommends => {
         'Catalyst::Engine::Apache' => '1.00',
         FCGI                       => 0,
-        'FCGI::ProcManager'        => 0
+        'FCGI::ProcManager'        => 0,
+        PAR                        => 0
     },
     create_makefile_pl => 'passthrough',
     create_readme      => 1,
@@ -79,6 +80,8 @@ else {
 qq/ Install "FCGI::ProcManager" for multiprocess FastCGI external support.\n/
       if ($@);
 }
+eval "use PAR ()";
+print qq/ Install "PAR" for PAR packaging support.\n/ if $@;
 
 print <<"EOF";
 
diff --git a/Changes b/Changes
index 3fb7723..54eb30a 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,8 @@
 This file documents the revision history for Perl extension Catalyst.
 
+5.57
+        - Added PAR support
+
 5.56   2005-11-16 10:33:00
         - Fixed FastCGI engine to not clobber the global %ENV on each
           request. (Sam Vilain)
index 1075c43..3de67b5 100644 (file)
@@ -43,7 +43,7 @@ our $DETACH    = "catalyst_detach\n";
 require Module::Pluggable::Fast;
 
 # Helper script generation
-our $CATALYST_SCRIPT_GEN = 12;
+our $CATALYST_SCRIPT_GEN = 13;
 
 __PACKAGE__->mk_classdata($_)
   for qw/components arguments dispatcher engine log dispatcher_class
@@ -54,7 +54,7 @@ __PACKAGE__->engine_class('Catalyst::Engine::CGI');
 __PACKAGE__->request_class('Catalyst::Request');
 __PACKAGE__->response_class('Catalyst::Response');
 
-our $VERSION = '5.56';
+our $VERSION = '5.57';
 
 sub import {
     my ( $class, @arguments ) = @_;
index 56c73d1..867d527 100644 (file)
@@ -80,6 +80,7 @@ sub mk_app {
         $self->_mk_apptest;
         $self->_mk_images;
         $self->_mk_favicon;
+        $self->_mk_package;
     }
     $self->_mk_cgi;
     $self->_mk_fastcgi;
@@ -441,6 +442,14 @@ sub _mk_favicon {
 
 }
 
+sub _mk_package {
+    my $self      = shift;
+    my $script    = $self->{script};
+    my $appprefix = $self->{appprefix};
+    $self->render_file( 'package', "$script\/$appprefix\_package.pl" );
+    chmod 0700, "$script/$appprefix\_package.pl";
+}
+
 =head1 HELPERS
 
 Helpers are classes that provide two methods.
@@ -963,7 +972,65 @@ This behavior can be suppressed with the C<-nonew> option.
 
 =head1 AUTHOR
 
-Sebastian Riedel, C<sri\@oook.de>
+Sebastian Riedel, C<sri@oook.de>
+
+=head1 COPYRIGHT
+
+Copyright 2004 Sebastian Riedel. All rights reserved.
+
+This library is free software, you can redistribute it and/or modify
+it under the same terms as Perl itself.
+
+=cut
+__package__
+[% startperl %] -w
+
+use strict;
+use Getopt::Long;
+use Pod::Usage;
+use Catalyst::PAR;
+
+my $help = 0;
+
+GetOptions( 'help|?' => \$help );
+
+pod2usage(1) if $help;
+
+my $par = Catalyst::PAR->new->package( {
+    par    => $ARGV[0] || '[% appprefix %].par',
+    engine => $ARGV[1],
+    class  => '[% name %]'
+} );
+
+1;
+
+=head1 NAME
+
+[% appprefix %]_package.pl - Package a Catalyst application
+
+=head1 SYNOPSIS
+
+[% appprefix %]_package.pl [par] [engine]
+
+ Options:
+   -help     display this help and exits
+
+ Examples:
+   [% appprefix %]_package.pl [% appprefix %].par FastCGI
+   [% appprefix %]_package.pl foo_linux_i386_apache2.par Apache2
+
+ See also:
+   perldoc Catalyst::Manual
+   perldoc Catalyst::Manual::Intro
+   perldoc pp
+
+=head1 DESCRIPTION
+
+Package a Catalyst application with L<PAR>.
+
+=head1 AUTHOR
+
+Sebastian Riedel, C<sri@oook.de>
 
 =head1 COPYRIGHT
 
diff --git a/lib/Catalyst/PAR.pm b/lib/Catalyst/PAR.pm
new file mode 100644 (file)
index 0000000..d634b07
--- /dev/null
@@ -0,0 +1,96 @@
+package Catalyst::PAR;
+
+use strict;
+use base 'Class::Accessor::Fast';
+use FindBin;
+use IO::File;
+use File::Spec;
+require Catalyst;
+
+=head1 NAME
+
+Catalyst::PAR - Package Catalyst Applications
+
+=head1 SYNOPSIS
+
+See L<Catalyst>
+
+=head1 DESCRIPTION
+
+Package Catalyst Applications.
+
+=head1 METHODS
+
+=over 4
+
+=item $self->package( $par, $engine )
+
+=cut
+
+sub package {
+    my ( $self, $options ) = @_;
+
+    my $par    = $options->{par}    || 'application.par';
+    my $engine = $options->{engine} || 'CGI';
+
+    # Check for PAR
+    eval "use PAR ()";
+    die "Please install PAR" if $@;
+    eval "use PAR::Packer ()";
+    die "Please install PAR::Packer" if $@;
+    eval "use App::Packer::PAR ()";
+    die "Please install App::Packer::PAR" if $@;
+    eval "use Module::ScanDeps ()";
+    die "Please install Module::ScanDeps" if $@;
+
+    my $par_test = File::Spec->catfile( $FindBin::Bin, '..', 'par_test.pl' );
+    unlink $par_test;
+
+    my $class    = $options->{class};
+    my $tmp_file = IO::File->new("> $par_test");
+    print $tmp_file <<"EOF";
+BEGIN { \$ENV{CATALYST_ENGINE} = '$engine' };
+use FindBin;
+use lib 'lib';
+use $class;
+EOF
+    $tmp_file->close;
+
+#    my $main = File::Spec->catfile( $FindBin::Bin, 'main.pl' );
+#    unlink $main;
+
+#    my $version   = $Catalyst::VERSION;
+#    my $main_file = IO::File->new("> $main");
+#    print $main_file <<"EOF";
+#print "$class on Catalyst $version.\\n";
+#EOF
+#    $main_file->close;
+
+    chdir File::Spec->catdir( $FindBin::Bin, '..' );
+    my %opt = ( 'x' => 1, 'n' => 0, 'o' => $par, 'a' => ['.'] );
+    App::Packer::PAR->new(
+        frontend  => 'Module::ScanDeps',
+        backend   => 'PAR::Packer',
+        frontopts => \%opt,
+        backopts  => \%opt,
+        args => [ 'par_test.pl' ],
+    )->go;
+
+    unlink $par_test;
+#    unlink $main;
+}
+
+=back
+
+=head1 AUTHOR
+
+Sebastian Riedel, C<sri@oook.de>
+
+=head1 LICENSE
+
+This library is free software, you can redistribute it and/or modify it under
+the same terms as Perl itself.
+
+=cut
+
+1;