| 1 | package Babble::Plugin::PostfixDeref; | ||||||||||
| 2 | |||||||||||
| 3 | 1 | ▶ | use Moo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 4 | |||||||||||
| 5 | 1 | my $scalar_post = q{ | |||||||||
| 6 | (?: | ||||||||||
| 7 | (?>(?&PerlOWS)) | ||||||||||
| 8 | (?: | ||||||||||
| 9 | (?: | ||||||||||
| 10 | (?>(?&PerlOWS)) -> (?>(?&PerlOWS)) | ||||||||||
| 11 | (?&PerlParenthesesList) | ||||||||||
| 12 | | | ||||||||||
| 13 | (?>(?&PerlOWS)) (?: -> (?&PerlOWS) )?+ | ||||||||||
| 14 | (?> \$\* | (?&PerlArrayIndexer) | (?&PerlHashIndexer) ) | ||||||||||
| 15 | ) | ||||||||||
| 16 | (?: | ||||||||||
| 17 | (?>(?&PerlOWS)) (?: -> (?&PerlOWS) )?+ | ||||||||||
| 18 | (?> \$\* | (?&PerlArrayIndexer) | (?&PerlHashIndexer) | (?&PerlParenthesesList) ) | ||||||||||
| 19 | )*+ | ||||||||||
| 20 | )?+ | ||||||||||
| 21 | (?: | ||||||||||
| 22 | (?>(?&PerlOWS)) -> (?>(?&PerlOWS)) | ||||||||||
| 23 | [\@%] | ||||||||||
| 24 | (?> \* | (?&PerlArrayIndexer) | (?&PerlHashIndexer) ) | ||||||||||
| 25 | )?+ | ||||||||||
| 26 | ) | ||||||||||
| 27 | }; | ||||||||||
| 28 | |||||||||||
| 29 | sub transform_to_plain { | ||||||||||
| 30 | 3 | ▶ | my ($self, $top) = @_; | ||||||||
|
Subroutine
transform_to_plain: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||
| 31 | 3 | $top->remove_use_argument(experimental => 'postderef'); | |||||||||
| 32 | 3 | $top->remove_use_argument(feature => 'postderef'); | |||||||||
| 33 | # TODO: cry about lvalues assignment to postfix derefs | ||||||||||
| 34 | my $tf = sub { | ||||||||||
| 35 | 4 | ▶ | my ($m) = @_; | ||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.2
| |||||||||||
| 36 | 4 | my ($term, $postfix) = $m->subtexts(qw(term postfix)); | |||||||||
| 37 | #warn "Term: $term"; warn "Postfix: $postfix"; | ||||||||||
| 38 | 4 | my $grammar = $m->grammar_regexp; | |||||||||
| 39 | 4 | my $strip_re = qr{ | |||||||||
| 40 | ( (?>(?&PerlOWS)) -> (?>(?&PerlOWS)) | ||||||||||
| 41 | (?> | ||||||||||
| 42 | (?> (?&PerlQualifiedIdentifier) | (?&PerlVariableScalar) ) | ||||||||||
| 43 | (?: (?>(?&PerlOWS)) (?&PerlParenthesesList) )?+ | ||||||||||
| 44 | | (?&PerlParenthesesList) | ||||||||||
| 45 | | (?&PerlArrayIndexer) | ||||||||||
| 46 | | (?&PerlHashIndexer) | ||||||||||
| 47 | | \$\* | ||||||||||
| 48 | ) | ||||||||||
| 49 | ) | ||||||||||
| 50 | ${grammar} | ||||||||||
| 51 | }x; | ||||||||||
| 52 | 4 | ▶ | while ($postfix =~ s/^${strip_re}//) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 53 | 1 | my $stripped = $1; | |||||||||
| 54 | 1 | ▶ | if ($stripped =~ /\$\*$/) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 55 | 1 | $term = '(map $$_, '.$term.')[0]'; | |||||||||
| 56 | } else { | ||||||||||
| 57 | 0 | $term .= $stripped; | |||||||||
| 58 | } | ||||||||||
| 59 | } | ||||||||||
| 60 | 4 | ▶ | if ($postfix) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 61 | 1 | my ($sigil, $rest) = ($postfix =~ /^\s*->\s*([\@%])(.*)$/); | |||||||||
| 62 | 1 | ▶ | $rest = '' if $rest eq '*'; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 63 | 1 | $term = '(map '.$sigil.'{$_}'.$rest.', '.$term.')'; | |||||||||
| 64 | } | ||||||||||
| 65 | 4 | $m->submatches->{term}->replace_text($term); | |||||||||
| 66 | 4 | $m->submatches->{postfix}->replace_text(''); | |||||||||
| 67 | 3 | }; | |||||||||
| 68 | 3 | $top->each_match_within(PrefixPostfixTerm => [ | |||||||||
| 69 | '(?: (?>(?&PerlPrefixUnaryOperator)) (?&PerlOWS) )*+', | ||||||||||
| 70 | [ term => '(?>(?&PerlTerm))' ], | ||||||||||
| 71 | [ postfix => '(?&PerlTermPostfixDereference)' ], | ||||||||||
| 72 | '(?: (?>(?&PerlOWS)) (?&PerlPostfixUnaryOperator) )?+' | ||||||||||
| 73 | ] => $tf); | ||||||||||
| 74 | 3 | $top->each_match_within(ScalarAccess => [ | |||||||||
| 75 | [ term => '(?>(?&PerlVariableScalar))' ], | ||||||||||
| 76 | [ postfix => $scalar_post ], | ||||||||||
| 77 | ] => $tf); | ||||||||||
| 78 | } | ||||||||||
| 79 | |||||||||||
| 80 | 1 | 1; | |||||||||