X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst%2FPAR.pm;h=6d7164b2572c683e6ae8693415505577b2c66768;hp=d634b0793244575874dde50372c3cd81efa2c128;hb=b5ecfcf07b8ffe7e9984f0279c8781ce51c6ac6a;hpb=fc04b84548e23bf35da1e6bd39fd06c327a496dd diff --git a/lib/Catalyst/PAR.pm b/lib/Catalyst/PAR.pm index d634b07..6d7164b 100644 --- a/lib/Catalyst/PAR.pm +++ b/lib/Catalyst/PAR.pm @@ -5,6 +5,7 @@ use base 'Class::Accessor::Fast'; use FindBin; use IO::File; use File::Spec; +use File::Find; require Catalyst; =head1 NAME @@ -21,16 +22,14 @@ Package Catalyst Applications. =head1 METHODS -=over 4 - -=item $self->package( $par, $engine ) +=head2 $self->package(\%options) =cut sub package { my ( $self, $options ) = @_; - my $par = $options->{par} || 'application.par'; + my $par = $options->{output} || 'application.par'; my $engine = $options->{engine} || 'CGI'; # Check for PAR @@ -43,45 +42,68 @@ sub package { eval "use Module::ScanDeps ()"; die "Please install Module::ScanDeps" if $@; + chdir File::Spec->catdir( $FindBin::Bin, '..' ); + + # Find additional files + my @files; + finddepth( + sub { + my $name = $File::Find::name; + return if $name =~ /^\W*lib/; + return if $name =~ /^\W*blib/; + return if $name =~ /^\W*_build/; + return if $name =~ /\.par$/; + return if $name !~ /\w+/; + push @files, $name; + }, + '.' + ); + my $par_test = File::Spec->catfile( $FindBin::Bin, '..', 'par_test.pl' ); unlink $par_test; + my $classes = ''; + for my $req ( split ',', $options->{classes} ) { + $classes .= "require $req;\n"; + } + my $version = $Catalyst::VERSION; my $class = $options->{class}; my $tmp_file = IO::File->new("> $par_test"); print $tmp_file <<"EOF"; +die "$class on Catalyst $version\n" if \$0 !~ /par_test.pl\.\\w+\$/; BEGIN { \$ENV{CATALYST_ENGINE} = '$engine' }; -use FindBin; use lib 'lib'; -use $class; +require $class; +import $class; +$classes EOF $tmp_file->close; -# my $main = File::Spec->catfile( $FindBin::Bin, 'main.pl' ); -# unlink $main; - -# my $version = $Catalyst::VERSION; -# my $main_file = IO::File->new("> $main"); -# print $main_file <<"EOF"; -#print "$class on Catalyst $version.\\n"; -#EOF -# $main_file->close; - - chdir File::Spec->catdir( $FindBin::Bin, '..' ); - my %opt = ( 'x' => 1, 'n' => 0, 'o' => $par, 'a' => ['.'] ); + # Create package + local $SIG{__WARN__} = sub { }; + open my $olderr, '>&STDERR'; + open STDERR, '>', File::Spec->devnull; + my %opt = ( + 'x' => 1, + 'n' => 0, + 'o' => $par, + 'a' => [@files], + 'p' => 1, + 'B' => $options->{core}, + 'm' => $options->{multiarch} + ); App::Packer::PAR->new( frontend => 'Module::ScanDeps', backend => 'PAR::Packer', frontopts => \%opt, backopts => \%opt, - args => [ 'par_test.pl' ], + args => ['par_test.pl'], )->go; + open STDERR, '>&', $olderr; unlink $par_test; -# unlink $main; } -=back - =head1 AUTHOR Sebastian Riedel, C