Updated PAR support
[catagits/Catalyst-Runtime.git] / lib / Catalyst / PAR.pm
CommitLineData
fc04b845 1package Catalyst::PAR;
2
3use strict;
4use base 'Class::Accessor::Fast';
5use FindBin;
6use IO::File;
7use File::Spec;
5f9455c6 8use File::Find;
b51339a0 9require Catalyst;
fc04b845 10
11=head1 NAME
12
13Catalyst::PAR - Package Catalyst Applications
14
15=head1 SYNOPSIS
16
17See L<Catalyst>
18
19=head1 DESCRIPTION
20
21Package Catalyst Applications.
22
23=head1 METHODS
24
25=over 4
26
27=item $self->package( $par, $engine )
28
29=cut
30
31sub package {
32 my ( $self, $options ) = @_;
33
34 my $par = $options->{par} || 'application.par';
35 my $engine = $options->{engine} || 'CGI';
36
37 # Check for PAR
38 eval "use PAR ()";
39 die "Please install PAR" if $@;
40 eval "use PAR::Packer ()";
41 die "Please install PAR::Packer" if $@;
42 eval "use App::Packer::PAR ()";
43 die "Please install App::Packer::PAR" if $@;
44 eval "use Module::ScanDeps ()";
45 die "Please install Module::ScanDeps" if $@;
46
5f9455c6 47 chdir File::Spec->catdir( $FindBin::Bin, '..' );
48
49 # Find additional files
50 my @files;
51 finddepth(
52 sub {
53 my $name = $File::Find::name;
54 return if $name =~ /^\W*lib/;
4bb9a245 55 return if $name =~ /^\W*blib/;
56 return if $name =~ /^\W*_build/;
5f9455c6 57 return if $name =~ /\.par$/;
58 return if $name !~ /\w+/;
5f9455c6 59 push @files, $name;
60 },
61 '.'
62 );
63
fc04b845 64 my $par_test = File::Spec->catfile( $FindBin::Bin, '..', 'par_test.pl' );
65 unlink $par_test;
66
b51339a0 67 my $version = $Catalyst::VERSION;
fc04b845 68 my $class = $options->{class};
69 my $tmp_file = IO::File->new("> $par_test");
70 print $tmp_file <<"EOF";
b51339a0 71die "$class on Catalyst $version\n" if \$0 !~ /par_test.pl\.\\w+\$/;
fc04b845 72BEGIN { \$ENV{CATALYST_ENGINE} = '$engine' };
fc04b845 73use lib 'lib';
b51339a0 74require $class;
75import $class;
fc04b845 76EOF
77 $tmp_file->close;
78
5f9455c6 79 # Create package
94a6e0e4 80 local $SIG{__WARN__} = sub { };
81 open my $olderr, '>&STDERR';
82 open STDERR, '>', File::Spec->devnull;
b51339a0 83 my %opt = ( 'x' => 1, 'n' => 0, 'o' => $par, 'a' => [@files], 'B' => 1 );
fc04b845 84 App::Packer::PAR->new(
85 frontend => 'Module::ScanDeps',
86 backend => 'PAR::Packer',
87 frontopts => \%opt,
88 backopts => \%opt,
5f9455c6 89 args => ['par_test.pl'],
fc04b845 90 )->go;
94a6e0e4 91 open STDERR, '>&', $olderr;
fc04b845 92
93 unlink $par_test;
fc04b845 94}
95
96=back
97
98=head1 AUTHOR
99
100Sebastian Riedel, C<sri@oook.de>
101
102=head1 LICENSE
103
104This library is free software, you can redistribute it and/or modify it under
105the same terms as Perl itself.
106
107=cut
108
1091;