lib/Serge/Engine/Plugin/append_hint_message.pm

filter: Statementstmt 97.1% 34 / 35 Branchbran 75.0% 6 / 8 Conditioncond 66.6% 2 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 88.8% 8 / 9 Podpod 0.0% 0 / 6 totaltotal 79.3% 50 / 63 SCAR 20.8
CC
8
Cov
91%
validate_data
6.2
process_then_block
3.0
name
2.0
CRAP 8.0
« Build ↑ Summary lib/Serge/Engine/Plugin/Transform/tags.pm »
1 package Serge::Engine::Plugin::append_hint_message;
2 2 ▶use parent Serge::Engine::Plugin::if;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 2 ▶use Serge::Util qw(set_flag);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 sub name {
9 0 ▶ return 'Plugin to append extra message to a hint';
Subroutine name: not called CC=1 SCAR=6.9
Pod undocumented
10 }
11  
12 sub init {
13 10 ▶ my $self = shift;
Subroutine init: called CC=1 SCAR=0.0
Pod undocumented
14  
15 10 $self->SUPER::init(@_);
16  
17 10 $self->merge_schema({
18 message => {'' => 'LIST',
19 '*' => 'STRING'
20 },
21  
22 if => {
23 '*' => {
24 then => {
25 message => {'' => 'LIST',
26 '*' => 'STRING'
27 },
28 },
29 },
30 },
31 });
32  
33 10 $self->add({
34 add_hint => \&add_hint
35 });
36 }
37  
38 sub validate_data {
39 10 ▶ my ($self) = @_;
Subroutine validate_data: called CC=6 SCAR=18.3
Pod undocumented
40  
41 10 $self->SUPER::validate_data;
42  
43 10 ▶ die "'message' parameter is not specified and no 'if' blocks found" if !exists $self->{data}->{if} && !$self->{data}->{message};
Branch: 1 branch
BranchTrueFalseTotal
unless exists $self->{"data"}{"if"} or $self->{"data"}{"message"} 0 10 10
Condition66%2/3
exists $self->{"data"}{"if"} or $self->{"data"}{"message"}
l!l&&r!l&&!r
820
MC/DC0%0/2
exists $self->{"data"}{"if"} or $self->{"data"}{"message"}
exists $self->{"data"}{"if"} $self->{"data"}{"message"}
Truth table66%2/3
A or B
A= exists $self->{"data"}{"if"}B= $self->{"data"}{"message"}
ABresult
1X1
011
000
44  
45 10 ▶ if (exists $self->{data}->{if}) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{"data"}{"if"}) 8 2 10
46 8 foreach my $block (@{$self->{data}->{if}}) {
47 9 ▶ die "'message' parameter is not specified inside if/then block" if !$block->{then}->{message};
Branch: 1 branch
BranchTrueFalseTotal
unless $block->{"then"}{"message"} 0 9 9
48 }
49 }
50 }
51  
52 sub adjust_phases {
53 10 ▶ my ($self, $phases) = @_;
Subroutine adjust_phases: called CC=1 SCAR=0.0
Pod undocumented
54  
55 # always tie to 'add_hint' phase
56 10 set_flag($phases, 'add_hint');
57 }
58  
59 sub process_then_block {
60 85 ▶ my ($self, $phase, $block, $filepath, $lang, $strref, $commentref, $aref) = @_;
Subroutine process_then_block: called CC=3 SCAR=11.0
Pod undocumented
61  
62 85 ▶ if ($phase eq 'add_hint') {
Branch: 1 branch
BranchTrueFalseTotal
if ($phase eq "add_hint") 50 35 85
63 50 my @m = @{$block->{message}}; # make a copy
64 50 foreach my $message (@m) {
65 # use render_full_output_path as a higher-level substitution for
66 # subst_macros which can also deal with filepath-based macros
67 78 $message = $self->{parent}->render_full_output_path($message, $filepath, $lang);
68 # additionally, substitute captures
69 78 $message = $self->subst_captures($message);
70 # push the message to the array of hints
71 78 push @$aref, $message;
72 }
73 }
74  
75 85 return (shift @_)->SUPER::process_then_block(@_);
76 }
77  
78 sub add_hint {
79 74 ▶ my ($self, $phase, $string, $context, $namespace, $filepath, $source_key, $lang, $aref) = @_;
Subroutine add_hint: called CC=1 SCAR=0.0
Pod undocumented
80  
81 74 return $self->SUPER::check($phase, $filepath, $lang, \$string, undef, $aref);
82 }
83  
84 2 1;
« Build ↑ Summary lib/Serge/Engine/Plugin/Transform/tags.pm »