make PAR work with new plugin scheme
[gitmo/MooseX-Runnable.git] / lib / MooseX / Runnable / Invocation / Plugin / PAR.pm
CommitLineData
b005539a 1package MooseX::Runnable::Invocation::Plugin::PAR;
2use Moose::Role;
3
4use Module::ScanDeps ();
5use App::Packer::PAR ();
6use MooseX::Runnable::Run;
7
dcfde64f 8use Data::Dump::Streamer;
9
b005539a 10use File::Temp qw(tempfile);
11
12my $mk_scanner = sub {
13 my $class = Moose::Meta::Class->create_anon_class( superclasses => ['Moose::Object'] );
14
15 for my $m (qw/set_file set_options calculate_info
16 go scan_deps add_deps _find_in_inc/){
17 $class->add_method( $m => sub { warn "$m @_" } );
18 }
19 $class->add_method( get_files => sub { warn 'get_files'; [ keys %INC ] } );
20 my $name = $class->name;
21 $name =~ s{::}{/}g;
22 $INC{ "$name.pm" } = 1;
23 return $class;
24};
25
26around run => sub {
27 my ($next, $self, @args) = @_;
28 print "Creating a PAR instead of runing the app.\n";
29
30 { # pre-load as much as possible
31 my $class = $self->load_class;
32 $self->apply_scheme($class);
33 eval {
34 # this is probably not possible, but we might as well try
35 $self->validate_class($class);
36 };
37 }
38
39 my $inc = join " ",
40 map { "require '$_';\n" }
41 keys %INC;
dcfde64f 42 my %plugins = %{ $self->plugins };
43 delete $plugins{PAR};
44 my $plugins = Dump(\%plugins)->Out;
45
b005539a 46 my $app = $self->class;
47 my $script = <<"END";
48use MooseX::Runnable::Run;
49use MooseX::Runnable::Invocation;
50require Params::Validate; # XXX!
51$inc
dcfde64f 52$plugins
b005539a 53exit MooseX::Runnable::Invocation->new(
54 class => '$app',
dcfde64f 55 plugins => \$HASH1,
7b33437c 56)->run(\@ARGV);
b005539a 57END
58
dcfde64f 59 print "script: \n$script";
60
b005539a 61 $app =~ s/::/_/g;
62 $app = lc $app;
63
64 my $opt = { e => $script, o => $app, vvv => 1 };
65
66 App::Packer::PAR->new(
67 frontend => 'Module::ScanDeps',
68 backend => 'PAR::Packer',
69 frontopts => $opt,
70 backopts => $opt,
71 args => [],
72 )->go;
73
74 return 0;
75};
76
771;