lib/Serge/Engine/Plugin/Transform/endpunc.pm

filter: Statementstmt 27.7% 10 / 36 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 42.8% 3 / 7 Podpod 0.0% 0 / 3 totaltotal 20.6% 13 / 63 SCAR 37.2
CC
8
Cov
20%
transform
72.0
name
2.0
filter_key
2.0
CRAP 41.3
« lib/Serge/Engine/Job.pm ↑ Summary lib/Serge/Sync/Plugin/TranslationService/pootle.pm »
1 package Serge::Engine::Plugin::Transform::endpunc;
2 1 ▶use parent Serge::Engine::Plugin::Base::Transform;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 sub name {
8 0 ▶ return 'End punctuation plugin';
Subroutine name: not called CC=1 SCAR=6.9
Pod undocumented
9 }
10  
11 sub filter_key {
12 0 ▶ my ($self, $s) = @_;
Subroutine filter_key: not called CC=1 SCAR=6.9
Pod undocumented
13 0 $s =~ s/[^\w\d\]\)\>]+$//; # remove all trailing non-character symbols
14 0 return $s;
15 }
16  
17 sub transform {
18 0 ▶ my ($self, $s, $target, $lang) = @_;
Subroutine transform: not called CC=8 SCAR=42.8
Pod undocumented
19  
20 0 my $sourcepunc = '';
21 0 ▶ if ($s =~ m/([^\w\d\]\)\>]+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /([^\w\d\]\)\>]+)$/) 0 0 0
22 0 $sourcepunc = $1;
23 }
24  
25 0 my $targetpunc = '';
26 0 ▶ if ($target =~ m/([^\w\d\]\)\>]+)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($target =~ /([^\w\d\]\)\>]+)$/) 0 0 0
27 0 $targetpunc = $1;
28 }
29  
30 0 ▶ if ($sourcepunc eq $targetpunc && $targetpunc eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($sourcepunc eq $targetpunc and $targetpunc eq "") 0 0 0
Condition0%0/3
$sourcepunc eq $targetpunc and $targetpunc eq ""
!ll&&!rl&&r
000
MC/DC0%0/2
$sourcepunc eq $targetpunc and $targetpunc eq ""
$sourcepunc eq $targetpunc $targetpunc eq ""
Truth table0%0/3
A and B
A= $sourcepunc eq $targetpuncB= $targetpunc eq ""
ABresult
0X0
100
111
31 # try to get rid of the trailing tags and whitespace to get the actual punctuation
32 0 my $filtered_target = $target;
33 0 $filtered_target =~ s/\s*<[^<>]+>\s*$//s;
34 0 ▶ if ($filtered_target ne $target) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filtered_target ne $target) 0 0 0
35 0 return $self->transform($s, $filtered_target, $lang);
36 }
37 }
38  
39 0 ▶ if ($sourcepunc ne $targetpunc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sourcepunc ne $targetpunc) 0 0 0
40 # In Japanese, replace certain punctuation symbols
41 0 ▶ if ($lang =~ m/^(ja|ja-.*)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($lang =~ /^(ja|ja-.*)$/) 0 0 0
42 0 $targetpunc = _adjust_japanese_punctuation($targetpunc);
43 }
44  
45 0 $s =~ s/[^\w\d\]\)\>]*$/$targetpunc/e;
46 }
47  
48 0 return $s;
49 }
50  
51 sub _adjust_japanese_punctuation {
52 0 ▶ my $s = shift;
Subroutine _adjust_japanese_punctuation: not called CC=1 SCAR=6.9
53 0 $s =~ s/\.{3}/…/g;
54 0 $s =~ tr/.?!/。?!/;
55 0 return $s;
56 }
57  
58 1 1;
« lib/Serge/Engine/Job.pm ↑ Summary lib/Serge/Sync/Plugin/TranslationService/pootle.pm »