Stories
Slash Boxes
Comments
NOTE: use Perl; is on undef hiatus. You can read content, but you can't post it. More info will be forthcoming forthcomingly.

All the Perl that's Practical to Extract and Report

use Perl Log In

Log In

[ Create a new account ]

ChrisDolan (2855)

ChrisDolan
  (email not shown publicly)
http://www.chrisdolan.net/

Journal of ChrisDolan (2855)

Thursday September 13, 2007
01:34 AM

15 of 20 grant-funded Perl::Critic policies done

[ #34435 ]

I wrote one pretty easy policy this week (RegularExpressions::ProhibitComplexRegexes) and one really hard one (RegularExpressions::ProhibitUnusedCaptures).

If any readers test that latter policy against some real world code, I'd appreciate the help. TO do so, get a Perl:Critic SVN checkout from the Perl-Critic-1.xxx branch and run P::C as usual. I'm concerned that there may be several scenarios I didn't think of. The problem sounds simple: make sure all captures get used somehow, either via $1, $2, ... variables or by catching the return value from the regexp in array context. But there are so many ways of doing either of those things...

Both of the new policies make use of Regexp::Parser by Jeff "japhy" Pinyan (because PPI doesn't parse the actual regexes). If you don't have that optional module installed, the policies pass silently. Regexp::Parser has a few missing features of regexp syntax, but nothing too important. My biggest complaint is that if you want it to parse with an "x" flag, you have to explicitly wrap the regexp with "(?x:...)" and there's no easy way to get just a subtree of the object model.

Interested in getting involved in P::C? Send a note to the P::C developer list and we'd be happy to point out a few policies on the to-do list that would be straightforward to write for a newcomer.

The Fine Print: The following comments are owned by whoever posted them. We are not responsible for them in any way.
 Full
 Abbreviated
 Hidden
More | Login | Reply
Loading... please wait.
  • I'd always thought it would be a good idea to add a method to the regexp PDOM classes to do that automagically.

    my $tree = $regexp->parse; or something...

    Sounds like Regexp::Parser needs a little tweaking before it's ready though.