lib/Serge/Engine/Plugin/trademarks.pm

filter: Statementstmt 33.3% 10 / 30 Branchbran 0.0% 0 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 37.5% 3 / 8 Podpod 0.0% 0 / 5 totaltotal 26.5% 13 / 49 SCAR 23.1
CC
4
Cov
28%
add_hint
12.0
validate_data
6.0
name
2.0
CRAP 10.0
« lib/Serge/Command.pm ↑ Summary lib/Serge/Interface/PluginHost.pm »
1 package Serge::Engine::Plugin::trademarks;
2 1 ▶use parent Serge::Plugin::Base::Callback;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 1 ▶use Serge::Util qw(set_flag);
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 sub name {
9 0 ▶ return 'Add "Do not alter trademarks" comment';
Subroutine name: not called CC=1 SCAR=6.9
Pod undocumented
10 }
11  
12 sub init {
13 0 ▶ my $self = shift;
Subroutine init: not called CC=1 SCAR=6.9
Pod undocumented
14  
15 0 $self->SUPER::init(@_);
16  
17 0 $self->merge_schema({
18 trademarks => 'ARRAY'
19 });
20  
21 0 $self->add({
22 add_hint => \&add_hint
23 });
24 }
25  
26 sub validate_data {
27 0 ▶ my ($self) = @_;
Subroutine validate_data: not called CC=2 SCAR=17.9
Pod undocumented
28  
29 0 $self->SUPER::validate_data;
30  
31 0 ▶ die "'trademarks' parameter is not specified" unless $self->{data}->{trademarks};
Branch: 1 branch
BranchTrueFalseTotal
unless $self->{"data"}{"trademarks"} 0 0 0
32  
33 0 my $e = 'qr/\b(\Q'.join('\E|\Q', @{$self->{data}->{trademarks}}).'\E)\b/';
34 0 $self->{re} = eval($e);
35 }
36  
37 sub adjust_phases {
38 0 ▶ my ($self, $phases) = @_;
Subroutine adjust_phases: not called CC=1 SCAR=6.9
Pod undocumented
39  
40 # always tie to 'add_hint' phase
41 0 set_flag($phases, 'add_hint');
42 }
43  
44 sub add_hint {
45 0 ▶ my ($self, $phase, $string, $context, $namespace, $filepath, $source_key, $lang, $aref) = @_;
Subroutine add_hint: not called CC=3 SCAR=24.8
Pod undocumented
46  
47 0 my %found;
48 0 ▶ while ($string =~ m/$self->{re}/sgi) {
Branch: 1 branch
BranchTrueFalseTotal
if ($string =~ /$self->{"re"}/sig) 0 0 0
49 0 $found{$1} = 1;
50 }
51 0 my $s = join(', ', sort keys %found);
52 0 ▶ if ($s ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($s ne "") 0 0 0
53 0 push @$aref, "Please do not alter trademarks ($s)";
54 }
55 }
56  
57 1 1;
« lib/Serge/Command.pm ↑ Summary lib/Serge/Interface/PluginHost.pm »