Commit | Line | Data |
098b6cb6 |
1 | package MooseX::Runnable::Invocation::Plugin::Debug; |
d1de1498 |
2 | # ABSTRACT: print debugging information |
3 | |
098b6cb6 |
4 | use Moose::Role; |
098b6cb6 |
5 | |
2828ce0c |
6 | with 'MooseX::Runnable::Invocation::Plugin::Role::CmdlineArgs'; |
7 | |
0c9cfd21 |
8 | # this is an example to cargo-cult, rather than a useful feature :) |
9 | has 'debug_prefix' => ( |
10 | is => 'ro', |
11 | isa => 'Str', |
12 | required => 1, |
13 | default => sub { "" }, |
14 | ); |
15 | |
16 | sub _build_initargs_from_cmdline { |
17 | my ($class, @args) = @_; |
18 | confess 'Bad args passed to Debug plugin' |
19 | unless @args % 2 == 0; |
20 | |
21 | my %args = @args; |
22 | |
23 | if(my $p = $args{'--prefix'}){ |
24 | return { debug_prefix => $p }; |
25 | } |
26 | return; |
27 | } |
28 | |
7ebff650 |
29 | sub _debug_message { |
30 | my ($self, @msg) = @_; |
31 | print {*STDERR} $self->debug_prefix, "[$$] ", @msg, "\n"; |
32 | } |
33 | |
00fc26d5 |
34 | for my $method (qw{ |
35 | load_class apply_scheme validate_class |
36 | create_instance start_application |
37 | }){ |
098b6cb6 |
38 | requires $method; |
39 | |
40 | before $method => sub { |
00fc26d5 |
41 | my ($self, @args) = @_; |
098b6cb6 |
42 | my $args = join ', ', @args; |
7ebff650 |
43 | $self->_debug_message("Calling $method($args)"); |
098b6cb6 |
44 | }; |
45 | |
46 | after $method => sub { |
0c9cfd21 |
47 | my $self = shift; |
7ebff650 |
48 | $self->_debug_message("Returning from $method"); |
098b6cb6 |
49 | }; |
50 | } |
51 | |
52 | 1; |
fc5720d5 |
53 | |
54 | __END__ |
55 | |
d1de1498 |
56 | =pod |
fc5720d5 |
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> |
d1de1498 |
68 | |
69 | =cut |