in reply to Re: How about class Foo {...} definition for Perl?
in thread How about class Foo {...} definition for Perl?

I had a quick look at the source code and it seems that if you were to put some of the things which the filter is replacing (eg the sub declerations) inside a quoted string they would still be replaced even though they clearly shouldn't.

No! I use Filter::Simple, and I parse subs and classes only in the 2nd part of the filter, where strings are in a place holder:

FILTER_ONLY( all => \&filter_html_blocks , code => \&CLASS_HPLOO , all + => \&dump_code ) ;
Soo, I take care about quoted strings! ;-P

Here's a valid code:

use Class::HPLOO ;#qw(dump) ; print "class null { sub n { 1 } }\n" ; class Foo { sub test { print "test>>@_\n" ; print " sub fake { 2 } \n" ; } }
Generated code:
print "class null { sub n { 1 } }\n" ; { package Foo ; use strict qw(vars) ; sub new { my $class = shift ; my $this = bless({} , $class) ; my $ret_this = $this->Foo(@_) if defined &Foo ; $this = $ret_this if ( UNIVERSAL::isa($ret_this,$class) ) ; $this = undef if ( $ret_this eq '0' ) ; return $this ; } sub test { my $this = shift ; print "test>>@_\n" ; print " sub fake { 2 } \n" ; } }

Graciliano M. P.
"Creativity is the expression of the liberty".

Replies are listed 'Best First'.
Re: Re: Re: How about class Foo {...} definition for Perl?
by hhdave (Beadle) on Jan 18, 2004 at 00:39 UTC

    Ah. Cunning :)

    I hadn't realised that. I guess I'm not up to date on perl source filtering modules/techniques.