| line | stmt | bran | cond | sub | pod | time | code | 
| 1 |  |  |  |  |  |  | package App::Automatan::Plugin::Source::File; | 
| 2 |  |  |  |  |  |  |  | 
| 3 |  |  |  |  |  |  | # ABSTRACT: File input module | 
| 4 |  |  |  |  |  |  |  | 
| 5 | 1 |  |  | 1 |  | 456 | use strict; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 28 |  | 
| 6 | 1 |  |  | 1 |  | 4 | use warnings; | 
|  | 1 |  |  |  |  | 1 |  | 
|  | 1 |  |  |  |  | 20 |  | 
| 7 | 1 |  |  | 1 |  | 444 | use Moo; | 
|  | 1 |  |  |  |  | 11127 |  | 
|  | 1 |  |  |  |  | 6 |  | 
| 8 |  |  |  |  |  |  |  | 
| 9 |  |  |  |  |  |  | sub go { | 
| 10 | 2 |  |  | 2 | 1 | 1677 | my $self = shift; | 
| 11 | 2 |  |  |  |  | 2 | my $in = shift; | 
| 12 |  |  |  |  |  |  |  | 
| 13 | 2 |  |  |  |  | 3 | my $d = $in->{debug}; | 
| 14 |  |  |  |  |  |  |  | 
| 15 | 2 |  |  |  |  | 2 | my $file = $in->{path}; | 
| 16 | 2 |  |  |  |  | 5 | _logger($d, "Processing file: $file"); | 
| 17 | 2 | 50 |  |  |  | 50 | open(my $fh, "<", $in->{path}) || return 1; | 
| 18 | 2 |  |  |  |  | 30 | my @lines = <$fh>; | 
| 19 | 2 |  |  |  |  | 11 | close($fh); | 
| 20 |  |  |  |  |  |  |  | 
| 21 | 2 | 50 |  |  |  | 6 | 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 |  |  |  |  | 4 | _logger($d, "deleting file: $file"); | 
| 30 | 1 |  |  |  |  | 68 | unlink $file; | 
| 31 |  |  |  |  |  |  | } | 
| 32 |  |  |  |  |  |  |  | 
| 33 | 2 |  |  |  |  | 5 | chomp(@lines); | 
| 34 |  |  |  |  |  |  |  | 
| 35 | 2 |  |  |  |  | 10 | return(@lines); | 
| 36 |  |  |  |  |  |  | } | 
| 37 |  |  |  |  |  |  |  | 
| 38 |  |  |  |  |  |  | sub _logger { | 
| 39 | 3 |  |  | 3 |  | 3 | my $level = shift; | 
| 40 | 3 |  |  |  |  | 3 | my $message = shift; | 
| 41 | 3 | 50 |  |  |  | 6 | print "$message\n" if $level; | 
| 42 | 3 |  |  |  |  | 4 | return 1; | 
| 43 |  |  |  |  |  |  | } | 
| 44 |  |  |  |  |  |  |  | 
| 45 |  |  |  |  |  |  | 1; | 
| 46 |  |  |  |  |  |  |  | 
| 47 |  |  |  |  |  |  | __END__ |