Reformatted documentation
[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
b5ecfcf0 25=head2 $self->package(\%options)
fc04b845 26
27=cut
28
29sub package {
30 my ( $self, $options ) = @_;
31
34a83d89 32 my $par = $options->{output} || 'application.par';
fc04b845 33 my $engine = $options->{engine} || 'CGI';
34
35 # Check for PAR
36 eval "use PAR ()";
37 die "Please install PAR" if $@;
38 eval "use PAR::Packer ()";
39 die "Please install PAR::Packer" if $@;
40 eval "use App::Packer::PAR ()";
41 die "Please install App::Packer::PAR" if $@;
42 eval "use Module::ScanDeps ()";
43 die "Please install Module::ScanDeps" if $@;
44
5f9455c6 45 chdir File::Spec->catdir( $FindBin::Bin, '..' );
46
47 # Find additional files
48 my @files;
49 finddepth(
50 sub {
51 my $name = $File::Find::name;
52 return if $name =~ /^\W*lib/;
4bb9a245 53 return if $name =~ /^\W*blib/;
54 return if $name =~ /^\W*_build/;
5f9455c6 55 return if $name =~ /\.par$/;
56 return if $name !~ /\w+/;
5f9455c6 57 push @files, $name;
58 },
59 '.'
60 );
61
fc04b845 62 my $par_test = File::Spec->catfile( $FindBin::Bin, '..', 'par_test.pl' );
63 unlink $par_test;
64
c5e57c7a 65 my $classes = '';
66 for my $req ( split ',', $options->{classes} ) {
67 $classes .= "require $req;\n";
68 }
b51339a0 69 my $version = $Catalyst::VERSION;
fc04b845 70 my $class = $options->{class};
71 my $tmp_file = IO::File->new("> $par_test");
72 print $tmp_file <<"EOF";
b51339a0 73die "$class on Catalyst $version\n" if \$0 !~ /par_test.pl\.\\w+\$/;
fc04b845 74BEGIN { \$ENV{CATALYST_ENGINE} = '$engine' };
fc04b845 75use lib 'lib';
b51339a0 76require $class;
77import $class;
c5e57c7a 78$classes
fc04b845 79EOF
80 $tmp_file->close;
81
5f9455c6 82 # Create package
94a6e0e4 83 local $SIG{__WARN__} = sub { };
84 open my $olderr, '>&STDERR';
85 open STDERR, '>', File::Spec->devnull;
e57eb11d 86 my %opt = (
87 'x' => 1,
88 'n' => 0,
89 'o' => $par,
90 'a' => [@files],
91 'p' => 1,
8079852c 92 'B' => $options->{core},
93 'm' => $options->{multiarch}
e57eb11d 94 );
fc04b845 95 App::Packer::PAR->new(
96 frontend => 'Module::ScanDeps',
97 backend => 'PAR::Packer',
98 frontopts => \%opt,
99 backopts => \%opt,
5f9455c6 100 args => ['par_test.pl'],
fc04b845 101 )->go;
94a6e0e4 102 open STDERR, '>&', $olderr;
fc04b845 103
104 unlink $par_test;
fc04b845 105}
106
fc04b845 107=head1 AUTHOR
108
109Sebastian Riedel, C<sri@oook.de>
110
111=head1 LICENSE
112
113This library is free software, you can redistribute it and/or modify it under
114the same terms as Perl itself.
115
116=cut
117
1181;