| 1 | package Locale::TextDomain::OO::Extract::Base::RegexBasedExtractor; ## no critic (TidyCode) | ||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||
| 3 | 7 | ▶ | use strict; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 4 | 7 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 5 | 7 | ▶ | use Carp qw(confess); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 6 | 7 | ▶ | use Clone qw(clone); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 7 | 7 | ▶ | use Data::Dumper (); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 8 | 7 | ▶ | use Moo; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 9 | 7 | ▶ | use MooX::StrictConstructor; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 10 | 7 | ▶ | use MooX::Types::MooseLike::Base qw(ArrayRef CodeRef RegexpRef ScalarRef); | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 11 | 7 | ▶ | use namespace::autoclean; | ||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||
| 13 | 7 | our $VERSION = '2.007'; | |||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||
| 15 | 7 | has content_ref => ( | |||||||||||||||||||||||||||||||||
| 16 | is => 'rw', | ||||||||||||||||||||||||||||||||||
| 17 | isa => ScalarRef, | ||||||||||||||||||||||||||||||||||
| 18 | ); | ||||||||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||||||||
| 20 | 7 | has start_rule => ( | |||||||||||||||||||||||||||||||||
| 21 | is => 'rw', | ||||||||||||||||||||||||||||||||||
| 22 | isa => RegexpRef, | ||||||||||||||||||||||||||||||||||
| 23 | ); | ||||||||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||||||||
| 25 | 7 | has rules => ( | |||||||||||||||||||||||||||||||||
| 26 | is => 'rw', | ||||||||||||||||||||||||||||||||||
| 27 | isa => ArrayRef, | ||||||||||||||||||||||||||||||||||
| 28 | ); | ||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||
| 30 | 7 | has debug_code => ( | |||||||||||||||||||||||||||||||||
| 31 | is => 'rw', | ||||||||||||||||||||||||||||||||||
| 32 | isa => CodeRef, | ||||||||||||||||||||||||||||||||||
| 33 | clearer => 'clear_debug_code', | ||||||||||||||||||||||||||||||||||
| 34 | ); | ||||||||||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||||||||
| 36 | 7 | has stack => ( | |||||||||||||||||||||||||||||||||
| 37 | is => 'rw', | ||||||||||||||||||||||||||||||||||
| 38 | isa => ArrayRef, | ||||||||||||||||||||||||||||||||||
| 39 | ); | ||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||
| 41 | 28 | ▶ | sub _parse_pos { | ||||||||||||||||||||||||||||||||
|
Subroutine
_parse_pos: called CC=4 SCAR=14.6
| |||||||||||||||||||||||||||||||||||
| 42 | 28 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||
| 44 | 28 | my $regex = $self->start_rule; | |||||||||||||||||||||||||||||||||
| 45 | 28 | my $content_ref = $self->content_ref; | |||||||||||||||||||||||||||||||||
| 46 | 28 | ▶ | defined ${$content_ref} | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 47 | or return confess 'content_ref is a reference to undef'; | ||||||||||||||||||||||||||||||||||
| 48 | 28 | my @stack; | |||||||||||||||||||||||||||||||||
| 49 | 28 | ▶ | while ( ${$content_ref} =~ m{ \G .*? ( $regex ) }xmsgc ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 50 | push @stack, { | ||||||||||||||||||||||||||||||||||
| 51 | 447 | start_pos => pos( ${$content_ref} ) - length $1, | |||||||||||||||||||||||||||||||||
| 52 | }; | ||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||
| 54 | 28 | $self->stack(\@stack); | |||||||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||||||||
| 56 | # debug if requested | ||||||||||||||||||||||||||||||||||
| 57 | 28 | ▶ | $self->debug_code | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 58 | or return $self; | ||||||||||||||||||||||||||||||||||
| 59 | 0 | my $dump = Data::Dumper ## no critic (LongChainsOfMethodCalls) | |||||||||||||||||||||||||||||||||
| 60 | ->new([ $self->stack ], [ qw(stack) ]) | ||||||||||||||||||||||||||||||||||
| 61 | ->Indent(1) | ||||||||||||||||||||||||||||||||||
| 62 | ->Quotekeys(0) | ||||||||||||||||||||||||||||||||||
| 63 | ->Sortkeys(1) | ||||||||||||||||||||||||||||||||||
| 64 | ->Useqq(1) | ||||||||||||||||||||||||||||||||||
| 65 | ->Dump; | ||||||||||||||||||||||||||||||||||
| 66 | 0 | chomp $dump; | |||||||||||||||||||||||||||||||||
| 67 | 0 | $self->debug_code->('stack start', $dump); | |||||||||||||||||||||||||||||||||
| 68 | |||||||||||||||||||||||||||||||||||
| 69 | 0 | return $self; | |||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||
| 72 | 28 | ▶ | sub _parse_rules { ## no critic (ExcessComplexity) | ||||||||||||||||||||||||||||||||
|
Subroutine
_parse_rules: called CC=38 SCAR=39.0
| |||||||||||||||||||||||||||||||||||
| 73 | 28 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||
| 75 | 28 | my $content_ref = $self->content_ref; | |||||||||||||||||||||||||||||||||
| 76 | 28 | for my $stack_item ( @{ $self->stack } ) { | |||||||||||||||||||||||||||||||||
| 77 | 447 | my $rules = clone( $self->rules ); | |||||||||||||||||||||||||||||||||
| 78 | 447 | my $pos = $stack_item->{start_pos}; | |||||||||||||||||||||||||||||||||
| 79 | 447 | my $level = 0; | |||||||||||||||||||||||||||||||||
| 80 | 447 | my @level_matched = ( 1 ); | |||||||||||||||||||||||||||||||||
| 81 | 447 | my $has_matched = 0; | |||||||||||||||||||||||||||||||||
| 82 | 447 | ▶ | $self->debug_code | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 83 | and $self->debug_code->('rules start', "$level: Starting at pos $pos."); | ||||||||||||||||||||||||||||||||||
| 84 | 447 | my (@parent_rules, @parent_pos, %level_and_of, @stack_result); | |||||||||||||||||||||||||||||||||
| 85 | RULE: { | ||||||||||||||||||||||||||||||||||
| 86 | 447 | my $rule = shift @{$rules}; | |||||||||||||||||||||||||||||||||
| 87 | 32218 | ▶ | if (! $rule) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 88 | 2362 | ▶ | $self->debug_code | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 89 | and $self->debug_code->('rules last', "$level: No more rules found."); | ||||||||||||||||||||||||||||||||||
| 90 | 2362 | ▶ | if (@parent_rules) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 91 | 1915 | $rules = pop @parent_rules; | |||||||||||||||||||||||||||||||||
| 92 | 1915 | () = pop @parent_pos; | |||||||||||||||||||||||||||||||||
| 93 | 1915 | ▶ | $self->debug_code | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 94 | and $self->debug_code->('rules parent', "$level: Going back to parent."); | ||||||||||||||||||||||||||||||||||
| 95 | # delete the parent and match | ||||||||||||||||||||||||||||||||||
| 96 | 1915 | ▶ | if ( ! $has_matched ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 97 | LEVEL: ## no critic (DeepNests) | ||||||||||||||||||||||||||||||||||
| 98 | 14 | for my $parent_level ( reverse 0 .. ( $level - 1 ) ) { | |||||||||||||||||||||||||||||||||
| 99 | 14 | ▶ | if ( exists $level_and_of{$parent_level} ) { ## no critic (DeepNests) | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 100 | 1 | $level_and_of{$parent_level} = 0; | |||||||||||||||||||||||||||||||||
| 101 | 1 | last LEVEL; | |||||||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||
| 105 | 1915 | --$level; | |||||||||||||||||||||||||||||||||
| 106 | 1915 | redo RULE; | |||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||
| 108 | 447 | last RULE; | |||||||||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||||||||
| 110 | # goto child | ||||||||||||||||||||||||||||||||||
| 111 | 29856 | ▶ | if ( ref $rule eq 'ARRAY' ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 112 | 7749 | push @parent_rules, $rules; | |||||||||||||||||||||||||||||||||
| 113 | 7749 | push @parent_pos, $pos; | |||||||||||||||||||||||||||||||||
| 114 | 7749 | $rules = clone($rule); | |||||||||||||||||||||||||||||||||
| 115 | 7749 | ▶ | $self->debug_code | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 116 | and $self->debug_code->('rules child', "$level: Going to child."); | ||||||||||||||||||||||||||||||||||
| 117 | 7749 | $level_matched[ ++$level ] = 1; | |||||||||||||||||||||||||||||||||
| 118 | 7749 | redo RULE; | |||||||||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||||||||
| 120 | # alternative | ||||||||||||||||||||||||||||||||||
| 121 | 22107 | ▶ | if ( lc $rule eq 'or' ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 122 | 6243 | ▶ | if ($has_matched) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 123 | 783 | $rules = pop @parent_rules; | |||||||||||||||||||||||||||||||||
| 124 | 783 | () = pop @parent_pos; | |||||||||||||||||||||||||||||||||
| 125 | 783 | $has_matched = 0; | |||||||||||||||||||||||||||||||||
| 126 | 783 | ▶ | $self->debug_code | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 127 | and $self->debug_code->('rules ignore', "$level: Matched before 'or' so ignore alternatives. Going back to parent."); | ||||||||||||||||||||||||||||||||||
| 128 | 783 | --$level; | |||||||||||||||||||||||||||||||||
| 129 | 783 | redo RULE; | |||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||
| 131 | $self->debug_code | ||||||||||||||||||||||||||||||||||
| 132 | 5460 | ▶ | and $self->debug_code->('rules try', "$level: Not matched so try next alternative."); | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 133 | 5460 | $level_matched[$level] = 1; | |||||||||||||||||||||||||||||||||
| 134 | 5460 | redo RULE; | |||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||
| 136 | # to expect the next match | ||||||||||||||||||||||||||||||||||
| 137 | 15864 | ▶ | if ( lc $rule eq 'and' ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 138 | 2085 | ▶ | if ( ! exists $level_and_of{$level} ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 139 | 403 | $level_and_of{$level} = 1; | |||||||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||||||||
| 141 | 2085 | ▶ | if ( $level_matched[$level] ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 142 | 2085 | ▶ | $self->debug_code | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 143 | and $self->debug_code->('rules next', "$level: And next rule."); | ||||||||||||||||||||||||||||||||||
| 144 | 2085 | redo RULE; | |||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||
| 146 | 0 | $rules = pop @parent_rules; | |||||||||||||||||||||||||||||||||
| 147 | 0 | () = pop @parent_pos; | |||||||||||||||||||||||||||||||||
| 148 | 0 | ▶ | $self->debug_code | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 149 | and $self->debug_code->('rules ignore following', "$level: Ignore following. Going back to parent."); | ||||||||||||||||||||||||||||||||||
| 150 | 0 | --$level; | |||||||||||||||||||||||||||||||||
| 151 | 0 | redo RULE; | |||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||
| 153 | 13779 | ▶ | if ( lc $rule eq 'begin' ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 154 | 5339 | @stack_result = (); | |||||||||||||||||||||||||||||||||
| 155 | 5339 | ▶ | $self->debug_code | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 156 | and $self->debug_code->('rules begin', "$level: Begin."); | ||||||||||||||||||||||||||||||||||
| 157 | 5339 | redo RULE; | |||||||||||||||||||||||||||||||||
| 158 | } | ||||||||||||||||||||||||||||||||||
| 159 | # done | ||||||||||||||||||||||||||||||||||
| 160 | 8440 | ▶ | if ( lc $rule eq 'end' ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 161 | my $is_and | ||||||||||||||||||||||||||||||||||
| 162 | = ! exists $level_and_of{$level} | ||||||||||||||||||||||||||||||||||
| 163 | || exists $level_and_of{$level} | ||||||||||||||||||||||||||||||||||
| 164 | 446 | ▶ | && $level_and_of{$level}; | ||||||||||||||||||||||||||||||||
|
Condition50%3/6
!exists $level_and_of{$level} || exists $level_and_of{$level} && $level_and_of{$level}
exists $level_and_of{$level} and $level_and_of{$level}
MC/DC0%0/3
!exists $level_and_of{$level} || exists $level_and_of{$level} && $level_and_of{$level}
!exists $level_and_of{$level}
exists $level_and_of{$level}
$level_and_of{$level}
Truth table50%2/4
not(A) || B and C
A= !exists $level_and_of{$level}B= exists $level_and_of{$level}C= $level_and_of{$level}
| |||||||||||||||||||||||||||||||||||
| 165 | 446 | ▶ | if ($is_and) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 166 | 446 | push @{ $stack_item->{match} }, @stack_result; | |||||||||||||||||||||||||||||||||
| 167 | 446 | ▶ | $self->debug_code | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 168 | and $self->debug_code->('rules end', "$level: End, so store data."); | ||||||||||||||||||||||||||||||||||
| 169 | } | ||||||||||||||||||||||||||||||||||
| 170 | 446 | redo RULE; | |||||||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||||||||
| 172 | # ref $rule is 'Regexp' or $rule is code | ||||||||||||||||||||||||||||||||||
| 173 | 7994 | pos ${$content_ref} = $pos; | |||||||||||||||||||||||||||||||||
| 174 | 7994 | ▶ | $self->debug_code | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 175 | and $self->debug_code->('rules current pos', "$level: Set the current pos to $pos."); | ||||||||||||||||||||||||||||||||||
| 176 | $has_matched | ||||||||||||||||||||||||||||||||||
| 177 | = my ($full_match, @result) | ||||||||||||||||||||||||||||||||||
| 178 | = ref $rule eq 'CODE' | ||||||||||||||||||||||||||||||||||
| 179 | ? $rule->($content_ref) | ||||||||||||||||||||||||||||||||||
| 180 | 7994 | ▶ | : ${$content_ref} =~ m{ \G ( $rule ) }xms; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 181 | 7994 | ▶ | $level_matched[$level] &&= $has_matched; | ||||||||||||||||||||||||||||||||
|
Condition66%2/3
$level_matched[$level] &&= $has_matched
MC/DC50%1/2
$level_matched[$level] &&= $has_matched
$level_matched[$level]
$has_matched
Truth table66%2/3
A &&= B
A= $level_matched[$level]B= $has_matched
| |||||||||||||||||||||||||||||||||||
| 182 | 7994 | ▶ | if ( exists $level_and_of{$level} ) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 183 | 1241 | ▶ | $level_and_of{$level} &&= $has_matched; | ||||||||||||||||||||||||||||||||
|
Condition100%3/3
$level_and_of{$level} &&= $has_matched
MC/DC100%2/2
$level_and_of{$level} &&= $has_matched
$level_and_of{$level}
$has_matched
Truth table100%3/3
A &&= B
A= $level_and_of{$level}B= $has_matched
| |||||||||||||||||||||||||||||||||||
| 184 | } | ||||||||||||||||||||||||||||||||||
| 185 | 7994 | ▶ | if ($has_matched) { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 186 | 2532 | push @stack_result, @result; | |||||||||||||||||||||||||||||||||
| 187 | 2532 | $pos += length $full_match; | |||||||||||||||||||||||||||||||||
| 188 | $self->debug_code | ||||||||||||||||||||||||||||||||||
| 189 | 2532 | ▶ | and do { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 190 | 0 | ▶ | my $rule_qr = ref $rule eq 'CODE' ? $rule->() : $rule; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 191 | 0 | $self->debug_code->( | |||||||||||||||||||||||||||||||||
| 192 | 'rules match', | ||||||||||||||||||||||||||||||||||
| 193 | "$level: Rule\n$rule_qr\nhas matched\n$full_match\nThe current pos is $pos.", | ||||||||||||||||||||||||||||||||||
| 194 | ); | ||||||||||||||||||||||||||||||||||
| 195 | }; | ||||||||||||||||||||||||||||||||||
| 196 | 2532 | redo RULE; | |||||||||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||||||||
| 198 | 5462 | $rules = pop @parent_rules; | |||||||||||||||||||||||||||||||||
| 199 | 5462 | $pos = pop @parent_pos; | |||||||||||||||||||||||||||||||||
| 200 | $self->debug_code | ||||||||||||||||||||||||||||||||||
| 201 | 5462 | ▶ | and do { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 202 | 0 | ▶ | my $rule_qr = ref $rule eq 'CODE' ? $rule->() : $rule; | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 203 | 0 | $self->debug_code->( | |||||||||||||||||||||||||||||||||
| 204 | 'rules no match', | ||||||||||||||||||||||||||||||||||
| 205 | "$level: Rule\n$rule_qr\nhas not matched. Going back to parent.", | ||||||||||||||||||||||||||||||||||
| 206 | ); | ||||||||||||||||||||||||||||||||||
| 207 | }; | ||||||||||||||||||||||||||||||||||
| 208 | 5462 | --$level; | |||||||||||||||||||||||||||||||||
| 209 | 5462 | redo RULE; | |||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||
| 211 | } | ||||||||||||||||||||||||||||||||||
| 212 | |||||||||||||||||||||||||||||||||||
| 213 | 28 | return $self; | |||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||
| 216 | 28 | ▶ | sub _cleanup_and_calculate_reference { | ||||||||||||||||||||||||||||||||
|
Subroutine
_cleanup_and_calculate_reference: called CC=3 SCAR=11.4
| |||||||||||||||||||||||||||||||||||
| 217 | 28 | my $self = shift; | |||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||
| 219 | 28 | my $stack = $self->stack; | |||||||||||||||||||||||||||||||||
| 220 | 28 | my $content_ref = $self->content_ref; | |||||||||||||||||||||||||||||||||
| 221 | 28 | @{$stack} = map { | |||||||||||||||||||||||||||||||||
| 222 | exists $_->{match} | ||||||||||||||||||||||||||||||||||
| 223 | 447 | ▶ | ? do { | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 224 | # calculate reference | ||||||||||||||||||||||||||||||||||
| 225 | 446 | my $pre_match = substr ${$content_ref}, 0, $_->{start_pos}; | |||||||||||||||||||||||||||||||||
| 226 | 446 | my $newline_count = $pre_match =~ tr{\n}{\n}; | |||||||||||||||||||||||||||||||||
| 227 | 446 | $_->{line_number} = $newline_count + 1; | |||||||||||||||||||||||||||||||||
| 228 | 446 | $_; | |||||||||||||||||||||||||||||||||
| 229 | } | ||||||||||||||||||||||||||||||||||
| 230 | # cleanup | ||||||||||||||||||||||||||||||||||
| 231 | : (); | ||||||||||||||||||||||||||||||||||
| 232 | 28 | } @{$stack}; | |||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||
| 234 | # debug if requested | ||||||||||||||||||||||||||||||||||
| 235 | 28 | ▶ | $self->debug_code | ||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||
| 236 | or return $self; | ||||||||||||||||||||||||||||||||||
| 237 | 0 | my $dump = Data::Dumper ## no critic (LongChainsOfMethodCalls) | |||||||||||||||||||||||||||||||||
| 238 | ->new([ $self->stack ], [ qw(stack) ]) | ||||||||||||||||||||||||||||||||||
| 239 | ->Indent(1) | ||||||||||||||||||||||||||||||||||
| 240 | ->Quotekeys(0) | ||||||||||||||||||||||||||||||||||
| 241 | ->Sortkeys(1) | ||||||||||||||||||||||||||||||||||
| 242 | ->Useqq(1) | ||||||||||||||||||||||||||||||||||
| 243 | ->Dump; | ||||||||||||||||||||||||||||||||||
| 244 | 0 | chomp $dump; | |||||||||||||||||||||||||||||||||
| 245 | 0 | $self->debug_code->('stack clean', $dump); | |||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||
| 247 | 0 | return $self; | |||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||
| 250 | 28 | ▶ | sub extract { | ||||||||||||||||||||||||||||||||
|
Subroutine
extract: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||
| 251 | 28 | my ($self, $arg_ref) = @_; | |||||||||||||||||||||||||||||||||
| 252 | |||||||||||||||||||||||||||||||||||
| 253 | 28 | $self->_parse_pos; | |||||||||||||||||||||||||||||||||
| 254 | 28 | $self->_parse_rules; | |||||||||||||||||||||||||||||||||
| 255 | 28 | $self->_cleanup_and_calculate_reference; | |||||||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||||||||
| 257 | 28 | return $self; | |||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||||||||
| 260 | 7 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||||||||
| 261 | |||||||||||||||||||||||||||||||||||
| 262 | 7 | 1; | |||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||
| 264 | __END__ | ||||||||||||||||||||||||||||||||||