add prototype Profile plugin
Jonathan Rockway [Thu, 25 Jun 2009 21:42:08 +0000 (14:42 -0700)]
lib/MooseX/Runnable/Invocation/Plugin/Profile.pm [new file with mode: 0644]

diff --git a/lib/MooseX/Runnable/Invocation/Plugin/Profile.pm b/lib/MooseX/Runnable/Invocation/Plugin/Profile.pm
new file mode 100644 (file)
index 0000000..28a4cc1
--- /dev/null
@@ -0,0 +1,21 @@
+package MooseX::Runnable::Invocation::Plugin::Profile;
+use Moose::Role;
+
+before 'load_class' => sub {
+    my ($self) = @_;
+    confess 'The Profile plugin cannot be used when not invoked via mx-urn'
+      unless $self->does('MooseX::Runnable::Invocation::Role::WithParsedArgs');
+
+    my @cmdline = $self->parsed_args->guess_cmdline(
+        perl_flags      => ['-d:NYTProf'],
+        without_plugins => ['Profile', '+'.__PACKAGE__],
+    );
+
+    eval { $self->_debug_message(
+        "Re-execing with ". join ' ' , @cmdline,
+    )};
+
+    exec(@cmdline);
+};
+
+1;