Updated Catalyst::PAR to ignore duplicate files
[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 9require Catalyst;
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/;
55 return if $name =~ /\.par$/;
56 return if $name !~ /\w+/;
57 warn "$name\n";
58 push @files, $name;
59 },
60 '.'
61 );
62
fc04b845 63 my $par_test = File::Spec->catfile( $FindBin::Bin, '..', 'par_test.pl' );
64 unlink $par_test;
65
66 my $class = $options->{class};
67 my $tmp_file = IO::File->new("> $par_test");
68 print $tmp_file <<"EOF";
69BEGIN { \$ENV{CATALYST_ENGINE} = '$engine' };
70use FindBin;
71use lib 'lib';
72use $class;
73EOF
74 $tmp_file->close;
75
5f9455c6 76 # Create package
77 my %opt = ( 'x' => 1, 'n' => 0, 'o' => $par, 'a' => [@files] );
fc04b845 78 App::Packer::PAR->new(
79 frontend => 'Module::ScanDeps',
80 backend => 'PAR::Packer',
81 frontopts => \%opt,
82 backopts => \%opt,
5f9455c6 83 args => ['par_test.pl'],
fc04b845 84 )->go;
85
86 unlink $par_test;
fc04b845 87}
88
89=back
90
91=head1 AUTHOR
92
93Sebastian Riedel, C<sri@oook.de>
94
95=head1 LICENSE
96
97This library is free software, you can redistribute it and/or modify it under
98the same terms as Perl itself.
99
100=cut
101
1021;