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