File Coverage

blib/lib/ETL/Yertl/Command/ymask.pm
Criterion Covered Total %
statement 27 29 93.1
branch 8 10 80.0
condition n/a
subroutine 4 4 100.0
pod 0 1 0.0
total 39 44 88.6


line stmt bran cond sub pod time code
1             package ETL::Yertl::Command::ymask;
2             our $VERSION = '0.035';
3             # ABSTRACT: Filter documents through applying a mask
4              
5 1     1   7 use ETL::Yertl;
  1         3  
  1         11  
6 1     1   335 use ETL::Yertl::Util qw( load_module );
  1         3  
  1         43  
7 1     1   301 use Data::Partial::Google;
  1         312411  
  1         301  
8              
9             sub main {
10 3     3 0 7 my $class = shift;
11              
12 3         4 my %opt;
13 3 50       13 if ( ref $_[-1] eq 'HASH' ) {
14 3         6 %opt = %{ pop @_ };
  3         9  
15             }
16              
17 3         8 my ( $mask, @files ) = @_;
18              
19 3 100       44 die "Must give a mask\n" unless $mask;
20              
21 2         39 my $filter = Data::Partial::Google->new( $mask );
22 2         9935 my $out_fmt = load_module( format => 'default' )->new;
23              
24 2 100       10 push @files, "-" unless @files;
25 2         6 for my $file ( @files ) {
26             # We're doing a similar behavior to <>, but manually for easier testing.
27 2         5 my $fh;
28 2 100       6 if ( $file eq '-' ) {
29             # Use the existing STDIN so tests can fake it
30 1         3 $fh = \*STDIN;
31             }
32             else {
33 1 50       37 unless ( open $fh, '<', $file ) {
34 0         0 warn "Could not open file '$file' for reading: $!\n";
35 0         0 next;
36             }
37             }
38              
39 2         12 my $in_fmt = load_module( format => 'default' )->new( input => $fh );
40 2         12 for my $doc ( $in_fmt->read ) {
41 4         27 print $out_fmt->write( $filter->mask( $doc ) );
42             }
43             }
44             }
45              
46             1;
47              
48             __END__