Home  |  Linux  | Mysql  | PHP  | XML
From:Eric Wilhelm Date:Mon Aug  4 01:11:39 2008
Subject:Re: PPI vs Acme::Bleach
# from Aristotle Pagaltzis
# on Sunday 03 August 2008 21:25:

>but if you consider all possible valid Perl code files
>that do something useful, it actually falls over most of the
>time. Grind your code through Acme::Bleach and give it PPI,
>f.ex.; you’ll get nothing interesting out the other side.

Is all code which does something useful using Acme::Bleach?  If so, no 
wonder I can't get any work done (because I obviously don't have any 
useful code installed or else Acme::Bleach would be on my workstation 
as a prereq.)

And anyway, given runnable code with Acme::Bleach, it would still 
contain the 'use Acme::Bleach' statement followed by a lot of special 
whitespace (which PPI would faithfully deliver to your parser), which 
means one could then just call brighten() and pass that to PPI -- a bit 
tricky if you want to load Acme::Bleach directly rather than using PPI 
to parse it and safely find the definition of brighten() ;-)

  eval {
    local *CORE::GLOBAL::open = sub {die};
    require Acme::Bleach;
  };
  my $white = Acme::Bleach::whiten('use Rod::Logic;');
  warn Acme::Bleach::brighten($white);

I'll not claim that PPI is perfect, but Acme::Bleach is a terrible 
example of it failing -- not just pathological but not even a true 
failure.

But on closer examination, one sees that perl is not actually parsing 
any of the Perl code which comes after 'use Acme::Bleach;', because it 
interprets that instruction as a BEGIN block and then interprets the 
code in Acme/Bleach.pm, which reads+rewrites your source and exit()s.  
So, perl didn't ever parse your Perl.  Even when you run the bleached 
code, the interpreter doesn't get past the use() statement and thus 
isn't parsing anything until it sees it come in through eval().

So, in effect PPI can *parse* bleached Perl better than perl.

So what Tom should have said is:

  Nothing but perl can interpret Perl.

--Eric
-- 
We who cut mere stones must always be envisioning cathedrals.
--Quarry worker's creed
---------------------------------------------------
    http://scratchcomputing.com
---------------------------------------------------
Navigate in group perl.module-authors at sever nntp.perl.org
Previous Next




  
© No Copyright
You are free to use Anything
Site Maintained by PHP Developer
Powered By PHP Consultants