| 1 | package Pipe::Tube::Grep; | ||||||||||
| 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 | 2 | ▶ | sub init { | ||||||||
|
Subroutine
init: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 11 | 2 | my ($self, $expr) = @_; | |||||||||
| 12 | 2 | $self->logger("Receiving the grep expression: $expr"); | |||||||||
| 13 | 2 | $self->{expr} = $expr; | |||||||||
| 14 | 2 | return $self; | |||||||||
| 15 | } | ||||||||||
| 16 | |||||||||||
| 17 | 14 | ▶ | sub run { | ||||||||
|
Subroutine
run: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||
| 18 | 14 | my ($self, @input) = @_; | |||||||||
| 19 | |||||||||||
| 20 | 14 | $self->logger("The grep expression: $self->{expr}"); | |||||||||
| 21 | 14 | ▶ | if ("Regexp" eq ref $self->{expr}) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | 7 | return grep /$self->{expr}/, @input; | |||||||||
| 23 | } else { | ||||||||||
| 24 | 7 | my $sub = $self->{expr}; | |||||||||
| 25 | 7 | return grep { $sub->($_) } @input; | |||||||||
| 26 | } | ||||||||||
| 27 | } | ||||||||||
| 28 | |||||||||||
| 29 | 1 | 1; | |||||||||
| 30 | |||||||||||