From: Jonathan Rockway Date: Mon, 13 Apr 2009 07:18:16 +0000 (-0500) Subject: add experimental PAR plugin! X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=b005539a949fed11cd58ccc868416370fc5da94c;p=gitmo%2FMooseX-Runnable.git add experimental PAR plugin! --- diff --git a/lib/MooseX/Runnable/Invocation/Plugin/PAR.pm b/lib/MooseX/Runnable/Invocation/Plugin/PAR.pm new file mode 100644 index 0000000..e6139b1 --- /dev/null +++ b/lib/MooseX/Runnable/Invocation/Plugin/PAR.pm @@ -0,0 +1,69 @@ +package MooseX::Runnable::Invocation::Plugin::PAR; +use Moose::Role; + +use Module::ScanDeps (); +use App::Packer::PAR (); +use MooseX::Runnable::Run; + +use File::Temp qw(tempfile); + +my $mk_scanner = sub { + my $class = Moose::Meta::Class->create_anon_class( superclasses => ['Moose::Object'] ); + + for my $m (qw/set_file set_options calculate_info + go scan_deps add_deps _find_in_inc/){ + $class->add_method( $m => sub { warn "$m @_" } ); + } + $class->add_method( get_files => sub { warn 'get_files'; [ keys %INC ] } ); + my $name = $class->name; + $name =~ s{::}{/}g; + $INC{ "$name.pm" } = 1; + return $class; +}; + +around run => sub { + my ($next, $self, @args) = @_; + print "Creating a PAR instead of runing the app.\n"; + + { # pre-load as much as possible + my $class = $self->load_class; + $self->apply_scheme($class); + eval { + # this is probably not possible, but we might as well try + $self->validate_class($class); + }; + } + + my $inc = join " ", + map { "require '$_';\n" } + keys %INC; + my $plugins = join ', ', map { "'$_'" } grep { $_ ne 'PAR' } @{$self->plugins}; + my $app = $self->class; + my $script = <<"END"; +use MooseX::Runnable::Run; +use MooseX::Runnable::Invocation; +require Params::Validate; # XXX! +$inc +exit MooseX::Runnable::Invocation->new( + class => '$app', + plugins => [$plugins], +)->run(@ARGV); +END + + $app =~ s/::/_/g; + $app = lc $app; + + my $opt = { e => $script, o => $app, vvv => 1 }; + + App::Packer::PAR->new( + frontend => 'Module::ScanDeps', + backend => 'PAR::Packer', + frontopts => $opt, + backopts => $opt, + args => [], + )->go; + + return 0; +}; + +1;