doc fixes; 0.01 release
[gitmo/MooseX-Runnable.git] / lib / MooseX / Runnable / Invocation / Plugin / Debug.pm
1 package MooseX::Runnable::Invocation::Plugin::Debug;
2 use Moose::Role;
3
4 with 'MooseX::Runnable::Invocation::Plugin::Role::CmdlineArgs';
5
6 # this is an example to cargo-cult, rather than a useful feature :)
7 has 'debug_prefix' => (
8     is       => 'ro',
9     isa      => 'Str',
10     required => 1,
11     default  => sub { "" },
12 );
13
14 sub _build_initargs_from_cmdline {
15     my ($class, @args) = @_;
16     confess 'Bad args passed to Debug plugin'
17       unless @args % 2 == 0;
18
19     my %args = @args;
20
21     if(my $p = $args{'--prefix'}){
22         return { debug_prefix => $p };
23     }
24     return;
25 }
26
27 sub _debug_message {
28     my ($self, @msg) = @_;
29     print {*STDERR} $self->debug_prefix, "[$$] ", @msg, "\n";
30 }
31
32 for my $method (qw{
33     load_class apply_scheme validate_class
34     create_instance start_application
35   }){
36     requires $method;
37
38     before $method => sub {
39         my ($self, @args) = @_;
40         my $args = join ', ', @args;
41         $self->_debug_message("Calling $method($args)");
42     };
43
44     after $method => sub {
45         my $self = shift;
46         $self->_debug_message("Returning from $method");
47     };
48 }
49
50 1;
51
52 __END__
53
54 =head1 NAME
55
56 MooseX::Runnable::Invocation::Plugin::Debug - print debugging information
57
58 =head1 DESCRIPTION
59
60 This is an example plugin, showing how you could write your own.  It
61 prints a message for each stage of the "run" process.  It is also used
62 by other plugins to determine whether or not to print debugging
63 messages.
64
65 =head1 SEE ALSO
66
67 L<MooseX::Runnable>