From: Jonathan Rockway Date: Wed, 29 Apr 2009 15:35:51 +0000 (-0500) Subject: make Debug plugin accept an argument (as an example) X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0c9cfd21242271c1dcb11c4349819ceeb4a99650;p=gitmo%2FMooseX-Runnable.git make Debug plugin accept an argument (as an example) --- diff --git a/lib/MooseX/Runnable/Invocation/Plugin/Debug.pm b/lib/MooseX/Runnable/Invocation/Plugin/Debug.pm index 94e0397..00db16a 100644 --- a/lib/MooseX/Runnable/Invocation/Plugin/Debug.pm +++ b/lib/MooseX/Runnable/Invocation/Plugin/Debug.pm @@ -1,6 +1,27 @@ package MooseX::Runnable::Invocation::Plugin::Debug; use Moose::Role; +# this is an example to cargo-cult, rather than a useful feature :) +has 'debug_prefix' => ( + is => 'ro', + isa => 'Str', + required => 1, + default => sub { "" }, +); + +sub _build_initargs_from_cmdline { + my ($class, @args) = @_; + confess 'Bad args passed to Debug plugin' + unless @args % 2 == 0; + + my %args = @args; + + if(my $p = $args{'--prefix'}){ + return { debug_prefix => $p }; + } + return; +} + for my $method (qw{ load_class apply_scheme validate_class create_instance start_application @@ -10,11 +31,12 @@ for my $method (qw{ before $method => sub { my ($self, @args) = @_; my $args = join ', ', @args; - print "Calling $method($args)\n"; + print $self->debug_prefix, "Calling $method($args)\n"; }; after $method => sub { - print "Returning from $method\n"; + my $self = shift; + print $self->debug_prefix, "Returning from $method\n"; }; }