File Coverage

blib/lib/Text/Pipe.pm
Criterion Covered Total %
statement 37 37 100.0
branch 3 4 75.0
condition n/a
subroutine 11 11 100.0
pod 3 3 100.0
total 54 55 98.1


line stmt bran cond sub pod time code
1             package Text::Pipe;
2              
3 8     8   4916 use strict;
  8         15  
  8         248  
4 8     8   36 use warnings;
  8         11  
  8         208  
5 8     8   639 use 5.006;
  8         28  
  8         298  
6 8     8   4762 use Text::Pipe::Base; # for def_pipe()
  8         30  
  8         100  
7 8     8   1240 use Sub::Name;
  8         15  
  8         573  
8 8     8   45 use UNIVERSAL::require;
  8         20  
  8         69  
9              
10              
11             our $VERSION = '0.10';
12              
13              
14 8     8   545 use base 'Exporter';
  8         17  
  8         2514  
15              
16              
17             our %EXPORT_TAGS = (
18             util => [ qw(PIPE) ],
19             );
20              
21              
22             our @EXPORT_OK = @{ $EXPORT_TAGS{all} = [ map { @$_ } values %EXPORT_TAGS ] };
23              
24              
25             # this is just a factory
26              
27             sub new {
28 63     63 1 1837 my ($class, $type, @config) = @_;
29 63         173 my $package = "Text::Pipe::$type";
30              
31             # Check; it might have been defined with def_pipe(), so ->require wouldn't
32             # work.
33              
34 63 100       634 unless (UNIVERSAL::can($package, 'filter')) {
35 40 50       291 $package->require or die $@;
36             }
37              
38 63         1017 $package->new(@config);
39             }
40              
41              
42             sub def_pipe {
43 1     1 1 17 my ($self, $name, $code) = @_;
44 1         3 my $package = "Text::Pipe::$name";
45              
46 8     8   69 no strict 'refs';
  8         18  
  8         10568  
47 1         3 @{ "${package}::ISA" } = ('Text::Pipe::Base');
  1         35  
48 1         10 *{ "${package}::filter" } = subname "${package}::filter" => $code;
  1         5  
49             }
50              
51              
52             # Easier, procedural, way to construct a pipe
53              
54             sub PIPE {
55 19     19 1 76 my ($type, @args) = @_;
56 19         98 Text::Pipe->new($type, @args);
57             }
58              
59              
60             1;
61              
62              
63             __END__