| 1 | package Locale::Babelfish::Phrase::ParserBase; | ||||||||||||||||||||||
| 2 | |||||||||||||||||||||||
| 3 | # ABSTRACT: Babelfish abstract parser. | ||||||||||||||||||||||
| 4 | |||||||||||||||||||||||
| 5 | 8 | ▶ | use utf8; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 6 | 8 | ▶ | use strict; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 7 | 8 | ▶ | use warnings; | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 8 | |||||||||||||||||||||||
| 9 | 8 | ▶ | use parent qw( Class::Accessor::Fast ); | ||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||
| 10 | |||||||||||||||||||||||
| 11 | 8 | our $VERSION = '2.13'; # VERSION | |||||||||||||||||||||
| 12 | |||||||||||||||||||||||
| 13 | 8 | __PACKAGE__->mk_accessors( qw( phrase index length prev piece escape ) ); | |||||||||||||||||||||
| 14 | |||||||||||||||||||||||
| 15 | |||||||||||||||||||||||
| 16 | 7 | ▶ | sub new { | ||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.0
Pod
documented
| |||||||||||||||||||||||
| 17 | 7 | my ( $class, $phrase ) = @_; | |||||||||||||||||||||
| 18 | 7 | my $parser = bless {}, $class; | |||||||||||||||||||||
| 19 | 7 | ▶ | $parser->init( $phrase ) if defined $phrase; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 20 | 7 | return $parser; | |||||||||||||||||||||
| 21 | } | ||||||||||||||||||||||
| 22 | |||||||||||||||||||||||
| 23 | |||||||||||||||||||||||
| 24 | 291 | ▶ | sub init { | ||||||||||||||||||||
|
Subroutine
init: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||
| 25 | 291 | my ( $self, $phrase ) = @_; | |||||||||||||||||||||
| 26 | 291 | $self->phrase( $phrase ); | |||||||||||||||||||||
| 27 | 291 | $self->index( -1 ); | |||||||||||||||||||||
| 28 | 291 | $self->prev( undef ); | |||||||||||||||||||||
| 29 | 291 | $self->length( length( $phrase ) ); | |||||||||||||||||||||
| 30 | 291 | $self->piece( '' ); | |||||||||||||||||||||
| 31 | 291 | $self->escape( 0 ); | |||||||||||||||||||||
| 32 | 291 | return $self; | |||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||
| 34 | |||||||||||||||||||||||
| 35 | |||||||||||||||||||||||
| 36 | 70 | ▶ | sub trim { | ||||||||||||||||||||
|
Subroutine
trim: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||
| 37 | 70 | my ( $self, $str ) = @_; | |||||||||||||||||||||
| 38 | 70 | $str =~ s/\A\p{PerlSpace}+//; | |||||||||||||||||||||
| 39 | 70 | $str =~ s/\p{PerlSpace}+\z//; | |||||||||||||||||||||
| 40 | 70 | return $str; | |||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||
| 42 | |||||||||||||||||||||||
| 43 | |||||||||||||||||||||||
| 44 | 6866 | ▶ | sub char { | ||||||||||||||||||||
|
Subroutine
char: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||
| 45 | 6866 | my ( $self ) = @_; | |||||||||||||||||||||
| 46 | 6866 | ▶ | return substr( $self->phrase, $self->index, 1 ) // ''; | ||||||||||||||||||||
|
Condition50%1/2
substr($self->phrase, $self->index, 1) // ""
MC/DC0%0/1
substr($self->phrase, $self->index, 1) // ""
substr($self->phrase, $self->index, 1)
Truth table50%1/2
A
A= substr($self->phrase, $self->index, 1)
| |||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||
| 48 | |||||||||||||||||||||||
| 49 | |||||||||||||||||||||||
| 50 | 159 | ▶ | sub next_char { | ||||||||||||||||||||
|
Subroutine
next_char: called CC=3 SCAR=11.1
Pod
documented
| |||||||||||||||||||||||
| 51 | 159 | my ( $self ) = @_; | |||||||||||||||||||||
| 52 | 159 | ▶ | return '' if $self->index >= $self->length - 1; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 53 | 157 | ▶ | return substr( $self->phrase, $self->index + 1, 1 ) // ''; | ||||||||||||||||||||
|
Condition50%1/2
substr($self->phrase, $self->index + 1, 1) // ""
MC/DC0%0/1
substr($self->phrase, $self->index + 1, 1) // ""
substr($self->phrase, $self->index + 1, 1)
Truth table50%1/2
A
A= substr($self->phrase, $self->index + 1, 1)
| |||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||
| 55 | |||||||||||||||||||||||
| 56 | |||||||||||||||||||||||
| 57 | 3723 | ▶ | sub to_next_char { | ||||||||||||||||||||
|
Subroutine
to_next_char: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||
| 58 | 3723 | my ( $self ) = @_; | |||||||||||||||||||||
| 59 | 3723 | ▶ | if ( $self->index >= 0 ) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 60 | 3432 | $self->prev( $self->char ); | |||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||
| 62 | 3723 | $self->index( $self->index + 1 ); | |||||||||||||||||||||
| 63 | 3723 | ▶ | return '' if $self->index eq $self->length; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 64 | 3434 | return $self->char(); | |||||||||||||||||||||
| 65 | } | ||||||||||||||||||||||
| 66 | |||||||||||||||||||||||
| 67 | |||||||||||||||||||||||
| 68 | 3 | ▶ | sub throw { | ||||||||||||||||||||
|
Subroutine
throw: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||
| 69 | 3 | my ( $self, $message ) = @_; | |||||||||||||||||||||
| 70 | 3 | ▶ | die "Cannot parse phrase \"". ( $self->phrase // 'undef' ). "\" at ". ( $self->index // '-1' ). " index: $message"; | ||||||||||||||||||||
|
Condition100%4/4
$self->phrase // "undef"
$self->index // -1
MC/DC100%1/1
$self->phrase // "undef"
$self->phrase
MC/DC100%1/1
$self->index // -1
$self->index
Truth table100%2/2
A
A= $self->phrase
Truth table100%2/2
A
A= $self->index
| |||||||||||||||||||||||
| 71 | } | ||||||||||||||||||||||
| 72 | |||||||||||||||||||||||
| 73 | |||||||||||||||||||||||
| 74 | 3055 | ▶ | sub add_to_piece { | ||||||||||||||||||||
|
Subroutine
add_to_piece: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||
| 75 | 3055 | my ( $self, @chars ) = @_; | |||||||||||||||||||||
| 76 | 3055 | $self->piece( join('', $self->piece, @chars ) ); | |||||||||||||||||||||
| 77 | } | ||||||||||||||||||||||
| 78 | |||||||||||||||||||||||
| 79 | |||||||||||||||||||||||
| 80 | 18 | ▶ | sub backward { | ||||||||||||||||||||
|
Subroutine
backward: called CC=2 SCAR=7.4
Pod
documented
| |||||||||||||||||||||||
| 81 | 18 | my ( $self ) = @_; | |||||||||||||||||||||
| 82 | 18 | $self->index( $self->index - 1 ); | |||||||||||||||||||||
| 83 | 18 | ▶ | if ( $self->index > 0 ) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 84 | 18 | $self->prev( substr( $self->phrase, $self->index - 1, 1 ) ); | |||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||
| 86 | else { | ||||||||||||||||||||||
| 87 | 0 | $self->prev( undef ); | |||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||
| 90 | |||||||||||||||||||||||
| 91 | |||||||||||||||||||||||
| 92 | 292 | ▶ | sub parse { | ||||||||||||||||||||
|
Subroutine
parse: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||||||||||||||
| 93 | 292 | my ( $self, $phrase ) = @_; | |||||||||||||||||||||
| 94 | |||||||||||||||||||||||
| 95 | 292 | ▶ | if ( defined $phrase ) { | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 96 | 291 | $self->init( $phrase ); | |||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||
| 98 | |||||||||||||||||||||||
| 99 | 292 | ▶ | $self->throw( "No phrase given" ) unless defined $self->phrase; | ||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||
| 100 | |||||||||||||||||||||||
| 101 | 291 | return $self->phrase; | |||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||
| 103 | |||||||||||||||||||||||
| 104 | 8 | 1; | |||||||||||||||||||||
| 105 | |||||||||||||||||||||||
| 106 | __END__ | ||||||||||||||||||||||