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

The syntax seems fairly nice and more like 'standard' OO

One problem I see with this sort of thing, though, is that without completely parsing the whole filtered source file there are ways in which to confuse it. 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. I know this is not likely to happen normally, but it would be a nasty gotcha if it did.

It all comes down to the difficulty in parsing perl. I did something which involved inventing a bit of new notation for perl once. It worked ok, provided I avoided anything which would confuse it. It suffered this same problem though.

  • Comment on Re: How about class Foo {...} definition for Perl?

Replies are listed 'Best First'.
Re: Re: How about class Foo {...} definition for Perl?
by gmpassos (Priest) on Jan 17, 2004 at 23:43 UTC
    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".

      Ah. Cunning :)

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