File Coverage

blib/lib/App/Automaton/Plugin/Source/File.pm
Criterion Covered Total %
statement 27 31 87.1
branch 5 8 62.5
condition n/a
subroutine 5 5 100.0
pod 1 1 100.0
total 38 45 84.4


line stmt bran cond sub pod time code
1             package App::Automaton::Plugin::Source::File;
2              
3             # ABSTRACT: File input module
4              
5 1     1   393 use strict;
  1         1  
  1         25  
6 1     1   3 use warnings;
  1         1  
  1         20  
7 1     1   360 use Moo;
  1         8508  
  1         5  
8              
9             sub go {
10 2     2 1 1416 my $self = shift;
11 2         3 my $in = shift;
12            
13 2         2 my $d = $in->{debug};
14              
15 2         2 my $file = $in->{path};
16 2         4 _logger($d, "Processing file: $file");
17 2 50       41 open(my $fh, "<", $in->{path}) || return 1;
18 2         23 my @lines = <$fh>;
19 2         8 close($fh);
20            
21 2 50       7 if ($in->{empty}) {
22 0         0 _logger($d, "emptying the file: $file");
23 0         0 open(my $fh, '>', $in->{path});
24 0         0 print $fh '';
25 0         0 close($fh);
26             }
27            
28 2 100       4 if ($in->{delete}) {
29 1         3 _logger($d, "deleting file: $file");
30 1         65 unlink $file;
31             }
32            
33 2         5 chomp(@lines);
34              
35 2         9 return(@lines);
36             }
37              
38             sub _logger {
39 3     3   3 my $level = shift;
40 3         2 my $message = shift;
41 3 50       5 print "$message\n" if $level;
42 3         3 return 1;
43             }
44              
45             1;
46              
47             __END__