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