| 1 | package XML::TMX::Reader; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 6 | $XML::TMX::Reader::VERSION = '0.39'; | |||||||||||||||||||||||||||||||||||||||||
| 3 | # ABSTRACT: Perl extension for reading TMX files | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | 6 | ▶ | use 5.010; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 6 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 6 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | 6 | ▶ | use Exporter (); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 9 | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 6 | ▶ | use XML::DT; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | 6 | ▶ | use XML::TMX::Writer; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 12 | 6 | ▶ | use File::BOM qw( open_bom); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 6 | our @ISA = 'Exporter'; | |||||||||||||||||||||||||||||||||||||||||
| 15 | 6 | our @EXPORT_OK = qw(); | |||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | 8 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 19 | 8 | my ($class, $file) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 20 | |||||||||||||||||||||||||||||||||||||||||||
| 21 | 8 | ▶ | return undef unless -f $file; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 22 | 7 | my $self = bless { | |||||||||||||||||||||||||||||||||||||||||
| 23 | encoding => _guess_encoding($file), | ||||||||||||||||||||||||||||||||||||||||||
| 24 | filename => $file, | ||||||||||||||||||||||||||||||||||||||||||
| 25 | ignore_markup => 1, | ||||||||||||||||||||||||||||||||||||||||||
| 26 | } => $class; | ||||||||||||||||||||||||||||||||||||||||||
| 27 | 7 | $self->_parse_header; | |||||||||||||||||||||||||||||||||||||||||
| 28 | 7 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 7 | ▶ | sub _guess_encoding { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_guess_encoding: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | 7 | my $file = shift; | |||||||||||||||||||||||||||||||||||||||||
| 33 | 7 | my $encoding = 'UTF-8'; | |||||||||||||||||||||||||||||||||||||||||
| 34 | 7 | my $enc = open_bom (my $fh, $file, ":utf8"); # or die "can't open $file ($!)"; | |||||||||||||||||||||||||||||||||||||||||
| 35 | 7 | ▶ | $encoding= $enc if $enc; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 36 | 7 | my $line = <$fh>; | |||||||||||||||||||||||||||||||||||||||||
| 37 | 7 | ▶ | if ($line =~ /encoding=['"]([^'"]+)['"]/) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 5 | $encoding = $1; | |||||||||||||||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||||||||||||||||
| 40 | #print STDERR "Debug: defuse.ENC= $enc; enc=$encoding\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 41 | 7 | close $fh; | |||||||||||||||||||||||||||||||||||||||||
| 42 | 7 | return $encoding; | |||||||||||||||||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||||||||||||||||
| 45 | 16 | ▶ | sub _enc2bin{ my $enc=shift; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_enc2bin: called CC=2 SCAR=7.4
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 16 | ▶ | if($enc =~ /utf.*8/i){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | 16 | $enc = "utf8" | |||||||||||||||||||||||||||||||||||||||||
| 48 | } | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | else {$enc = "encoding($enc)"} | |||||||||||||||||||||||||||||||||||||||||
| 50 | 16 | return ":$enc"; | |||||||||||||||||||||||||||||||||||||||||
| 51 | } | ||||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 7 | ▶ | sub _parse_header { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_parse_header: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 54 | 7 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 7 | my $header = ""; | |||||||||||||||||||||||||||||||||||||||||
| 57 | { | ||||||||||||||||||||||||||||||||||||||||||
| 58 | 7 | my $fh; | |||||||||||||||||||||||||||||||||||||||||
| 59 | 7 | local $/ = "<body>"; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 7 | open_bom($fh, $self->{filename},_enc2bin($self->{encoding})) ;# or die "$!"; | |||||||||||||||||||||||||||||||||||||||||
| 61 | #print STDERR "Debug2: defuse.ENC= $!- ; enc=$self->{encoding}\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 62 | 7 | $header = <$fh>; | |||||||||||||||||||||||||||||||||||||||||
| 63 | 7 | close $fh; | |||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | 7 | $header =~ s/^.*(<header)/$1/s; | |||||||||||||||||||||||||||||||||||||||||
| 67 | 7 | $header =~ s/(<\/header>).*$/$1/s; | |||||||||||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||||||||||
| 69 | 7 | $header =~ s!(<header[^/]+/>).*$!$1!s; | |||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||
| 71 | dtstring($header => ( | ||||||||||||||||||||||||||||||||||||||||||
| 72 | 7 | ▶ | 'header' => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 73 | 7 | $self->{header}{$_} = $v{$_} for (keys %v); | |||||||||||||||||||||||||||||||||||||||||
| 74 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 75 | 16 | ▶ | 'prop' => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.1
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 16 | ▶ | $v{type} ||= "_"; | ||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$XML::TMX::Reader::v{"type"} ||= "_"
MC/DC0%0/1
$XML::TMX::Reader::v{"type"} ||= "_"
$XML::TMX::Reader::v{"type"}
Truth table50%1/2
A
A= $XML::TMX::Reader::v{"type"}
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | 16 | push @{$self->{header}{-prop}{$v{type}}}, $c; | |||||||||||||||||||||||||||||||||||||||||
| 78 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 79 | 16 | ▶ | 'note' => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 16 | push @{$self->{header}{-note}}, $c; | |||||||||||||||||||||||||||||||||||||||||
| 81 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 82 | 7 | )); | |||||||||||||||||||||||||||||||||||||||||
| 83 | } | ||||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | |||||||||||||||||||||||||||||||||||||||||||
| 86 | 0 | ▶ | sub ignore_markup { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ignore_markup: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | my ($self, $opt) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | ▶ | $opt = 1 unless defined $opt; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | $self->{ignore_markup} = $opt; | |||||||||||||||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 2 | ▶ | sub languages { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
languages: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 94 | 2 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 95 | 2 | my %languages = (); | |||||||||||||||||||||||||||||||||||||||||
| 96 | $self->for_tu({proc_tu => 100}, | ||||||||||||||||||||||||||||||||||||||||||
| 97 | 13 | ▶ | sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||||||||||||||||||||||||||||||||||
| 98 | 13 | my $tu = shift; | |||||||||||||||||||||||||||||||||||||||||
| 99 | 13 | for ( keys %$tu ) { | |||||||||||||||||||||||||||||||||||||||||
| 100 | 52 | ▶ | $languages{$_}++ unless m/^-/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||
| 102 | 2 | } ); | |||||||||||||||||||||||||||||||||||||||||
| 103 | 2 | return keys %languages; | |||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||||||||||||||||
| 107 | 12 | ▶ | sub _merge_notes { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_merge_notes: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||||||||||||||||
| 108 | 12 | my ($orig, $new) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||
| 110 | 12 | ▶ | $orig //= []; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$orig //= []
MC/DC100%1/1
$orig //= []
$orig
Truth table100%2/2
A
A= $orig
| |||||||||||||||||||||||||||||||||||||||||||
| 111 | 12 | ▶ | $orig = [$orig] unless ref $orig eq "ARRAY"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 112 | 12 | ▶ | $new = [$new] unless ref $new eq "ARRAY"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||||||||||||||||
| 114 | 12 | push @$orig => grep { my $x = $_; !grep { $x eq $_} @$orig } @$new; | |||||||||||||||||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 12 | return $orig; | |||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | 5 | ▶ | sub _merge_props { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_merge_props: called CC=6 SCAR=19.6
| |||||||||||||||||||||||||||||||||||||||||||
| 120 | 5 | my ($orig, $new) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 121 | 5 | ▶ | die "-prop should be hash" if $orig and ref $orig ne "HASH"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$orig and ref $orig ne "HASH"
MC/DC0%0/2
$orig and ref $orig ne "HASH"
$orig
ref $orig ne "HASH"
Truth table66%2/3
A and B
A= $origB= ref $orig ne "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 122 | 5 | ▶ | die "-prop should be hash" if $new and ref $new ne "HASH"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$new and ref $new ne "HASH"
MC/DC0%0/2
$new and ref $new ne "HASH"
$new
ref $new ne "HASH"
Truth table33%1/3
A and B
A= $newB= ref $new ne "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||||||||||||||||
| 124 | 5 | for my $key (keys %$new) { | |||||||||||||||||||||||||||||||||||||||||
| 125 | 6 | $orig->{$key} = _merge_notes($orig->{$key}, $new->{$key}); | |||||||||||||||||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||||||||||||||||
| 127 | 5 | return $orig; | |||||||||||||||||||||||||||||||||||||||||
| 128 | } | ||||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | 4 | ▶ | sub _compute_header { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_compute_header: called CC=3 SCAR=12.3
| |||||||||||||||||||||||||||||||||||||||||||
| 131 | 4 | my ($current, $conf) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 132 | 4 | my %header = %$current; | |||||||||||||||||||||||||||||||||||||||||
| 133 | 4 | ▶ | if (exists($conf->{-note})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | $header{-note} = _merge_notes($header{-note}, $conf->{-note}); | |||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||
| 136 | 4 | ▶ | if (exists($conf->{-prop})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | $header{-prop} = _merge_props($header{-prop}, $conf->{-prop}); | |||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||
| 139 | 4 | return \%header; | |||||||||||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||||||||||||||||
| 142 | 9 | ▶ | sub for_tu { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
for_tu: called CC=36 SCAR=45.3
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 143 | 9 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 144 | 9 | my $conf = { -header => 1 }; | |||||||||||||||||||||||||||||||||||||||||
| 145 | 9 | my $i = 0; | |||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | 9 | ▶ | ref($_[0]) eq "HASH" and $conf = {%$conf , %{shift(@_)}}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||||||||||||||||
| 149 | 9 | my $code = shift; | |||||||||||||||||||||||||||||||||||||||||
| 150 | 9 | ▶ | die "invalid processor" unless ref($code) eq "CODE"; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 151 | |||||||||||||||||||||||||||||||||||||||||||
| 152 | 9 | local $/; | |||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||
| 154 | 9 | my $outputingTMX = 0; | |||||||||||||||||||||||||||||||||||||||||
| 155 | 9 | my $tmx; | |||||||||||||||||||||||||||||||||||||||||
| 156 | my $data; | ||||||||||||||||||||||||||||||||||||||||||
| 157 | 9 | my $gen=0; | |||||||||||||||||||||||||||||||||||||||||
| 158 | my %h = ( | ||||||||||||||||||||||||||||||||||||||||||
| 159 | -type => { tu => 'SEQ', tuv => 'SEQ' }, | ||||||||||||||||||||||||||||||||||||||||||
| 160 | 59 | ▶ | tu => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=13 SCAR=28.1
| |||||||||||||||||||||||||||||||||||||||||||
| 161 | 59 | my $tu; | |||||||||||||||||||||||||||||||||||||||||
| 162 | 59 | for my $va (@$c) { | |||||||||||||||||||||||||||||||||||||||||
| 163 | 306 | ▶ | if ($va->[0] eq "-prop") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 164 | 87 | push @{$tu->{$va->[0]}{$va->[1]}}, $va->[2] | |||||||||||||||||||||||||||||||||||||||||
| 165 | } elsif ($va->[0] eq "-note") { | ||||||||||||||||||||||||||||||||||||||||||
| 166 | 101 | push @{$tu->{$va->[0]}}, $va->[1] | |||||||||||||||||||||||||||||||||||||||||
| 167 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 168 | 118 | $tu->{$va->[0]} = $va->[1] | |||||||||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||||||||||||||||
| 171 | 59 | my ($ans, $v) = $code->($tu, \%v); | |||||||||||||||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||||||||||||||||
| 173 | # Check if the user wants to create a TMX and | ||||||||||||||||||||||||||||||||||||||||||
| 174 | # forgot to say us | ||||||||||||||||||||||||||||||||||||||||||
| 175 | 59 | ▶ | if (!$outputingTMX && $ans && ref($ans) eq "HASH") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition83%5/6
not $outputingTMX and $ans and ref $ans eq "HASH"
not $outputingTMX and $ans
MC/DC0%0/3
not $outputingTMX and $ans and ref $ans eq "HASH"
not $outputingTMX
$ans
ref $ans eq "HASH"
Truth table75%3/4
not(A) and B and C
A= not $outputingTMXB= $ansC= ref $ans eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | $outputingTMX = 1; | |||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | $tmx = XML::TMX::Writer->new(); | |||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | ▶ | if ($conf->{-header}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | my $header = _compute_header($self->{header}, $conf); | |||||||||||||||||||||||||||||||||||||||||
| 180 | 0 | $tmx->start_tmx(encoding => $self->{encoding}, %$header); | |||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||
| 183 | # Add the translation unit | ||||||||||||||||||||||||||||||||||||||||||
| 184 | 59 | ▶ | if ($ans && ref($ans) eq "HASH") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$ans and ref $ans eq "HASH"
MC/DC100%2/2
$ans and ref $ans eq "HASH"
$ans
ref $ans eq "HASH"
Truth table100%3/3
A and B
A= $ansB= ref $ans eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 185 | 20 | $gen++; | |||||||||||||||||||||||||||||||||||||||||
| 186 | 20 | ▶ | %v = %$v if ($v && ref($v) eq "HASH"); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$v and ref $v eq "HASH"
MC/DC0%0/2
$v and ref $v eq "HASH"
$v
ref $v eq "HASH"
Truth table33%1/3
A and B
A= $vB= ref $v eq "HASH"
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | |||||||||||||||||||||||||||||||||||||||||||
| 188 | 20 | my %ans = (%v, %$ans); | |||||||||||||||||||||||||||||||||||||||||
| 189 | 20 | ▶ | $ans{"-n"}=$i if $conf->{n} ; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 190 | 20 | $tmx->add_tu(-verbatim => $conf->{-verbatim}, %ans); | |||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||
| 192 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||
| 194 | 118 | ▶ | tuv => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=7 SCAR=20.8
| |||||||||||||||||||||||||||||||||||||||||||
| 195 | 118 | my $tuv; | |||||||||||||||||||||||||||||||||||||||||
| 196 | 118 | for my $v (@$c) { | |||||||||||||||||||||||||||||||||||||||||
| 197 | 154 | ▶ | if ($v->[0] eq "-prop") { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 198 | 18 | push @{$tuv->{$v->[0]}{$v->[1]}}, $v->[2] | |||||||||||||||||||||||||||||||||||||||||
| 199 | } elsif ($v->[0] eq "-note") { | ||||||||||||||||||||||||||||||||||||||||||
| 200 | 18 | push @{$tuv->{$v->[0]}}, $v->[1] | |||||||||||||||||||||||||||||||||||||||||
| 201 | } elsif ($v->[0] eq "-cdata") { | ||||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | $tuv->{-iscdata} = 1; | |||||||||||||||||||||||||||||||||||||||||
| 203 | 0 | $tuv->{-seg} = $v->[1]; | |||||||||||||||||||||||||||||||||||||||||
| 204 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 205 | 118 | $tuv->{-seg} = $v->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||||||||||||||||
| 207 | } | ||||||||||||||||||||||||||||||||||||||||||
| 208 | 118 | ▶ | [ $v{lang} || $v{'xml:lang'} || "_" => $tuv ] | ||||||||||||||||||||||||||||||||||||||||
|
Condition40%2/5
$XML::TMX::Reader::v{'lang'} || $XML::TMX::Reader::v{'xml:lang'} || '_'
$XML::TMX::Reader::v{"lang"} or $XML::TMX::Reader::v{"xml:lang"}
MC/DC0%0/2
$XML::TMX::Reader::v{'lang'} || $XML::TMX::Reader::v{'xml:lang'} || '_'
$XML::TMX::Reader::v{"lang"}
$XML::TMX::Reader::v{"xml:lang"}
Truth table33%1/3
A or B
A= $XML::TMX::Reader::v{"lang"}B= $XML::TMX::Reader::v{"xml:lang"}
| |||||||||||||||||||||||||||||||||||||||||||
| 209 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 210 | 105 | ▶ | prop => sub { ["-prop", $v{type} || "_", $c] }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
Condition50%1/2
$XML::TMX::Reader::v{'type'} || '_'
MC/DC0%0/1
$XML::TMX::Reader::v{'type'} || '_'
$XML::TMX::Reader::v{'type'}
Truth table50%1/2
A
A= $XML::TMX::Reader::v{'type'}
| |||||||||||||||||||||||||||||||||||||||||||
| 211 | 119 | ▶ | note => sub { ["-note" , $c] }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | 118 | ▶ | seg => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=2 SCAR=7.6
| |||||||||||||||||||||||||||||||||||||||||||
| 213 | 118 | ▶ | return ($v{iscdata}) ? [ -cdata => $c ] : [ $c ] | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 214 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | ▶ | -cdata => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | father->{'iscdata'} = 1; $c }, | |||||||||||||||||||||||||||||||||||||||||
| 217 | 0 | ▶ | hi => sub { $self->{ignore_markup}?$c:toxml }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | ▶ | ph => sub { $self->{ignore_markup}?$c:toxml }, | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | 9 | ); | |||||||||||||||||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | 9 | $/ = "\n"; | |||||||||||||||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||||||||||||||||
| 224 | 9 | $h{-outputenc} = $h{-inputenc} = $self->{encoding}; | |||||||||||||||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||||||||||||||||
| 226 | 9 | my $resto = ""; | |||||||||||||||||||||||||||||||||||||||||
| 227 | ## Go through the header... | ||||||||||||||||||||||||||||||||||||||||||
| 228 | 9 | my $fh; | |||||||||||||||||||||||||||||||||||||||||
| 229 | 9 | open_bom($fh, $self->{filename},_enc2bin($self->{encoding})) ;# or die "$!"; | |||||||||||||||||||||||||||||||||||||||||
| 230 | #print STDERR "Debug2: defuse.ENC= $! ; enc=" ,_enc2bin($self->{encoding}),"\n"; | ||||||||||||||||||||||||||||||||||||||||||
| 231 | 9 | ▶ | while (<$fh>) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 232 | 87 | ▶ | next if /^\s*$/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 233 | 75 | ▶ | last if /<body\b/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 234 | } | ||||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | 9 | ▶ | if (m!(.*?)(<body.*?>)(.*)!s) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 237 | 9 | $resto = $3; | |||||||||||||||||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||||||||||||||||
| 241 | # If we have an output filename, user wants to output a TMX | ||||||||||||||||||||||||||||||||||||||||||
| 242 | 9 | ▶ | $conf->{-output} = $conf->{output} if defined($conf->{output}); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 243 | 9 | ▶ | if (defined($conf->{-output})) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | 4 | $outputingTMX = 1; | |||||||||||||||||||||||||||||||||||||||||
| 245 | 4 | $tmx = XML::TMX::Writer->new(); | |||||||||||||||||||||||||||||||||||||||||
| 246 | 4 | ▶ | if ($conf->{-header}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 247 | 4 | my $header = _compute_header($self->{header}, $conf); | |||||||||||||||||||||||||||||||||||||||||
| 248 | $tmx->start_tmx(encoding => $self->{encoding}, | ||||||||||||||||||||||||||||||||||||||||||
| 249 | -output => $conf->{-output}, | ||||||||||||||||||||||||||||||||||||||||||
| 250 | 4 | %$header); | |||||||||||||||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||||||||||||||||
| 252 | } | ||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||
| 254 | 9 | $/ = "</tu>"; | |||||||||||||||||||||||||||||||||||||||||
| 255 | 9 | ▶ | $conf->{-verbose}++ if $conf->{verbose}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | 9 | ▶ | print STDERR "." if $conf->{-verbose}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 257 | 9 | ▶ | while (<$fh>) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | 68 | ▶ | ($_ = $resto . $_ and $resto = "" ) if $resto; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition50%3/6
$resto && (($_ = $resto . $_) && ($resto = ''))
$_ = $resto . $_ and $resto = ""
MC/DC0%0/3
$resto && (($_ = $resto . $_) && ($resto = ''))
$resto
$_ = $resto . $_
$resto = ""
Truth table0%0/4
A && B and C
A= $restoB= $_ = $resto . $_C= $resto = ""
| |||||||||||||||||||||||||||||||||||||||||||
| 259 | 68 | ▶ | last if /<\/body>/; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 260 | 60 | $i++; | |||||||||||||||||||||||||||||||||||||||||
| 261 | 60 | ▶ | print STDERR "\r$i" if $conf->{-verbose} && !($i % 10); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$conf->{"-verbose"} and not $i % 10
MC/DC0%0/2
$conf->{"-verbose"} and not $i % 10
$conf->{"-verbose"}
not $i % 10
Truth table33%1/3
A and not(B)
A= $conf->{"-verbose"}B= not $i % 10
| |||||||||||||||||||||||||||||||||||||||||||
| 262 | 60 | ▶ | last if defined $conf->{proc_tu} && $i > $conf->{proc_tu} ; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
defined $conf->{"proc_tu"} and $i > $conf->{"proc_tu"}
MC/DC100%2/2
defined $conf->{"proc_tu"} and $i > $conf->{"proc_tu"}
defined $conf->{"proc_tu"}
$i > $conf->{"proc_tu"}
Truth table100%3/3
A and B
A= defined $conf->{"proc_tu"}B= $i > $conf->{"proc_tu"}
| |||||||||||||||||||||||||||||||||||||||||||
| 263 | 59 | ▶ | last if defined $conf->{gen_tu} && $gen > $conf->{gen_tu}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
defined $conf->{"gen_tu"} and $gen > $conf->{"gen_tu"}
MC/DC0%0/2
defined $conf->{"gen_tu"} and $gen > $conf->{"gen_tu"}
defined $conf->{"gen_tu"}
$gen > $conf->{"gen_tu"}
Truth table66%2/3
A and B
A= defined $conf->{"gen_tu"}B= $gen > $conf->{"gen_tu"}
| |||||||||||||||||||||||||||||||||||||||||||
| 264 | # next if defined $conf->{patt} && !m/$conf->{patt}/ ; | ||||||||||||||||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||||||||||||||||
| 266 | 59 | ▶ | if (defined $conf->{patt}){ ## FIXME untested | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | ▶ | if(ref($conf->{patt})){ ## EN=>/cat/ PT=>/gato/ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 268 | 0 | my $ok = 1; | |||||||||||||||||||||||||||||||||||||||||
| 269 | 0 | my $textli = ""; | |||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | for my $li (keys %{$conf->{patt}}){ | |||||||||||||||||||||||||||||||||||||||||
| 271 | 0 | my $patli= $conf->{patt}{$li}; | |||||||||||||||||||||||||||||||||||||||||
| 272 | 0 | ▶ | if (m!lang=["']$li['"](.*?)</tuv>!is ) { $textli = $1 }; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | ▶ | $ok &&= ($textli =~ /$patli/) | ||||||||||||||||||||||||||||||||||||||||
|
Condition0%0/3
$ok &&= $textli =~ /$patli/
MC/DC0%0/2
$ok &&= $textli =~ /$patli/
$ok
$textli =~ /$patli/
Truth table0%0/3
A &&= B
A= $okB= $textli =~ /$patli/
| |||||||||||||||||||||||||||||||||||||||||||
| 274 | } | ||||||||||||||||||||||||||||||||||||||||||
| 275 | 0 | ▶ | next unless $ok | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||||||||||||||||
| 277 | else { ## /cat.*/ | ||||||||||||||||||||||||||||||||||||||||||
| 278 | 0 | ▶ | next if not m/$conf->{patt}/ ; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||||||||||||||||
| 280 | } | ||||||||||||||||||||||||||||||||||||||||||
| 281 | #### | ||||||||||||||||||||||||||||||||||||||||||
| 282 | # This can't be done. Not sure why it was being done. | ||||||||||||||||||||||||||||||||||||||||||
| 283 | # So, please, unless you know the implications for tagged crpora | ||||||||||||||||||||||||||||||||||||||||||
| 284 | # do not uncomment it. | ||||||||||||||||||||||||||||||||||||||||||
| 285 | # s/\>\s+/>/; | ||||||||||||||||||||||||||||||||||||||||||
| 286 | 59 | undef($data); | |||||||||||||||||||||||||||||||||||||||||
| 287 | 59 | ▶ | if ($conf->{'-raw'}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | my $ans = $code->($_); | |||||||||||||||||||||||||||||||||||||||||
| 289 | 0 | ▶ | if ($conf->{-output}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 290 | 0 | ▶ | $ans->{"-n"}=$i if $conf->{n} ; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 291 | 0 | $tmx->add_tu(-raw => $ans); | |||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||
| 293 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 294 | 59 | eval { dtstring($_, %h) } ; ## dont die in invalid XML | |||||||||||||||||||||||||||||||||||||||||
| 295 | 59 | ▶ | warn $@ if $@; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||||||||||||||||
| 298 | 9 | ▶ | print STDERR "\r$i\n" if $conf->{-verbose}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 299 | 9 | close $fh; | |||||||||||||||||||||||||||||||||||||||||
| 300 | |||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||
| 302 | 9 | ▶ | $tmx->end_tmx if $conf->{-header} && $outputingTMX; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
$conf->{"-header"} and $outputingTMX
MC/DC50%1/2
$conf->{"-header"} and $outputingTMX
$conf->{"-header"}
$outputingTMX
Truth table66%2/3
A and B
A= $conf->{"-header"}B= $outputingTMX
| |||||||||||||||||||||||||||||||||||||||||||
| 303 | } | ||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||||||||||||||||
| 306 | 0 | ▶ | sub to_html { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
to_html: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 307 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | my %opt = @_; | |||||||||||||||||||||||||||||||||||||||||
| 309 | 0 | my @ls=$self->languages; | |||||||||||||||||||||||||||||||||||||||||
| 310 | 0 | my $html="<table><tr>". join("\n",map{"<td>$_</td>"} @ls) ."</tr>\n"; | |||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | ▶ | $self->for_tu(sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||
| 312 | 0 | my ($langs, $opts) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 313 | 0 | my $ret = ""; # "<table>"; | |||||||||||||||||||||||||||||||||||||||||
| 314 | 0 | for (@ls) { | |||||||||||||||||||||||||||||||||||||||||
| 315 | 0 | ▶ | if( defined $langs->{$_}){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 316 | 0 | $ret .= "\n\t<td l='$_'>$langs->{$_}{-seg}</td>" | |||||||||||||||||||||||||||||||||||||||||
| 317 | } | ||||||||||||||||||||||||||||||||||||||||||
| 318 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | $ret .= "\n\t<td l='$_'></td>" | |||||||||||||||||||||||||||||||||||||||||
| 320 | } | ||||||||||||||||||||||||||||||||||||||||||
| 321 | } | ||||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||
| 323 | #if ($opt{icons}) { | ||||||||||||||||||||||||||||||||||||||||||
| 324 | # $ret .= "<img src=\"/icons/flags/".lc($_).".png\" alt=\"$_\"/>" | ||||||||||||||||||||||||||||||||||||||||||
| 325 | # } else { | ||||||||||||||||||||||||||||||||||||||||||
| 326 | # $ret .= "$_" | ||||||||||||||||||||||||||||||||||||||||||
| 327 | # } | ||||||||||||||||||||||||||||||||||||||||||
| 328 | # $ret .= "</td><td>$langs->{$_}{-seg}</td></tr>\n" | ||||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | $html.= "<tr>$ret\n</tr>\n"; | |||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | return "" | |||||||||||||||||||||||||||||||||||||||||
| 331 | } | ||||||||||||||||||||||||||||||||||||||||||
| 332 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | return $html; | |||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||
| 335 | |||||||||||||||||||||||||||||||||||||||||||
| 336 | 0 | ▶ | sub for_tu2 { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
for_tu2: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 337 | 0 | warn "Please update your code to use 'for_tu'\n"; | |||||||||||||||||||||||||||||||||||||||||
| 338 | 0 | &for_tu; | |||||||||||||||||||||||||||||||||||||||||
| 339 | } | ||||||||||||||||||||||||||||||||||||||||||
| 340 | |||||||||||||||||||||||||||||||||||||||||||
| 341 | |||||||||||||||||||||||||||||||||||||||||||
| 342 | 6 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 343 | |||||||||||||||||||||||||||||||||||||||||||
| 344 | __END__ | ||||||||||||||||||||||||||||||||||||||||||