| 1 | # Author Chris "BinGOs" Williams | ||||||||||
| 2 | # | ||||||||||
| 3 | # This module may be used, modified, and distributed under the same | ||||||||||
| 4 | # terms as Perl itself. Please see the license that came with your Perl | ||||||||||
| 5 | # distribution for details. | ||||||||||
| 6 | # | ||||||||||
| 7 | |||||||||||
| 8 | package POE::Filter::ParseWords; | ||||||||||
| 9 | 2 | $POE::Filter::ParseWords::VERSION = '1.08'; | |||||||||
| 10 | #ABSTRACT: A POE-based parser to parse text into an array of tokens. | ||||||||||
| 11 | |||||||||||
| 12 | 2 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 2 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 2 | ▶ | use base qw(POE::Filter); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 2 | ▶ | use Text::ParseWords; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | |||||||||||
| 17 | 1 | ▶ | sub new { | ||||||||
|
Subroutine
new: called CC=4 SCAR=14.1
Pod
documented
| |||||||||||
| 18 | 1 | my $class = shift; | |||||||||
| 19 | 1 | my %opts = @_; | |||||||||
| 20 | 1 | $opts{lc $_} = delete $opts{$_} for keys %opts; | |||||||||
| 21 | 1 | ▶ | $opts{keep} = 0 unless $opts{keep}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 22 | 1 | ▶ | $opts{delim} = '\s+' unless $opts{delim}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | 1 | $opts{BUFFER} = []; | |||||||||
| 24 | 1 | bless \%opts, $class; | |||||||||
| 25 | } | ||||||||||
| 26 | |||||||||||
| 27 | 2 | ▶ | sub get { | ||||||||
|
Subroutine
get: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 28 | 2 | my ($self, $raw) = @_; | |||||||||
| 29 | 2 | my $events = []; | |||||||||
| 30 | 2 | push @$events, [ parse_line( $self->{delim}, $self->{keep}, $_ ) ] for @$raw; | |||||||||
| 31 | 2 | return $events; | |||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | 0 | ▶ | sub get_one_start { | ||||||||
|
Subroutine
get_one_start: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 35 | 0 | my ($self, $raw) = @_; | |||||||||
| 36 | 0 | push @{ $self->{BUFFER} }, $_ for @$raw; | |||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | 0 | ▶ | sub get_one { | ||||||||
|
Subroutine
get_one: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||
| 40 | 0 | my $self = shift; | |||||||||
| 41 | 0 | my $events = []; | |||||||||
| 42 | 0 | my $event = shift @{ $self->{BUFFER} }; | |||||||||
| 43 | 0 | ▶ | push @$events, [ parse_line( $self->{delim}, $self->{keep}, $event ) ] if defined $event; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 44 | 0 | return $events; | |||||||||
| 45 | } | ||||||||||
| 46 | |||||||||||
| 47 | 0 | ▶ | sub put { | ||||||||
|
Subroutine
put: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||
| 48 | 0 | warn "PUT is unimplemented\n"; | |||||||||
| 49 | 0 | return; | |||||||||
| 50 | } | ||||||||||
| 51 | |||||||||||
| 52 | 1 | ▶ | sub clone { | ||||||||
|
Subroutine
clone: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||
| 53 | 1 | my $self = shift; | |||||||||
| 54 | 1 | my $nself = { }; | |||||||||
| 55 | 1 | $nself->{$_} = $self->{$_} for keys %{ $self }; | |||||||||
| 56 | 1 | $nself->{BUFFER} = [ ]; | |||||||||
| 57 | 1 | return bless $nself, ref $self; | |||||||||
| 58 | } | ||||||||||
| 59 | |||||||||||
| 60 | 2 | qq[Parse it!]; | |||||||||
| 61 | |||||||||||
| 62 | __END__ | ||||||||||