Subject: | ProhibitAmpersandSigils with parens |
Date: | Sat, 30 Aug 2008 09:21:31 +1000 |
To: | bug-perl-critic [...] rt.cpan.org |
From: | Kevin Ryde <user42 [...] zip.com.au> |
ProhibitAmpersandSigils allows
defined &foo
but doesn't with parens like
defined(&foo)
It'd be good if it let you do that (and leave ProhibitParensWithBuiltins
to deny such parens, for those who don't like them).
Perhaps something like:
--- ProhibitAmpersandSigils.pm.old 2008-07-25 08:48:25.000000000 +1000
+++ ProhibitAmpersandSigils.pm 2008-08-30 09:16:58.000000000 +1000
@@ -46,8 +46,20 @@
return if ( $elem !~ m{\A [&] }mx ); # ok
- my $previous = $elem->sprevious_sibling();
- return if $previous and $EXEMPTIONS{$previous};
+ # look up past parens to get say the "defined" in "defined(&foo)"
+ if (! $psib) {
+ my $parent = $elem->parent();
+ if ($parent && $parent->isa('PPI::Statement::Expression')) {
+ my $grandparent = $parent->parent();
+ if ($grandparent && $grandparent->isa('PPI::Structure::List')) {
+ my $word = $grandparent->sprevious_sibling();
+ if ($word && $word->isa('PPI::Token::Word')) {
+ $psib = $word;
+ }
+ }
+ }
+ }
+ return if $psib and $EXEMPTIONS{$psib};
return $self->violation( $DESC, $EXPL, $elem );
}
--
"The most rewarding part was when he gave me my money."