Reformatted documentation
[catagits/Catalyst-Runtime.git] / lib / Catalyst / PAR.pm
index d634b07..6d7164b 100644 (file)
@@ -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<sri@oook.de>