File Coverage

blib/lib/Pipe/Tube/Grep.pm
Criterion Covered Total %
statement 23 23 100.0
branch 2 2 100.0
condition n/a
subroutine 6 6 100.0
pod 0 2 0.0
total 31 33 93.9


line stmt bran cond sub pod time code
1             package Pipe::Tube::Grep;
2 1     1   7 use strict;
  1         3  
  1         62  
3 1     1   6 use warnings;
  1         1  
  1         34  
4 1     1   29 use 5.006;
  1         3  
  1         51  
5              
6 1     1   6 use base 'Pipe::Tube';
  1         2  
  1         356  
7              
8             our $VERSION = '0.05';
9              
10             sub init {
11 2     2 0 4 my ($self, $expr) = @_;
12 2         14 $self->logger("Receiving the grep expression: $expr");
13 2         5 $self->{expr} = $expr;
14 2         8 return $self;
15             }
16              
17             sub run {
18 14     14 0 29 my ($self, @input) = @_;
19              
20 14         57 $self->logger("The grep expression: $self->{expr}");
21 14 100       38 if ("Regexp" eq ref $self->{expr}) {
22 7         46 return grep /$self->{expr}/, @input;
23             } else {
24 7         11 my $sub = $self->{expr};
25 7         16 return grep { $sub->($_) } @input;
  5         13  
26             }
27             }
28              
29             1;
30