| 1 | package Serge::Engine::Plugin::if; | ||||||||||||||||||||||||||||
| 2 | 2 | ▶ | use parent Serge::Plugin::Base::Callback; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | |||||||||||||||||||||||||||||
| 4 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 2 | ▶ | use Serge::Util qw(set_flag subst_macros_strref); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | # if multiple 'if' blocks are provided, at least one of them must match: | ||||||||||||||||||||||||||||
| 9 | # result = (block1 || block2 || block3 || ...) | ||||||||||||||||||||||||||||
| 10 | # Note that 'if' block contains 'set_flag'/'remove_flag' directives, | ||||||||||||||||||||||||||||
| 11 | # it will always be processed, even if the previous if block already | ||||||||||||||||||||||||||||
| 12 | # evaluates to a 'true' value | ||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | # Within any 'if' block, all provided statements must match: | ||||||||||||||||||||||||||||
| 15 | # blockN = (statement1 && statement2 && statement3 && ...) | ||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | # Within a statement, multiple positive options (*_matches) are treated like this: | ||||||||||||||||||||||||||||
| 18 | # statementN = (option1 || option2 || option3 || ...) | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | # Within a statement, multiple negative options (*_doesnt_match) are treated like this: | ||||||||||||||||||||||||||||
| 21 | # statementN = !(option1 || option2 || option3 || ...) | ||||||||||||||||||||||||||||
| 22 | # which is equivalent to: | ||||||||||||||||||||||||||||
| 23 | # statementN = (!option1 && !option2 && !option3 && ...) | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | sub name { | ||||||||||||||||||||||||||||
| 26 | 0 | ▶ | return 'Generic "if" plugin that implements conditionals and flag checking/setting. See "process_if" for a plugin that uses this functionality'; | ||||||||||||||||||||||||||
|
Subroutine
name: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | sub init { | ||||||||||||||||||||||||||||
| 30 | 14 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
init: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 14 | $self->SUPER::init(@_); | |||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||
| 34 | 14 | $self->merge_schema({ | |||||||||||||||||||||||||||
| 35 | set_flag => 'ARRAY', | ||||||||||||||||||||||||||||
| 36 | remove_flag => 'ARRAY', | ||||||||||||||||||||||||||||
| 37 | capture => {'' => 'LIST', | ||||||||||||||||||||||||||||
| 38 | '*' => { | ||||||||||||||||||||||||||||
| 39 | match => 'ARRAY', | ||||||||||||||||||||||||||||
| 40 | prefix => 'STRING', | ||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | }, | ||||||||||||||||||||||||||||
| 43 | return => 'BOOLEAN', | ||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | if => {'' => 'LIST', | ||||||||||||||||||||||||||||
| 46 | '*' => { | ||||||||||||||||||||||||||||
| 47 | file_matches => 'ARRAY', | ||||||||||||||||||||||||||||
| 48 | file_doesnt_match => 'ARRAY', | ||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | lang_matches => 'ARRAY', | ||||||||||||||||||||||||||||
| 51 | lang_doesnt_match => 'ARRAY', | ||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | content_matches => 'ARRAY', | ||||||||||||||||||||||||||||
| 54 | content_doesnt_match => 'ARRAY', | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | comment_matches => 'ARRAY', | ||||||||||||||||||||||||||||
| 57 | comment_doesnt_match => 'ARRAY', | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | has_flag => 'ARRAY', | ||||||||||||||||||||||||||||
| 60 | has_no_flag => 'ARRAY', | ||||||||||||||||||||||||||||
| 61 | has_all_flags => 'ARRAY', | ||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||
| 63 | has_capture => 'ARRAY', | ||||||||||||||||||||||||||||
| 64 | has_no_capture => 'ARRAY', | ||||||||||||||||||||||||||||
| 65 | has_all_captures => 'ARRAY', | ||||||||||||||||||||||||||||
| 66 | |||||||||||||||||||||||||||||
| 67 | then => { | ||||||||||||||||||||||||||||
| 68 | set_flag => 'ARRAY', | ||||||||||||||||||||||||||||
| 69 | remove_flag => 'ARRAY', | ||||||||||||||||||||||||||||
| 70 | capture => {'' => 'LIST', | ||||||||||||||||||||||||||||
| 71 | '*' => { | ||||||||||||||||||||||||||||
| 72 | match => 'ARRAY', | ||||||||||||||||||||||||||||
| 73 | prefix => 'STRING', | ||||||||||||||||||||||||||||
| 74 | } | ||||||||||||||||||||||||||||
| 75 | }, | ||||||||||||||||||||||||||||
| 76 | return => 'BOOLEAN', | ||||||||||||||||||||||||||||
| 77 | }, | ||||||||||||||||||||||||||||
| 78 | }, | ||||||||||||||||||||||||||||
| 79 | }, | ||||||||||||||||||||||||||||
| 80 | }); | ||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||
| 82 | 14 | $self->add({ | |||||||||||||||||||||||||||
| 83 | before_job => \&before_job, | ||||||||||||||||||||||||||||
| 84 | after_load_file => \&check, | ||||||||||||||||||||||||||||
| 85 | after_load_source_file_for_processing => \&check_file_content, | ||||||||||||||||||||||||||||
| 86 | before_deserialize_ts_file => \&check_file_content, | ||||||||||||||||||||||||||||
| 87 | after_serialize_ts_file => \&check_file_content, | ||||||||||||||||||||||||||||
| 88 | before_save_localized_file => \&check, | ||||||||||||||||||||||||||||
| 89 | }); | ||||||||||||||||||||||||||||
| 90 | } | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | sub validate_data { | ||||||||||||||||||||||||||||
| 93 | 14 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
validate_data: called CC=4 SCAR=13.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | 14 | $self->SUPER::validate_data; | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 14 | ▶ | if (exists $self->{data}->{if}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 10 | foreach my $block (@{$self->{data}->{if}}) { | |||||||||||||||||||||||||||
| 99 | 11 | ▶ | die "'then' block is not specified" if !exists $block->{then}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 100 | } | ||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | |||||||||||||||||||||||||||||
| 104 | sub adjust_phases { | ||||||||||||||||||||||||||||
| 105 | 3 | ▶ | my ($self, $phases) = @_; | ||||||||||||||||||||||||||
|
Subroutine
adjust_phases: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 106 | |||||||||||||||||||||||||||||
| 107 | # always tie to 'before_job' phase | ||||||||||||||||||||||||||||
| 108 | 3 | set_flag($phases, 'before_job'); | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | sub before_job { | ||||||||||||||||||||||||||||
| 112 | 11 | ▶ | my ($self) = @_; | ||||||||||||||||||||||||||
|
Subroutine
before_job: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | # initialize/clear plugin data for each job | ||||||||||||||||||||||||||||
| 115 | 11 | my $job = $self->{parent}; | |||||||||||||||||||||||||||
| 116 | 11 | ▶ | $job->{plugin_data} = {} unless exists $job->{plugin_data}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 117 | 11 | ▶ | $job->{plugin_data}->{check_if} = {} unless exists $job->{plugin_data}->{check_if}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 118 | 11 | $job->{plugin_data}->{check_if}->{flags} = {}; | |||||||||||||||||||||||||||
| 119 | 11 | $job->{plugin_data}->{check_if}->{captures} = {}; | |||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | sub check_file_content { | ||||||||||||||||||||||||||||
| 123 | 20 | ▶ | my ($self, $phase, $file, $strref) = @_; | ||||||||||||||||||||||||||
|
Subroutine
check_file_content: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||
| 125 | 20 | $self->check($phase, $file, undef, $strref); | |||||||||||||||||||||||||||
| 126 | } | ||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||
| 128 | sub flags { | ||||||||||||||||||||||||||||
| 129 | 80 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
flags: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 130 | 80 | return $self->{parent}->{plugin_data}->{check_if}->{flags}; | |||||||||||||||||||||||||||
| 131 | } | ||||||||||||||||||||||||||||
| 132 | |||||||||||||||||||||||||||||
| 133 | sub captures { | ||||||||||||||||||||||||||||
| 134 | 152 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
captures: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 135 | 152 | return $self->{parent}->{plugin_data}->{check_if}->{captures}; | |||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||
| 138 | sub check { | ||||||||||||||||||||||||||||
| 139 | 122 | ▶ | my ($self, $phase, $file, $lang, $strref, $commentref, @extra_params) = @_; | ||||||||||||||||||||||||||
|
Subroutine
check: called CC=6 SCAR=18.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 122 | ▶ | if (!exists $self->{data}->{if}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 142 | 26 | my $result = $self->process_then_block($phase, $self->{data}, $file, $lang, $strref, $commentref, @extra_params); | |||||||||||||||||||||||||||
| 143 | 26 | ▶ | return $result if defined $result; # return result if the block returns 1 or 0; continue if it returns undef | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 144 | 26 | return 1; | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 96 | foreach my $block (@{$self->{data}->{if}}) { | |||||||||||||||||||||||||||
| 148 | 110 | ▶ | if ($self->check_block($phase, $block, $file, $lang, $strref, $commentref)) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 149 | 64 | my $result = $self->process_then_block($phase, $block->{then}, $file, $lang, $strref, $commentref, @extra_params); | |||||||||||||||||||||||||||
| 150 | 64 | ▶ | return $result if defined $result; # return result if the block returns 1 or 0; continue if it returns undef | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||
| 154 | 96 | return 0; | |||||||||||||||||||||||||||
| 155 | } | ||||||||||||||||||||||||||||
| 156 | |||||||||||||||||||||||||||||
| 157 | sub check_block { | ||||||||||||||||||||||||||||
| 158 | 110 | ▶ | my ($self, $phase, $block, $file, $lang, $strref, $commentref) = @_; | ||||||||||||||||||||||||||
|
Subroutine
check_block: called CC=30 SCAR=44.3
Pod
undocumented
| |||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 110 | ▶ | if ($self->{parent}->{debug}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 161 | 0 | ▶ | print "[if]::check_block('$phase', '$file', '$lang', ". | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 162 | #(defined $strref ? '[content], ' : '-- no content --, '). | ||||||||||||||||||||||||||||
| 163 | #(defined $commentref ? '[comment]' : '-- no comment --'). | ||||||||||||||||||||||||||||
| 164 | (defined $strref ? "'$$strref', " : '-- no content --, '). | ||||||||||||||||||||||||||||
| 165 | (defined $commentref ? "'$$commentref'" : '-- no comment --'). | ||||||||||||||||||||||||||||
| 166 | ")\n"; | ||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | print "[if]::check_block; current flags for '$self->{parent}->{engine}->{current_file_rel}': ", | ||||||||||||||||||||||||||||
| 169 | 0 | join(', ', sort keys %{$self->flags->{$self->{parent}->{engine}->{current_file_rel}}}), "\n"; | |||||||||||||||||||||||||||
| 170 | } | ||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||
| 172 | # Sanity checks. Some phases don't provide language, content or comment to match against | ||||||||||||||||||||||||||||
| 173 | |||||||||||||||||||||||||||||
| 174 | 110 | ▶ | die "'lang_matches' parameter is specified for a phase '$phase' that doesn't provide lang" if (exists $block->{lang_matches} && !defined $lang); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $block->{"lang_matches"} and not defined $lang
MC/DC0%0/2
exists $block->{"lang_matches"} and not defined $lang
exists $block->{"lang_matches"}
not defined $lang
Truth table33%1/3
A and not(B)
A= exists $block->{"lang_matches"}B= not defined $lang
| |||||||||||||||||||||||||||||
| 175 | 110 | ▶ | die "'lang_doesnt_match' parameter is specified for a phase '$phase' that doesn't provide lang" if (exists $block->{lang_doesnt_match} && !defined $lang); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $block->{"lang_doesnt_match"} and not defined $lang
MC/DC0%0/2
exists $block->{"lang_doesnt_match"} and not defined $lang
exists $block->{"lang_doesnt_match"}
not defined $lang
Truth table33%1/3
A and not(B)
A= exists $block->{"lang_doesnt_match"}B= not defined $lang
| |||||||||||||||||||||||||||||
| 176 | |||||||||||||||||||||||||||||
| 177 | 110 | ▶ | die "'content_matches' parameter is specified for a phase '$phase' that doesn't provide content" if (exists $block->{content_matches} && !defined $strref); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $block->{"content_matches"} and not defined $strref
MC/DC0%0/2
exists $block->{"content_matches"} and not defined $strref
exists $block->{"content_matches"}
not defined $strref
Truth table66%2/3
A and not(B)
A= exists $block->{"content_matches"}B= not defined $strref
| |||||||||||||||||||||||||||||
| 178 | 110 | ▶ | die "'content_doesnt_match' parameter is specified for a phase '$phase' that doesn't provide content" if (exists $block->{content_doesnt_match} && !defined $strref); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $block->{"content_doesnt_match"} and not defined $strref
MC/DC0%0/2
exists $block->{"content_doesnt_match"} and not defined $strref
exists $block->{"content_doesnt_match"}
not defined $strref
Truth table33%1/3
A and not(B)
A= exists $block->{"content_doesnt_match"}B= not defined $strref
| |||||||||||||||||||||||||||||
| 179 | |||||||||||||||||||||||||||||
| 180 | 110 | ▶ | die "'comment_matches' parameter is specified for a phase '$phase' that doesn't provide comment" if (exists $block->{comment_matches} && !defined $commentref); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $block->{"comment_matches"} and not defined $commentref
MC/DC0%0/2
exists $block->{"comment_matches"} and not defined $commentref
exists $block->{"comment_matches"}
not defined $commentref
Truth table33%1/3
A and not(B)
A= exists $block->{"comment_matches"}B= not defined $commentref
| |||||||||||||||||||||||||||||
| 181 | 110 | ▶ | die "'comment_doesnt_match' parameter is specified for a phase '$phase' that doesn't provide comment" if (exists $block->{comment_doesnt_match} && !defined $commentref); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
exists $block->{"comment_doesnt_match"} and not defined $commentref
MC/DC0%0/2
exists $block->{"comment_doesnt_match"} and not defined $commentref
exists $block->{"comment_doesnt_match"}
not defined $commentref
Truth table33%1/3
A and not(B)
A= exists $block->{"comment_doesnt_match"}B= not defined $commentref
| |||||||||||||||||||||||||||||
| 182 | |||||||||||||||||||||||||||||
| 183 | 110 | ▶ | return 0 unless $self->_check_statement($block->{file_matches}, 1, $file); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 184 | 110 | ▶ | return 0 unless $self->_check_statement($block->{file_doesnt_match}, undef, $file); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | 110 | ▶ | return 0 unless $self->_check_statement($block->{lang_matches}, 1, $lang); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 187 | 110 | ▶ | return 0 unless $self->_check_statement($block->{lang_doesnt_match}, undef, $lang); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||
| 189 | 110 | ▶ | return 0 unless $self->_check_statement($block->{content_matches}, 1, $$strref); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 190 | 78 | ▶ | return 0 unless $self->_check_statement($block->{content_doesnt_match}, undef, $$strref); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | 78 | ▶ | return 0 unless $self->_check_statement($block->{comment_matches}, 1, $$commentref); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 193 | 78 | ▶ | return 0 unless $self->_check_statement($block->{comment_doesnt_match}, undef, $$commentref); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||
| 195 | 78 | my $flags = $self->flags; | |||||||||||||||||||||||||||
| 196 | 78 | ▶ | return 0 unless $self->_check_has_member($flags, $block->{has_flag}, 1); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 197 | 71 | ▶ | return 0 unless $self->_check_has_member($flags, $block->{has_no_flag}, undef); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 198 | 71 | ▶ | return 0 unless $self->_check_has_all_members($flags, $block->{has_all_flags}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 199 | |||||||||||||||||||||||||||||
| 200 | 71 | my $captures = $self->captures; | |||||||||||||||||||||||||||
| 201 | 71 | ▶ | return 0 unless $self->_check_has_member($captures, $block->{has_capture}, 1); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 202 | 71 | ▶ | return 0 unless $self->_check_has_member($captures, $block->{has_no_capture}, undef); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 203 | 71 | ▶ | return 0 unless $self->_check_has_all_members($captures, $block->{has_all_captures}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | 64 | return 1; | |||||||||||||||||||||||||||
| 206 | } | ||||||||||||||||||||||||||||
| 207 | |||||||||||||||||||||||||||||
| 208 | sub _key { | ||||||||||||||||||||||||||||
| 209 | 210 | ▶ | my $self = shift; | ||||||||||||||||||||||||||
|
Subroutine
_key: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 210 | 210 | return $self->{parent}->{engine}->{current_file_rel}; | |||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||
| 213 | sub _check_statement { | ||||||||||||||||||||||||||||
| 214 | 784 | ▶ | my ($self, $ruleset, $positive, $value) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_check_statement: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||
| 216 | 784 | ▶ | return 1 unless defined $ruleset; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||
| 218 | 68 | foreach my $rule (@$ruleset) { | |||||||||||||||||||||||||||
| 219 | 68 | ▶ | if ($value =~ m/$rule/s) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 220 | 36 | return $positive; | |||||||||||||||||||||||||||
| 221 | } | ||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||
| 223 | 32 | return !$positive; | |||||||||||||||||||||||||||
| 224 | } | ||||||||||||||||||||||||||||
| 225 | |||||||||||||||||||||||||||||
| 226 | sub _check_has_member { | ||||||||||||||||||||||||||||
| 227 | 291 | ▶ | my ($self, $memberset, $flagset, $positive) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_check_has_member: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 228 | |||||||||||||||||||||||||||||
| 229 | 291 | ▶ | return 1 unless defined $flagset; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 230 | 28 | ▶ | my $f = $memberset->{$self->_key} || {}; | ||||||||||||||||||||||||||
|
Condition100%2/2
$$memberset{$self->_key} || {}
MC/DC100%1/1
$$memberset{$self->_key} || {}
$$memberset{$self->_key}
Truth table100%2/2
A
A= $$memberset{$self->_key}
| |||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | 28 | foreach my $flag (@$flagset) { | |||||||||||||||||||||||||||
| 233 | 28 | ▶ | if (exists $f->{$flag}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 234 | 21 | return $positive; | |||||||||||||||||||||||||||
| 235 | } | ||||||||||||||||||||||||||||
| 236 | } | ||||||||||||||||||||||||||||
| 237 | 7 | return !$positive; | |||||||||||||||||||||||||||
| 238 | } | ||||||||||||||||||||||||||||
| 239 | |||||||||||||||||||||||||||||
| 240 | sub _check_has_all_members { | ||||||||||||||||||||||||||||
| 241 | 142 | ▶ | my ($self, $memberset, $flagset) = @_; | ||||||||||||||||||||||||||
|
Subroutine
_check_has_all_members: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||
| 243 | 142 | ▶ | return 1 unless defined $flagset; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 244 | |||||||||||||||||||||||||||||
| 245 | 14 | ▶ | my $f = $memberset->{$self->_key} || {}; | ||||||||||||||||||||||||||
|
Condition50%1/2
$$memberset{$self->_key} || {}
MC/DC0%0/1
$$memberset{$self->_key} || {}
$$memberset{$self->_key}
Truth table50%1/2
A
A= $$memberset{$self->_key}
| |||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||
| 247 | 14 | foreach my $flag (@$flagset) { | |||||||||||||||||||||||||||
| 248 | 28 | ▶ | if (!exists $f->{$flag}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 249 | 7 | return 0; | |||||||||||||||||||||||||||
| 250 | } | ||||||||||||||||||||||||||||
| 251 | } | ||||||||||||||||||||||||||||
| 252 | 7 | return 1; | |||||||||||||||||||||||||||
| 253 | } | ||||||||||||||||||||||||||||
| 254 | |||||||||||||||||||||||||||||
| 255 | sub process_then_block { | ||||||||||||||||||||||||||||
| 256 | 90 | ▶ | my ($self, $phase, $block, $file, $lang, $strref, $commentref) = @_; | ||||||||||||||||||||||||||
|
Subroutine
process_then_block: called CC=18 SCAR=30.7
Pod
undocumented
| |||||||||||||||||||||||||||||
| 257 | |||||||||||||||||||||||||||||
| 258 | 90 | my $key = $self->_key; | |||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | # deal with flags only when set_flag/remove_flag directives are defined | ||||||||||||||||||||||||||||
| 261 | 90 | ▶ | if (exists $block->{set_flag} || exists $block->{remove_flag}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
exists $block->{"set_flag"} or exists $block->{"remove_flag"}
MC/DC50%1/2
exists $block->{"set_flag"} or exists $block->{"remove_flag"}
exists $block->{"set_flag"}
exists $block->{"remove_flag"}
Truth table66%2/3
A or B
A= exists $block->{"set_flag"}B= exists $block->{"remove_flag"}
| |||||||||||||||||||||||||||||
| 262 | 2 | my $flags = $self->flags; | |||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||
| 264 | 2 | ▶ | $flags->{$key} = {} unless exists $flags->{$key}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 265 | |||||||||||||||||||||||||||||
| 266 | 2 | ▶ | if (exists $block->{set_flag}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 267 | 2 | foreach my $value (@{$block->{set_flag}}) { | |||||||||||||||||||||||||||
| 268 | 2 | $flags->{$key}->{$value} = 1; | |||||||||||||||||||||||||||
| 269 | } | ||||||||||||||||||||||||||||
| 270 | } | ||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||
| 272 | 2 | ▶ | if (exists $block->{remove_flag}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 273 | 0 | foreach my $value (@{$block->{remove_flag}}) { | |||||||||||||||||||||||||||
| 274 | 0 | delete $flags->{$key}->{$value}; | |||||||||||||||||||||||||||
| 275 | } | ||||||||||||||||||||||||||||
| 276 | } | ||||||||||||||||||||||||||||
| 277 | } | ||||||||||||||||||||||||||||
| 278 | |||||||||||||||||||||||||||||
| 279 | 90 | ▶ | if (exists $block->{capture}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 280 | 3 | my $captures = $self->captures; | |||||||||||||||||||||||||||
| 281 | |||||||||||||||||||||||||||||
| 282 | 3 | ▶ | $captures->{$key} = {} unless exists $captures->{$key}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||
| 284 | 3 | my $rules = $block->{capture}; | |||||||||||||||||||||||||||
| 285 | 3 | foreach my $rule (@$rules) { | |||||||||||||||||||||||||||
| 286 | 3 | my ($from, $modifiers) = @{$rule->{match}}; | |||||||||||||||||||||||||||
| 287 | 3 | my $prefix = $rule->{prefix}; | |||||||||||||||||||||||||||
| 288 | |||||||||||||||||||||||||||||
| 289 | 3 | my $output_lang = $lang; | |||||||||||||||||||||||||||
| 290 | 3 | my $r = $self->{parent}->{output_lang_rewrite}; | |||||||||||||||||||||||||||
| 291 | 3 | ▶ | $output_lang = $r->{$lang} if defined $r && exists($r->{$lang}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
defined $r and exists $r->{$lang}
MC/DC0%0/2
defined $r and exists $r->{$lang}
defined $r
exists $r->{$lang}
Truth table33%1/3
A and B
A= defined $rB= exists $r->{$lang}
| |||||||||||||||||||||||||||||
| 292 | |||||||||||||||||||||||||||||
| 293 | 3 | subst_macros_strref(\$from, $file, $output_lang); | |||||||||||||||||||||||||||
| 294 | |||||||||||||||||||||||||||||
| 295 | 3 | my @matches; | |||||||||||||||||||||||||||
| 296 | 3 | my $eval_line = "\@matches = \$\$strref =~ m/$from/$modifiers;"; | |||||||||||||||||||||||||||
| 297 | 3 | eval($eval_line); | |||||||||||||||||||||||||||
| 298 | 3 | ▶ | die "eval() failed on: '$eval_line'\n$@" if $@; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 299 | |||||||||||||||||||||||||||||
| 300 | 3 | ▶ | for (my $i = 0; $i <= $#matches; $i++) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 301 | 5 | my $name = $prefix.($i+1); | |||||||||||||||||||||||||||
| 302 | 5 | my $value = $matches[$i]; | |||||||||||||||||||||||||||
| 303 | 5 | ▶ | print "::captured for [$key]: [$name]=>[$value]\n" if $self->{parent}->{debug}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 304 | 5 | $captures->{$key}->{$name} = $value; | |||||||||||||||||||||||||||
| 305 | } | ||||||||||||||||||||||||||||
| 306 | } | ||||||||||||||||||||||||||||
| 307 | } | ||||||||||||||||||||||||||||
| 308 | |||||||||||||||||||||||||||||
| 309 | 90 | ▶ | if (exists $block->{return}) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 310 | 0 | ▶ | return $block->{return} ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 311 | } | ||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||
| 313 | 90 | return undef; | |||||||||||||||||||||||||||
| 314 | } | ||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||
| 316 | sub subst_captures { | ||||||||||||||||||||||||||||
| 317 | 78 | ▶ | my ($self, $message) = @_; | ||||||||||||||||||||||||||
|
Subroutine
subst_captures: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||
| 319 | 78 | my $key = $self->_key; | |||||||||||||||||||||||||||
| 320 | 78 | my $captures = $self->captures; | |||||||||||||||||||||||||||
| 321 | 78 | ▶ | return $message unless exists $captures->{$key}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||
| 323 | 35 | $message =~ s/%CAPTURE:(\S+)%/$captures->{$key}->{$1}/ge; | |||||||||||||||||||||||||||
| 324 | |||||||||||||||||||||||||||||
| 325 | 35 | return $message; | |||||||||||||||||||||||||||
| 326 | } | ||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||
| 328 | 2 | 1; | |||||||||||||||||||||||||||