Locale/Msgfmt/po.pm

filter: Statementstmt 92.5% 74 / 80 Branchbran 88.8% 32 / 36 Conditioncond 72.7% 8 / 11 MC/DCmcdc 50.0% 3 / 6 Subroutinesub 100% 9 / 9 Podpod 0.0% 0 / 5 totaltotal 85.7% 126 / 147 CC 23 SCAR 22.6
CC
23
Cov
90%
read_po
14.8
add_string
9.0
new
2.1
CRAP 9.6
« Locale/Msgfmt.pm ↑ Summary Locale/Msgfmt/mo.pm »
1 package Locale::Msgfmt::po;
2  
3 4 ▶use 5.008005;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 4 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 4 ▶use Locale::Msgfmt::Utils ();
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 4 our $VERSION = '0.15';
9  
10 15 ▶sub new {
Subroutine new: called CC=2 SCAR=7.2
Pod undocumented
11 15 my $class = shift;
12 15 ▶ return bless shift || {}, $class;
Condition50%1/2
shift() || {}
l!l
150
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
Aresult
11
00
13 }
14  
15 893 ▶sub cleanup_string {
Subroutine cleanup_string: called CC=1 SCAR=0.0
Pod undocumented
16 893 my $str = shift;
17 893 $str =~ s/\\n/\n/g;
18 893 $str =~ s/\\r/\r/g;
19 893 $str =~ s/\\t/\t/g;
20 893 $str =~ s/\\"/"/g;
21 893 $str =~ s/\\\\/\\/g;
22 893 return $str;
23 }
24  
25 468 ▶sub add_string {
Subroutine add_string: called CC=9 SCAR=22.0
Pod undocumented
26 468 my $self = shift;
27 468 my $hash = shift;
28 468 my %h = %{$hash};
29 468 ▶ return if !( defined( $h{msgid} ) && defined( $h{msgstr} ) );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $h{"msgid"} and defined $h{"msgstr"} 6 462 468
Condition66%2/3
defined $h{"msgid"} and defined $h{"msgstr"}
!ll&&!rl&&r
60462
MC/DC50%1/2
defined $h{"msgid"} and defined $h{"msgstr"}
defined $h{"msgid"} defined $h{"msgstr"}
Truth table66%2/3
A and B
A= defined $h{"msgid"}B= defined $h{"msgstr"}
ABresult
0X0
100
111
30 462 ▶ return if ( $h{fuzzy} && !$self->{fuzzy} && length( $h{msgid} ) > 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $h{"fuzzy"} and not $self->{"fuzzy"} and length $h{"msgid"} > 0 9 453 462
Condition83%5/6
$h{"fuzzy"} and not $self->{"fuzzy"} and length $h{"msgid"} > 0
!ll&&!rl&&r
45309
$h{"fuzzy"} and not $self->{"fuzzy"}
!ll&&!rl&&r
45039
MC/DC66%2/3
$h{"fuzzy"} and not $self->{"fuzzy"} and length $h{"msgid"} > 0
$h{"fuzzy"} not $self->{"fuzzy"} length $h{"msgid"} > 0
Truth table75%3/4
A and not(B) and C
A= $h{"fuzzy"}B= not $self->{"fuzzy"}C= length $h{"msgid"} > 0
ABCresult
0XX0
10X0
1100
1111
31 453 my $msgstr = join Locale::Msgfmt::Utils::null(), @{ $h{msgstr} };
32 453 ▶ return if ( $msgstr eq "" );
Branch: 1 branch
BranchTrueFalseTotal
if $msgstr eq "" 8 445 453
33 445 my $context;
34 my $plural;
35  
36 445 ▶ if ( $h{msgctxt} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($h{'msgctxt'}) { } 2 443 445
37 2 $context = cleanup_string( $h{msgctxt} ) . Locale::Msgfmt::Utils::eot();
38 } else {
39 443 $context = "";
40 }
41 445 ▶ if ( $h{msgid_plural} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($h{'msgid_plural'}) { } 1 444 445
42 1 $plural = Locale::Msgfmt::Utils::null() . cleanup_string( $h{msgid_plural} );
43 } else {
44 444 $plural = "";
45 }
46 445 $self->{mo}->add_string( $context . cleanup_string( $h{msgid} ) . $plural, cleanup_string($msgstr) );
47 }
48  
49 15 ▶sub read_po {
Subroutine read_po: called CC=14 SCAR=26.9
Pod undocumented
50 15 my $self = shift;
51 15 my $pofile = shift;
52 15 my $mo = $self->{mo};
53 15 ▶ open my $F, '<', $pofile or die "Could not open ($pofile) $!";
Branch: 1 branch
BranchTrueFalseTotal
open my $F, "<", $pofile or die "Could not open ($pofile) $!" 15 0 15
54 15 my %h = ();
55 15 my $type;
56 15 ▶ while (<$F>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $F)) 1962 15 1977
57 1962 s/\r\n/\n/;
58 1962 ▶ if (/^(msgid(?:|_plural)|msgctxt) +"(.*)" *$/) {
Branch: 5 branches
BranchTrueFalseTotal
if (/^(msgid(?:|_plural)|msgctxt) +"(.*)" *$/) { } 465 1497 1962
elsif (/^msgstr(?:\[(\d*)\])? +"(.*)" *$/) { } 463 1034 1497
elsif (/^"(.*)" *$/) { } 60 974 1034
elsif (/^ *$/) { } 453 521 974
elsif (/^#/) { } 521 0 521
59 465 $type = $1;
60 465 ▶ if ( defined( $h{$type} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $h{$type}) 0 465 465
61 0 $self->add_string( \%h );
62 0 %h = ();
63 }
64 465 $h{$type} = $2;
65 } elsif (/^msgstr(?:\[(\d*)\])? +"(.*)" *$/) {
66 463 $type = "msgstr";
67 463 ▶ if ( !$h{$type} ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($h{$type}) 462 1 463
68 462 @{ $h{$type} } = ();
69 }
70 463 push @{ $h{$type} }, $2;
71 } elsif (/^"(.*)" *$/) {
72 60 ▶ if ( $type eq "msgstr" ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'msgstr') { } 34 26 60
73 34 @{ $h{$type} }[ scalar( @{ $h{$type} } ) - 1 ] .= $1;
74 } else {
75 26 $h{$type} .= $1;
76 }
77 } elsif (/^ *$/) {
78 453 $self->add_string( \%h );
79 453 %h = ();
80 453 $type = undef;
81 } elsif (/^#/) {
82 521 ▶ if (/^#, fuzzy/) {
Branch: 2 branches
BranchTrueFalseTotal
if (/^#, fuzzy/) { } 12 509 521
elsif (/^#:/) { } 454 55 509
83 12 $h{fuzzy} = 1;
84 } elsif (/^#:/) {
85 454 ▶ if ( defined( $h{msgid} ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $h{"msgid"}) 0 454 454
86 0 $self->add_string( \%h );
87 0 %h = ();
88 0 $type = undef;
89 }
90 }
91 } else {
92 0 die( "unknown line: " . $_ );
93 }
94 }
95 15 $self->add_string( \%h );
96 15 close $F;
97 }
98  
99 15 ▶sub parse {
Subroutine parse: called CC=1 SCAR=0.0
Pod undocumented
100 15 my $self = shift;
101 15 my ( $pofile, $mo ) = @_;
102 15 $self->{mo} = $mo;
103 15 $self->read_po($pofile);
104 }
105  
106 4 1;
107  
108 __END__
« Locale/Msgfmt.pm ↑ Summary Locale/Msgfmt/mo.pm »