File Coverage

blib/lib/ExtUtils/Builder/Action/Code.pm
Criterion Covered Total %
statement 37 39 94.8
branch 6 8 75.0
condition 5 8 62.5
subroutine 10 10 100.0
pod 4 5 80.0
total 62 70 88.5


line stmt bran cond sub pod time code
1             package ExtUtils::Builder::Action::Code;
2             $ExtUtils::Builder::Action::Code::VERSION = '0.020';
3 8     8   367220 use strict;
  8         19  
  8         313  
4 8     8   42 use warnings;
  8         36  
  8         494  
5              
6 8     8   495 use parent 'ExtUtils::Builder::Action::Perl';
  8         349  
  8         47  
7              
8 8     8   421 use Carp ();
  8         19  
  8         237  
9 8     8   2634 use ExtUtils::Builder::Util 'get_perl';
  8         23  
  8         3861  
10              
11             sub new {
12 22     22 0 945060 my ($class, %args) = @_;
13 22 50       81 Carp::croak('Need to define code') if !$args{code};
14 22   100     144 $args{modules} //= [];
15 22         165 my $self = $class->SUPER::new(%args);
16 22         147 return $self;
17             }
18              
19             sub modules {
20 28     28 1 49 my $self = shift;
21 28         46 return @{ $self->{modules} };
  28         124  
22             }
23              
24             sub execute {
25 21     21 1 2059 my ($self, %opts) = @_;
26 21         60 my $code = $self->to_code();
27 21 100       63 if (!$opts{quiet}) {
28 12   66     100 my $message = $self->{message} // $code;
29 12         188 print "$message\n";
30             }
31 21 50       1766 eval $code . '; 1' or die $@;
32 21         149 return;
33             }
34              
35             sub to_code {
36 28     28 1 2224 my ($self, %opts) = @_;
37 28 100       108 my @modules = $opts{skip_loading} ? () : map { "require $_" } $self->modules;
  0         0  
38 28         139 return join '; ', @modules, $self->{code};
39             }
40              
41             sub to_command {
42 3     3 1 2143 my ($self, %opts) = @_;
43 3         16 my @modules = map { "-M$_" } $self->modules;
  0         0  
44 3   33     23 my $perl = $opts{perl} // get_perl(%opts);
45 3         12 return [ $perl, @modules, '-e', $self->to_code(skip_loading => 'main') ];
46             }
47              
48             1;
49              
50             #ABSTRACT: Action objects for perl code
51              
52             __END__