SPUG: September meeting question

Joshua ben Jore twists at gmail.com
Wed Nov 8 13:57:10 PST 2006

On 11/8/06, Paul Cook <ppcook at gmail.com> wrote:
> Here is what Josh ben Jore said in response to my same question:
> -------------------------
> On 10/29/06, Paul Cook <ppcook at gmail.com> wrote:
> > Thanks Josh. I'm a novice. What does dual-lifed mean?
> It lives soley in core perl right now but will be available separately
> on CPAN soon. This allows you to upgrade the module without upgrading
> perl.

So it's a nice thought but my home is full of boxes and I don't have
the computer with ~/src uncrated so I figure "soon" is pretty
relative. The latest B::Lint
fixes it to work on threaded perls (that's the major bug, I think),
and adds some new stuff like making it use plugins.

I also make all uses of <> a warning because it's evil. Most people
should write linty things in Perl::Critic. Some things can't be done
in P::C because the interpreter has to compile the code first for it
to be sane (things like "does this function exist?" aren't possible in
P::C). When it's impossible in P::C, write it in B::Lint. The plugin
interface sucks right now though. It should use Module::Pluggable.

As an example, here's a plugin I wrote to find uses of C<sort { $a <
$b }> which occurred to someone else's co-worker and probably anyone
who is expecting something C++ like.

package B::Lint::Plugin::SortOperator;
use B::Lint;
B::Lint->register_plugin( __PACKAGE__ => [qw[ sort-operator ]] );
use List::MoreUtils 'any';

sub match {
   my $op = shift @_;

   return unless $op->isa( 'B::LISTOP' )
     and $op->name eq 'sort';

   # perl -MO=Concise -e 'print sort { $a < $b } @X'
   # (sort
   #    (pushmark) s ->5
   #    (null
   #       (scope
   #            (ex-nextstate)
   #            (lt
   #               (ex-rv2sv
   #                  (gvsv "a"))
   #               (ex-rv2sv
   #                (gvsv "b")))))
   #    (rv2av
   #       (gv "X")))
   my $comparison_op = eval { $op->first->sibling->first->first->sibling }
     or return;

   # <, >, lt, gt
   return unless $comparison_op->name =~ /^s?[lg]t\z/;

   B::Lint::warning( 'Invalid use of a comparison operator' );


More information about the spug-list mailing list