File Coverage

examples/testfilter.pl
Criterion Covered Total %
statement 17 17 100.0
branch 2 2 100.0
condition n/a
subroutine 5 5 100.0
pod n/a
total 24 24 100.0


line stmt bran cond sub pod time code
1             package Grepper;
2              
3             # This is an example of how to use the Text::Filter class.
4             #
5             # It implements a module that provides a single instance method: grep,
6             # that performs some kind of grep(1)-style function (how surprising!).
7             #
8             # A class method 'grepper' is also provided for easy access to do 'the
9             # right thing'.
10              
11 1     1   895 use strict;
  1         2  
  1         65  
12              
13 1     1   6 use base qw(Text::Filter);
  1         2  
  1         92  
14 1     1   5 use base qw(Exporter);
  1         1  
  1         186  
15             our @EXPORT = qw(grepper);
16              
17             # Constructor. All is done by the superclass.
18              
19             # Instance method, just an example. No magic.
20             sub grep {
21 8     8   12 my $self = shift;
22 8         10 my $pat = shift;
23 8         7 my $line;
24 8         26 while ( defined ($line = $self->readline) ) {
25 31 100       172 $self->writeline ($line) if $line =~ $pat;
26             }
27             }
28              
29             # Class method, for convenience.
30             # Usage: grepper (, , );
31             sub grepper {
32 1     1   522 my ($input, $output, $pat) = @_;
33              
34             # Create a Grepper object.
35 1         11 my $grepper = new Grepper (input => $input, output => $output);
36              
37             # Call its grep method.
38 1         4 $grepper->grep ($pat);
39             }
40              
41             1;