| 1 | package Pipe::Tube::Print; | ||||||||||||||
| 2 | 1 | ▶ | use strict; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | 1 | ▶ | use warnings; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 4 | 1 | ▶ | use 5.006; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 5 | |||||||||||||||
| 6 | 1 | ▶ | use base 'Pipe::Tube'; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | |||||||||||||||
| 8 | 1 | our $VERSION = '0.06'; | |||||||||||||
| 9 | |||||||||||||||
| 10 | 4 | ▶ | sub init { | ||||||||||||
|
Subroutine
init: called CC=5 SCAR=16.6
Pod
undocumented
| |||||||||||||||
| 11 | 4 | my ($self, $file) = @_; | |||||||||||||
| 12 | # file can be either undef -> STDOUT or a filehandle, or a filename -> print into that file, | ||||||||||||||
| 13 | 4 | ▶ | if ($file) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 14 | 4 | ▶ | if (not ref $file) { # string, assume filename | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 15 | 2 | ▶ | open my $fh, ">", $file or die $!; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 16 | 2 | $self->{fh} = $fh; | |||||||||||||
| 17 | 2 | $self->logger("Print: received filename"); | |||||||||||||
| 18 | } elsif ('GLOB' eq ref $file) { # filehandle | ||||||||||||||
| 19 | 2 | $self->{fh} = $file; | |||||||||||||
| 20 | 2 | $self->logger("Print: received filehandle"); | |||||||||||||
| 21 | } else { | ||||||||||||||
| 22 | 0 | die "Unkown type of paramter for print: '" . ref($file) . "'\n"; | |||||||||||||
| 23 | } | ||||||||||||||
| 24 | } | ||||||||||||||
| 25 | 4 | return $self; | |||||||||||||
| 26 | } | ||||||||||||||
| 27 | |||||||||||||||
| 28 | 28 | ▶ | sub run { | ||||||||||||
|
Subroutine
run: called CC=2 SCAR=7.2
Pod
undocumented
| |||||||||||||||
| 29 | 28 | my ($self, @input) = @_; | |||||||||||||
| 30 | 28 | $self->logger("Print: @input"); | |||||||||||||
| 31 | 28 | ▶ | if (my $fh = $self->{fh}) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 32 | 28 | print $fh @input; | |||||||||||||
| 33 | } else { | ||||||||||||||
| 34 | 0 | print @input; | |||||||||||||
| 35 | } | ||||||||||||||
| 36 | 28 | return; | |||||||||||||
| 37 | } | ||||||||||||||
| 38 | |||||||||||||||
| 39 | |||||||||||||||
| 40 | 1 | 1; | |||||||||||||
| 41 | |||||||||||||||