File Coverage

blib/lib/Verby/Action.pm
Criterion Covered Total %
statement 1 3 33.3
branch n/a
condition n/a
subroutine 1 1 100.0
pod n/a
total 2 4 50.0


line stmt bran cond sub pod time code
1             #!/usr/bin/perl
2              
3             package Verby::Action;
4 2     2   32239 use Moose::Role;
  0            
  0            
5              
6             our $VERSION = "0.05";
7              
8             use Carp qw/longmess/;
9              
10             requires "do";
11              
12             requires "verify";
13              
14             sub confirm {
15             my ( $self, $c, @args ) = @_;
16              
17             $self->verify($c, @args) or
18             $c->logger->log_and_die(level => "error", message =>
19             "verification of $self failed: "
20             . ($c->error || "error unknown"));
21             }
22              
23             __PACKAGE__
24              
25             __END__
26              
27             =pod
28              
29             =head1 NAME
30              
31             Verby::Action - The base role for an action in Verby.
32              
33             =head1 SYNOPSIS
34              
35             package MyAction;
36             use Moose;
37              
38             with qw/Verby::Action/;
39              
40             sub do { ... }
41              
42             sub verify { ... }
43              
44             =head1 DESCRIPTION
45              
46             A Verby::Action is an object encapsulating reusable code. Steps usually
47             delegate to actions, for the actual grunt work.
48              
49             =head1 METHODS
50              
51             =over 4
52              
53             =item B<new>
54              
55             Instantiate an action. Actions should be able to live indefinitely, and should
56             not carry internal state with them. All the parameters for C<do> or C<verify>
57             are provided within the context.
58              
59             The action instance data should only be used to configure action "flavours",
60             controlling behavior that should not be parameter sensitive (configuration
61             data).
62              
63             =item B<do $cxt>
64              
65             The thing that the action really does. For example
66              
67             package Verby::Action::Download;
68              
69             sub do {
70             my ($self, $c) = @_;
71             system("wget", "-O", $c->file, $c->url);
72             }
73              
74             Will use wget to download C<< $c->url >> to C<< $c->file >>.
75              
76             This is a bad example though, you ought to subclass L<Verby::Action::Run> if
77             you want to run a command.
78              
79             =item B<verify $cxt>
80              
81             Perform a boolean check - whether or not the action is completed, for a given
82             set of arguments.
83              
84             For example, if C<do> downloads C<< $c->file >> from C<< $c->url >>, then the
85             verify method would look like:
86              
87             sub verify {
88             my ($self, $c) = @_;
89             -f $c->file;
90             }
91              
92             or it could even make a HEAD request and make sure that C<< $c->file >> is up
93             to date.
94              
95             =item B<confirm $cxt>
96              
97             Typically called at the end of an action's do:
98              
99             sub do {
100             my ($self, $c) = @_;
101             ...
102             $self->confirm($c);
103             }
104              
105             It will call C<< $c->logger->log_and_die >> unless C<verify> returns a true value.
106              
107             If C<< $c->error >> contains a string then it'll be printed as well.
108              
109             =back
110              
111             =head1 ASYNCHRONOUS ACTIONS
112              
113             Since L<Verby> is an abstraction layer over L<POE> and every step get's it's
114             own L<POE::Session>, an actions C<do> method can create child sessions, and the
115             parent session will wait till they are completed, as per default POE behavior.
116              
117             =back
118              
119             Note that this documentation assumes delegation of step methods to action
120             methods.
121              
122             L<Verby::Dispatcher> actually has nothing to do with L<Verby::Action>, it's
123             just that typically a L<Verby::Step> is just a thin wrapper for
124             L<Verby::Action>, so the methods roughly correspond.
125              
126             See L<Verby::Step::Closure> for a trivial way to generate steps given a
127             L<Verby::Action> subclass.
128              
129             =head1 BUGS
130              
131             None that we are aware of. Of course, if you find a bug, let us know, and we
132             will be sure to fix it.
133              
134             =head1 CODE COVERAGE
135              
136             We use B<Devel::Cover> to test the code coverage of the tests, please refer to COVERAGE section of the L<Verby> module for more information.
137              
138             =head1 SEE ALSO
139              
140             =head1 AUTHOR
141              
142             Yuval Kogman, E<lt>nothingmuch@woobling.orgE<gt>
143              
144             =head1 COPYRIGHT AND LICENSE
145              
146             Copyright 2005-2008 by Infinity Interactive, Inc.
147              
148             L<http://www.iinteractive.com>
149              
150             This library is free software; you can redistribute it and/or modify
151             it under the same terms as Perl itself.
152              
153             =cut