File Coverage

blib/lib/Verby/Action/BuildTool.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::BuildTool;
4 2     2   288400 use Moose;
  0            
  0            
5              
6             with qw/Verby::Action::Run/;
7              
8             use File::Spec;
9             use File::stat;
10              
11             has command => (
12             isa => "Str",
13             is => "rw",
14             default => $^X,
15             );
16              
17             has script => (
18             isa => "Str",
19             is => "rw",
20             default => "Makefile.PL",
21             );
22              
23             has target => (
24             isa => "Str",
25             is => "rw",
26             default => "Makefile",
27             );
28              
29             sub do {
30             my ( $self, $c ) = @_;
31              
32             my $wd = $c->workdir || $c->logger->log_and_die(level => "error", message => "No working directory provided");
33             my @args = @{ $c->additional_args || [] };
34              
35             $self->create_poe_session(
36             c => $c,
37             cli => [ $self->command, $self->script, @args ],
38             init => sub { chdir $wd },
39             );
40             }
41              
42             sub finished {
43             my ( $self, $c ) = @_;
44             $self->confirm( $c );
45             }
46              
47             sub log_extra {
48             my ( $self, $c ) = @_;
49             " in " . $c->workdir;
50             }
51              
52             sub verify {
53             my ( $self, $c ) = @_;
54              
55             my $target = File::Spec->catfile($c->workdir, $self->target);
56             my $script = File::Spec->catfile($c->workdir, $self->script);
57              
58             unless (-e $target) {
59             $c->error("$target doesn't exist");
60             return;
61             }
62            
63             unless ( stat($target)->mtime >= stat($script)->mtime ) {
64             $c->error("$target is out of date");
65             return;
66             }
67              
68             return 1;
69             }
70              
71             __PACKAGE__
72              
73             __END__
74              
75             =pod
76              
77             =head1 NAME
78              
79             Verby::Action::BuildTool - Action to run 'perl Makefile.PL' or something
80             similar in a specific directory.
81              
82             =head1 SYNOPSIS
83              
84             use Verby::Action::MakefilePL;
85              
86             =head1 DESCRIPTION
87              
88             This action runs something like 'perl Makefile.PL' (the C<script> field) if the
89             C<target> field (it's output file) seems out of date.
90              
91             =head1 METHODS
92              
93             =over 4
94              
95             =item B<do>
96              
97             Run the C<script> in the specified directory, using C<command>.
98              
99             =item B<log_extra>
100              
101             Used by the Run role to improve the log messages.
102              
103             =item B<verfiy>
104              
105             Ensures that the C<target> file exists next to the C<script> file, and that is
106             as new or newer than C<script>.
107              
108             =back
109              
110             =head1 FIELDS
111              
112             =over 4
113              
114             =item B<command>
115              
116             Defaults to C<$^X> (the process used to invoke the currently running perl
117             program, probably "perl" or the shebang line).
118              
119             =item B<script>
120              
121             Defaults to C<Makefile.PL>.
122              
123             =item B<target>
124              
125             Defaults to C<Makefile>.
126              
127             =back
128              
129             =head1 PARAMETERS
130              
131             =over 4
132              
133             =item C<workdir>
134              
135             The directory in which to run the script.
136              
137             =item C<additional_args>
138              
139             An optional array ref for additional parameters to send to the script.
140              
141             =back
142              
143             =head1 BUGS
144              
145             None that we are aware of. Of course, if you find a bug, let us know, and we will be sure to fix it.
146              
147             =head1 CODE COVERAGE
148              
149             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.
150              
151             =head1 SEE ALSO
152              
153             =head1 AUTHOR
154              
155             Yuval Kogman, E<lt>nothingmuch@woobling.orgE<gt>
156              
157             =head1 COPYRIGHT AND LICENSE
158              
159             Copyright 2005-2008 by Infinity Interactive, Inc.
160              
161             L<http://www.iinteractive.com>
162              
163             This library is free software; you can redistribute it and/or modify
164             it under the same terms as Perl itself.
165              
166             =cut