| 1 | package Search::Tools::TokenListPP; | ||||||||||||||
| 2 | 2 | ▶ | use Moo; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 3 | 2 | extends 'Search::Tools::Object'; | |||||||||||||
| 4 | use overload | ||||||||||||||
| 5 | 3 | ▶ | '""' => sub { $_[0]->str; }, | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 6 | 7 | ▶ | 'bool' => sub { $_[0]->len; }, | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 7 | 2 | fallback => 1; | |||||||||||||
| 8 | 2 | ▶ | use Carp; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 9 | 2 | with 'Search::Tools::TokenListUtils'; | |||||||||||||
| 10 | |||||||||||||||
| 11 | 2 | our $VERSION = '1.007'; | |||||||||||||
| 12 | |||||||||||||||
| 13 | 2 | has 'pos' => ( is => 'rw' ); | |||||||||||||
| 14 | 2 | has 'num' => ( is => 'rw' ); | |||||||||||||
| 15 | |||||||||||||||
| 16 | 15 | ▶ | sub len { | ||||||||||||
|
Subroutine
len: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 17 | 15 | return scalar @{ $_[0]->{tokens} }; | |||||||||||||
| 18 | } | ||||||||||||||
| 19 | |||||||||||||||
| 20 | 2 | ▶ | sub get_heat { | ||||||||||||
|
Subroutine
get_heat: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 21 | 2 | return $_[0]->{heat}; | |||||||||||||
| 22 | } | ||||||||||||||
| 23 | |||||||||||||||
| 24 | 200 | ▶ | sub next { | ||||||||||||
|
Subroutine
next: called CC=3 SCAR=11.2
Pod
documented
| |||||||||||||||
| 25 | 200 | my $self = shift; | |||||||||||||
| 26 | 200 | my $tokens = $self->{tokens}; | |||||||||||||
| 27 | 200 | my $len = scalar(@$tokens) - 1; | |||||||||||||
| 28 | 200 | ▶ | if ( $len == -1 ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 29 | 0 | return; | |||||||||||||
| 30 | } | ||||||||||||||
| 31 | elsif ( $self->{pos} > $len ) { | ||||||||||||||
| 32 | 6 | return; | |||||||||||||
| 33 | } | ||||||||||||||
| 34 | else { | ||||||||||||||
| 35 | 194 | return $tokens->[ $self->{pos}++ ]; | |||||||||||||
| 36 | } | ||||||||||||||
| 37 | } | ||||||||||||||
| 38 | |||||||||||||||
| 39 | 6 | ▶ | sub prev { | ||||||||||||
|
Subroutine
prev: called CC=3 SCAR=12.3
Pod
documented
| |||||||||||||||
| 40 | 6 | my $self = shift; | |||||||||||||
| 41 | 6 | my $tokens = $self->{tokens}; | |||||||||||||
| 42 | 6 | my $len = scalar(@$tokens) - 1; | |||||||||||||
| 43 | 6 | ▶ | if ( $len == -1 ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 44 | 0 | return; | |||||||||||||
| 45 | } | ||||||||||||||
| 46 | elsif ( $self->{pos} < 0 ) { | ||||||||||||||
| 47 | 0 | return; | |||||||||||||
| 48 | } | ||||||||||||||
| 49 | else { | ||||||||||||||
| 50 | 6 | return $tokens->[ --$self->{pos} ]; | |||||||||||||
| 51 | } | ||||||||||||||
| 52 | } | ||||||||||||||
| 53 | |||||||||||||||
| 54 | 0 | ▶ | sub reset { | ||||||||||||
|
Subroutine
reset: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 55 | 0 | $_[0]->{pos} = 0; | |||||||||||||
| 56 | } | ||||||||||||||
| 57 | |||||||||||||||
| 58 | 0 | ▶ | sub set_pos { | ||||||||||||
|
Subroutine
set_pos: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 59 | 0 | $_[0]->{pos} = $_[1]; | |||||||||||||
| 60 | } | ||||||||||||||
| 61 | |||||||||||||||
| 62 | 62 | ▶ | sub get_token { | ||||||||||||
|
Subroutine
get_token: called CC=3 SCAR=11.8
Pod
documented
| |||||||||||||||
| 63 | 62 | my $self = shift; | |||||||||||||
| 64 | 62 | my $len = scalar( @{ $self->{tokens} } ) - 1; | |||||||||||||
| 65 | 62 | my $i = shift; | |||||||||||||
| 66 | 62 | ▶ | if ( !defined $i ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 67 | 0 | croak "index position required"; | |||||||||||||
| 68 | } | ||||||||||||||
| 69 | 62 | ▶ | if ( !defined $self->{tokens}->[$i] ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 70 | 0 | return; | |||||||||||||
| 71 | } | ||||||||||||||
| 72 | else { | ||||||||||||||
| 73 | 62 | return $self->{tokens}->[$i]; | |||||||||||||
| 74 | } | ||||||||||||||
| 75 | } | ||||||||||||||
| 76 | |||||||||||||||
| 77 | 14 | ▶ | sub as_array { | ||||||||||||
|
Subroutine
as_array: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 78 | 14 | return $_[0]->{tokens}; | |||||||||||||
| 79 | } | ||||||||||||||
| 80 | |||||||||||||||
| 81 | 6 | ▶ | sub matches { | ||||||||||||
|
Subroutine
matches: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 82 | 6 | return [ grep { $_->{is_match} } @{ $_[0]->{tokens} } ]; | |||||||||||||
| 83 | } | ||||||||||||||
| 84 | |||||||||||||||
| 85 | 0 | ▶ | sub num_matches { | ||||||||||||
|
Subroutine
num_matches: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||
| 86 | 0 | return scalar @{ shift->matches }; | |||||||||||||
| 87 | } | ||||||||||||||
| 88 | |||||||||||||||
| 89 | 2 | 1; | |||||||||||||
| 90 | |||||||||||||||
| 91 | __END__ | ||||||||||||||