File Coverage

blib/lib/Run/Parts/Perl.pm
Criterion Covered Total %
statement 40 40 100.0
branch 1 2 100.0
condition 2 2 100.0
subroutine 10 10 100.0
pod 6 6 100.0
total 59 60 100.0


line stmt bran cond sub pod time code
1             package Run::Parts::Perl;
2              
3             # ABSTRACT: Pure Perl implementation of Debian's run-parts tool
4              
5 5     5   29 use Modern::Perl;
  5         9  
  5         30  
6 5     5   6032 use autodie;
  5         84278  
  5         35  
7 5     5   41719 use Taint::Util;
  5         3215  
  5         29  
8 5     5   357 use Run::Parts::Common;
  5         10  
  5         3395  
9              
10             our $VERSION = '0.08'; # VERSION generated by DZP::OurPkgVersion
11              
12              
13             # On DOS and Windows, run-parts' regular expressions are not really
14             # applicable. Allow an arbitrary alphanumerical suffix there.
15             my $win_suffix = dosish() ? qr/\.[a-z0-9]+/i : qr'';
16             my $file_re = qr/^[-A-Za-z0-9_]+($win_suffix)?$/;
17              
18              
19             sub new {
20 5     5 1 3926 my $self = {};
21 5         24 bless($self, shift);
22 5         45 $self->{dir} = shift;
23              
24 5         57 return $self;
25             }
26              
27              
28             sub run_parts_command {
29 26     26 1 63 my $self = shift;
30 26   100     231 my $rp_cmd = shift // 'run';
31              
32 26         142 my @result = $self->$rp_cmd(@_);
33              
34 26         560 return lines(@result);
35             }
36              
37              
38             sub list {
39 26     26 1 67 my $self = shift;
40 26         142 my $dir = $self->{dir};
41              
42 26         215 opendir(my $dh, $dir);
43 104         1706 my @list = sort map {
44             # $dir can neither be '' nor undef, hence no check necessary
45 208         2378 "$dir/$_";
46             } grep {
47 26         12890 /$file_re/
48             } readdir($dh);
49             }
50              
51              
52             sub test {
53 12     12 1 54 my $self = shift;
54 12         52 my $dir = $self->{dir};
55              
56 12         75 return grep { -x } $self->list($dir);
  48         1208  
57             }
58              
59              
60             sub run {
61 4     4 1 12 my $self = shift;
62 4         204 my $dir = $self->{dir};
63              
64 8         65 return map {
65 4         21 my $command = $_;
66 8         83 untaint($command);
67             # uncoverable branch true
68 8 50       122 $command =~ s(/)(\\)g if dosish();
69 8         88490 my $output = `$command`;
70 8         173 chomp($output);
71 8         464 $output;
72             } $self->test($dir);
73             }
74              
75              
76             sub dosish {
77 13     13 1 347 return $^O =~ /^(dos|os2|MSWin32)$/;
78             }
79              
80              
81             qr/\.d$/; # End of Run::Parts::Perl
82              
83             __END__