Fixed typo
[catagits/Catalyst-Runtime.git] / lib / Catalyst / PAR.pm
1 package Catalyst::PAR;
2
3 use strict;
4 use base 'Class::Accessor::Fast';
5 use FindBin;
6 use IO::File;
7 use File::Spec;
8 use File::Find;
9 require Catalyst;
10
11 =head1 NAME
12
13 Catalyst::PAR - Package Catalyst Applications
14
15 =head1 SYNOPSIS
16
17 See L<Catalyst>
18
19 =head1 DESCRIPTION
20
21 Package Catalyst Applications.
22
23 =head1 METHODS
24
25 =over 4
26
27 =item $self->package( $par, $engine )
28
29 =cut
30
31 sub 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
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             push @files, $name;
58         },
59         '.'
60     );
61
62     my $par_test = File::Spec->catfile( $FindBin::Bin, '..', 'par_test.pl' );
63     unlink $par_test;
64
65     my $class    = $options->{class};
66     my $tmp_file = IO::File->new("> $par_test");
67     print $tmp_file <<"EOF";
68 BEGIN { \$ENV{CATALYST_ENGINE} = '$engine' };
69 use FindBin;
70 use lib 'lib';
71 use $class;
72 EOF
73     $tmp_file->close;
74
75     # Create package
76     my %opt = ( 'x' => 1, 'n' => 0, 'o' => $par, 'a' => [@files] );
77     App::Packer::PAR->new(
78         frontend  => 'Module::ScanDeps',
79         backend   => 'PAR::Packer',
80         frontopts => \%opt,
81         backopts  => \%opt,
82         args      => ['par_test.pl'],
83     )->go;
84
85     unlink $par_test;
86 }
87
88 =back
89
90 =head1 AUTHOR
91
92 Sebastian Riedel, C<sri@oook.de>
93
94 =head1 LICENSE
95
96 This library is free software, you can redistribute it and/or modify it under
97 the same terms as Perl itself.
98
99 =cut
100
101 1;