lib/Serge/Engine/Plugin/replace_strings.pm

filter: Statementstmt 28.2% 13 / 46 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 36.3% 4 / 11 Podpod 0.0% 0 / 7 totaltotal 19.7% 17 / 86 SCAR 42.8
CC
11
Cov
20%
validate_data
42.0
process_then_block
30.0
adjust_phases
6.0
CRAP 72.2
« lib/Serge/Engine/Plugin/test_language.pm ↑ Summary lib/Serge/Sync/Plugin/TranslationService/command.pm »
1 package Serge::Engine::Plugin::replace_strings;
2 1 ▶use parent Serge::Engine::Plugin::if;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶no warnings qw(uninitialized);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 1 ▶use Serge::Util qw(subst_macros_strref);
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 sub name {
11 0 ▶ return 'Generic string replacement plugin';
Subroutine name: not called CC=1 SCAR=6.9
Pod undocumented
12 }
13  
14 sub init {
15 0 ▶ my $self = shift;
Subroutine init: not called CC=1 SCAR=6.9
Pod undocumented
16  
17 0 $self->SUPER::init(@_);
18  
19 0 $self->merge_schema({
20 replace => {'' => 'LIST',
21 '*' => 'ARRAY'
22 },
23 if => {
24 '*' => {
25 then => {
26 replace => {'' => 'LIST',
27 '*' => 'ARRAY'
28 },
29 },
30 },
31 },
32 });
33  
34 0 $self->add({
35 after_load_file => \&check,
36 before_save_localized_file => \&check,
37 rewrite_source => \&check,
38 rewrite_translation => \&check,
39 rewrite_path => \&rewrite_path,
40 rewrite_relative_output_file_path => \&rewrite_path,
41 rewrite_absolute_output_file_path => \&rewrite_path,
42 rewrite_relative_ts_file_path => \&rewrite_path,
43 rewrite_absolute_ts_file_path => \&rewrite_path
44 });
45 }
46  
47 sub validate_data {
48 0 ▶ my ($self) = @_;
Subroutine validate_data: not called CC=6 SCAR=37.4
Pod undocumented
49  
50 0 $self->SUPER::validate_data;
51  
52 0 ▶ die "'replace' parameter is not specified and no 'if' blocks found" if !exists $self->{data}->{if} && !$self->{data}->{replace};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"data"}{"if"} or $self->{"data"}{"replace"} 0 0 0
Condition0%0/3
exists $self->{"data"}{"if"} or $self->{"data"}{"replace"}
l!l&&r!l&&!r
000
MC/DC0%0/2
exists $self->{"data"}{"if"} or $self->{"data"}{"replace"}
exists $self->{"data"}{"if"} $self->{"data"}{"replace"}
Truth table0%0/3
A or B
A= exists $self->{"data"}{"if"}B= $self->{"data"}{"replace"}
ABresult
1X1
011
000
53  
54 0 ▶ if (exists $self->{data}->{if}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"data"}{"if"}) 0 0 0
55 0 foreach my $block (@{$self->{data}->{if}}) {
56 0 ▶ die "'replace' parameter is not specified inside if/then block" if !$block->{then}->{replace};
Branch: 1 branch
BranchTrueFalseTotal
unless $block->{"then"}{"replace"} 0 0 0
57 }
58 }
59 }
60  
61 sub adjust_phases {
62 0 ▶ my ($self, $phases) = @_;
Subroutine adjust_phases: not called CC=2 SCAR=17.9
Pod undocumented
63  
64 0 $self->SUPER::adjust_phases($phases);
65  
66 # this plugin makes sense only when applied to a single phase
67 # (in addition to 'before_job' phase inherited from Serge::Engine::Plugin::if plugin)
68 0 ▶ die "This plugin needs to be attached to only one phase at a time" unless @$phases == 2;
Branch: 1 branch
BranchTrueFalseTotal
unless @$phases == 2 0 0 0
69 }
70  
71 sub process_then_block {
72 0 ▶ my ($self, $phase, $block, $file, $lang, $strref) = @_;
Subroutine process_then_block: not called CC=5 SCAR=34.0
Pod undocumented
73  
74 #print "::process_then_block(), phase=[$phase], block=[$block], file=[$file], lang=[$lang], strref=[$strref]\n";
75  
76 0 my $rules = $block->{replace};
77 0 foreach my $rule (@$rules) {
78 0 my ($from, $to, $modifiers) = @$rule;
79  
80 0 my $output_lang = $lang;
81 0 my $r = $self->{parent}->{output_lang_rewrite};
82 0 ▶ $output_lang = $r->{$lang} if defined $r && exists($r->{$lang});
Branch: 1 branch
BranchTrueFalseTotal
if defined $r and exists $r->{$lang} 0 0 0
Condition0%0/3
defined $r and exists $r->{$lang}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $r and exists $r->{$lang}
defined $r exists $r->{$lang}
Truth table0%0/3
A and B
A= defined $rB= exists $r->{$lang}
ABresult
0X0
100
111
83  
84 0 subst_macros_strref(\$from, $file, $output_lang);
85 0 subst_macros_strref(\$to, $file, $output_lang);
86  
87 0 my $eval_line = "\$\$strref =~ s/$from/$to/$modifiers;";
88 0 eval($eval_line);
89 0 ▶ die "eval() failed on: '$eval_line'\n$@" if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 0 0
90 }
91  
92 0 return (shift @_)->SUPER::process_then_block(@_);
93 }
94  
95 sub check {
96 0 ▶ my $self = shift;
Subroutine check: not called CC=1 SCAR=6.9
Pod undocumented
97 0 return $self->SUPER::check(@_);
98 }
99  
100 sub rewrite_path {
101 0 ▶ my ($self, $phase, $path, $lang) = @_;
Subroutine rewrite_path: not called CC=1 SCAR=6.9
Pod undocumented
102 0 $self->SUPER::check($phase, $path, $lang, \$path);
103 0 return $path;
104 }
105  
106 1 1;
« lib/Serge/Engine/Plugin/test_language.pm ↑ Summary lib/Serge/Sync/Plugin/TranslationService/command.pm »