| 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() || {}
MC/DC0%0/1
shift() || {}
shift()
Truth table50%1/2
A
A= shift()
| |||||||||||||||||||||||||||||||||||||||||||
| 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
Condition66%2/3
defined $h{"msgid"} and defined $h{"msgstr"}
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"}
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 462 | ▶ | return if ( $h{fuzzy} && !$self->{fuzzy} && length( $h{msgid} ) > 0 ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
$h{"fuzzy"} and not $self->{"fuzzy"} and length $h{"msgid"} > 0
$h{"fuzzy"} and not $self->{"fuzzy"}
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
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 453 | my $msgstr = join Locale::Msgfmt::Utils::null(), @{ $h{msgstr} }; | |||||||||||||||||||||||||||||||||||||||||
| 32 | 453 | ▶ | return if ( $msgstr eq "" ); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 33 | 445 | my $context; | |||||||||||||||||||||||||||||||||||||||||
| 34 | my $plural; | ||||||||||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 445 | ▶ | if ( $h{msgctxt} ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 15 | my %h = (); | |||||||||||||||||||||||||||||||||||||||||
| 55 | 15 | my $type; | |||||||||||||||||||||||||||||||||||||||||
| 56 | 15 | ▶ | while (<$F>) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 1962 | s/\r\n/\n/; | |||||||||||||||||||||||||||||||||||||||||
| 58 | 1962 | ▶ | if (/^(msgid(?:|_plural)|msgctxt) +"(.*)" *$/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 59 | 465 | $type = $1; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 465 | ▶ | if ( defined( $h{$type} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 68 | 462 | @{ $h{$type} } = (); | |||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||
| 70 | 463 | push @{ $h{$type} }, $2; | |||||||||||||||||||||||||||||||||||||||||
| 71 | } elsif (/^"(.*)" *$/) { | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 60 | ▶ | if ( $type eq "msgstr" ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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
| |||||||||||||||||||||||||||||||||||||||||||
| 83 | 12 | $h{fuzzy} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 84 | } elsif (/^#:/) { | ||||||||||||||||||||||||||||||||||||||||||
| 85 | 454 | ▶ | if ( defined( $h{msgid} ) ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 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__ | ||||||||||||||||||||||||||||||||||||||||||