Babelfish/Phrase/PluralFormsParser.pm

filter: Statementstmt 100% 44 / 44 Branchbran 75.0% 6 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 100% 3 / 3 totaltotal 96.8% 62 / 64 CC 6 SCAR 9.5
CC
6
Cov
96%
parse
5.0
new
2.0
BEGIN
1.0
CRAP 2.6
« Babelfish/Phrase/Compiler.pm ↑ Summary Babelfish/Phrase/ParserBase.pm »
1 package Locale::Babelfish::Phrase::PluralFormsParser;
2  
3 # ABSTRACT: Babelfish plurals syntax parser.
4  
5 7 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 7 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 7 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 7 ▶use feature 'state';
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 7 ▶use Locale::Babelfish::Phrase::Parser ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12  
13 7 our $VERSION = '2.13'; # VERSION
14  
15 7 ▶use parent qw( Class::Accessor::Fast );
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 7 __PACKAGE__->mk_accessors( qw( phrase strict_forms regular_forms ) );
18  
19  
20 292 ▶sub new {
Subroutine new: called CC=2 SCAR=7.0
Pod documented
21 292 my ( $class, $phrase ) = @_;
22 292 my $parser = bless {}, $class;
23 292 ▶ $parser->init( $phrase ) if defined $phrase;
Branch: 1 branch
BranchTrueFalseTotal
if defined $phrase 0 292 292
24 292 return $parser;
25 }
26  
27  
28 35 ▶sub init {
Subroutine init: called CC=1 SCAR=0.0
Pod documented
29 35 my ( $self, $phrase ) = @_;
30 35 $self->phrase( $phrase );
31 35 $self->regular_forms( [] );
32 35 $self->strict_forms( {} );
33 35 return $self;
34 }
35  
36  
37 34 ▶sub parse {
Subroutine parse: called CC=5 SCAR=16.1
Pod documented
38 34 my ( $self, $phrase ) = @_;
39  
40 34 ▶ $self->init( $phrase ) if defined $phrase;
Branch: 1 branch
BranchTrueFalseTotal
if defined $phrase 34 0 34
41 34 state $phrase_parser = Locale::Babelfish::Phrase::Parser->new();
42  
43 # тут проще регуляркой
44 34 my @forms = split( m/(?<!\\)\|/s, $phrase );
45  
46 34 for my $form ( @forms ) {
47 92 my $value = undef;
48 92 ▶ if ( $form =~ m/\A=([0-9]+)\p{PerlSpace}*(.+)\z/s ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($form =~ /\A=([0-9]+)\p{PerlSpace}*(.+)\z/s) 7 85 92
49 7 ( $value, $form ) = ( $1, $2 );
50 }
51 92 $form = $phrase_parser->parse( $form );
52  
53 92 ▶ if ( defined $value ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $value) { } 7 85 92
54 7 $self->strict_forms->{$value} = $form;
55 }
56 else {
57 85 push @{ $self->regular_forms }, $form;
58 }
59 }
60  
61 return {
62 34 strict => $self->strict_forms,
63 regular => $self->regular_forms,
64 };
65 }
66  
67 7 1;
68  
69 __END__
« Babelfish/Phrase/Compiler.pm ↑ Summary Babelfish/Phrase/ParserBase.pm »