File Coverage

blib/lib/Verby/Action/Make.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::Make;
4 1     1   1997 use Moose;
  0            
  0            
5              
6             with qw(Verby::Action::Run::Unconditional);
7              
8             our $VERSION = "0.05";
9              
10             has make_path => (
11             isa => "Str",
12             is => "rw",
13             default => "make",
14             );
15              
16             has num_jobs => (
17             isa => "Int",
18             is => "rw",
19             default => 1,
20             );
21              
22             has silent => (
23             isa => "Bool",
24             is => "rw",
25             default => 1,
26             );
27              
28             sub do {
29             my ( $self, $c ) = @_;
30              
31             my $wd = $c->workdir;
32             my $makefile = $c->makefile;
33             my @targets = (($c->target || ()), @{ $c->targets || [] });
34              
35             my $num_jobs = $self->num_jobs;
36             my $silent = $self->silent;
37              
38             $c->is_make_test(1) if "@targets" eq "test";
39              
40             my @cli = (
41             $self->make_path,
42             "-j$num_jobs",
43             ( $silent ? "-s" : () ),
44             ( defined($makefile) ? ( "-f" => $makefile ) : () ),
45             "-C" => $wd,
46             @targets,
47             );
48              
49             $self->create_poe_session(
50             c => $c,
51             cli => \@cli,
52             );
53             }
54              
55             sub finished {
56             my ( $self, $c ) = @_;
57              
58             my $out = $c->stdout;
59             chomp($out);
60             $c->logger->info("test output:\n$out") if $c->is_make_test;
61              
62             $self->confirm($c);
63             }
64              
65             around exit_code_is_ok => sub {
66             my $next = shift;
67             my ( $self, $c ) = @_;
68            
69             if ( $c->is_make_test and $c->allow_test_failurei ) {
70             # GNU make exits with '2' on any error in a subtool
71             # this is not perfect, but it's something
72             $c->program_exit == 2 || $self->$next($c);
73             } else {
74             $self->$next($c);
75             }
76             };
77              
78             sub log_extra {
79             my ( $self, $c ) = @_;
80             " in " . $c->workdir;
81             }
82              
83             __PACKAGE__
84              
85             __END__
86              
87             =pod
88              
89             =head1 NAME
90              
91             Verby::Action::Make - Action to run make(1).
92              
93             =head1 SYNOPSIS
94              
95             use Verby::Action::Make;
96              
97             =head1 DESCRIPTION
98              
99             =head1 METHODS
100              
101             =over 4
102              
103             =item B<do>
104              
105             Run the make command with the specified parameters and fields.
106              
107             =item B<log_extra>
108              
109             Used by the Run role to provide better log messages.
110              
111             =item B<finished>
112              
113             Called by the Run role when the job has finished,
114              
115             =back
116              
117             =head1 PARAMETERS
118              
119             =over 4
120              
121             =item B<target>
122              
123             =item B<targets>
124              
125             The make targets to run, like e.g. C<test>.
126              
127             Optional.
128              
129             =item B<workdir>
130              
131             The directory in which the makefile should be found. This is passed as the
132             C<-C> option to C<make>.
133              
134             =item B<makefile>
135              
136             If defined, passed as the C<-f> option to make.
137              
138             =back
139              
140             =head1 FIELDS
141              
142             =over 4
143              
144             =item B<make_path>
145              
146             The name of the command to run. Defaults to C<make>, but can be overridden to
147             use e.g. C<gmake>, or something not in $PATH.
148              
149             =item B<num_jobs>
150              
151             The C<-j> flag to make. Defaults to 1.
152              
153             =item B<silent>
154              
155             Whether or not to pass the C<-s> option to make. Defaults to true.
156              
157             =back
158              
159             =head1 BUGS
160              
161             None that we are aware of. Of course, if you find a bug, let us know, and we
162             will be sure to fix it.
163              
164             =head1 CODE COVERAGE
165              
166             We use B<Devel::Cover> to test the code coverage of the tests, please refer to
167             COVERAGE section of the L<Verby> module for more information.
168              
169             =head1 SEE ALSO
170              
171             =head1 AUTHOR
172              
173             Yuval Kogman, E<lt>nothingmuch@woobling.orgE<gt>
174              
175             =head1 COPYRIGHT AND LICENSE
176              
177             Copyright 2005-2008 by Infinity Interactive, Inc.
178              
179             L<http://www.iinteractive.com>
180              
181             This library is free software; you can redistribute it and/or modify
182             it under the same terms as Perl itself.
183              
184             =cut