File Coverage

blib/lib/Pipe/Tube/Print.pm
Criterion Covered Total %
statement 26 28 92.8
branch 6 10 60.0
condition n/a
subroutine 6 6 100.0
pod 0 2 0.0
total 38 46 82.6


line stmt bran cond sub pod time code
1             package Pipe::Tube::Print;
2 1     1   5 use strict;
  1         2  
  1         150  
3 1     1   6 use warnings;
  1         2  
  1         36  
4 1     1   31 use 5.006;
  1         3  
  1         41  
5              
6 1     1   5 use base 'Pipe::Tube';
  1         2  
  1         413  
7              
8             our $VERSION = '0.05';
9              
10             sub init {
11 4     4 0 10 my ($self, $file) = @_;
12             # file can be either undef -> STDOUT or a filehandle, or a filename -> print into that file,
13 4 50       10 if ($file) {
14 4 100       20 if (not ref $file) { # string, assume filename
    50          
15 2 50       242 open my $fh, ">", $file or die $!;
16 2         7 $self->{fh} = $fh;
17 2         16 $self->logger("Print: received filename");
18             } elsif ('GLOB' eq ref $file) { # filehandle
19 2         7 $self->{fh} = $file;
20 2         7 $self->logger("Print: received filehandle");
21             } else {
22 0         0 die "Unkown type of paramter for print: '" . ref($file) . "'\n";
23             }
24             }
25 4         18 return $self;
26             }
27              
28             sub run {
29 28     28 0 53 my ($self, @input) = @_;
30 28         88 $self->logger("Print: @input");
31 28 50       63 if (my $fh = $self->{fh}) {
32 28         166 print $fh @input;
33             } else {
34 0         0 print @input;
35             }
36 28         175 return;
37             }
38              
39              
40             1;
41