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

I feel about this the same way I feel about all auto-generated class modules: if you already understand OO Perl and you happen to like the module in question, then go ahead and use it. Just as importantly, you should know the limits of the module so you know when to ditch it (just like any other tool). Personally, I would avoid Class::HPLOO simply because it relies on source filtering, which is always messy. If you can come up with a non-filtering solution with reasonable performance, I might use it.

----
I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
-- Schemer

: () { :|:& };:

Note: All code is untested, unless otherwise stated

Replies are listed 'Best First'.
Re: Re: How about class Foo {...} definition for Perl?
by gmpassos (Priest) on Jan 18, 2004 at 02:13 UTC
    Do you have some idea of how to make this without filtering, and without rebuild Perl?

    I suse Filter::Simple, and this is not very stable, since is very easy to break the syntax, specialy the place holders that Text::Balanced uses, that accept any char from 0 to 255, what will mess with the code if you have to much place holders, since you start to get #, @ , $ , @ , % in the code.

    I have fixed the problem using my own place holder over the previous place holder, but this is a hard work.

    Other fixes were made, because Text::Balanced also mess with q|qq|qr|qw|qx|tr|y|s|m! Well, I'm trying to make the best work here and test it a lot!

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

      It'd be difficult to get exactly the same syntax without a filter. A subroutine named class with a prototype of (@&) could get you part way there. It could be called like class 'Foo' extends => qw( Bar Baz ) { . . . };.

      Instead of using the builtin sub definition, you could create a new subroutine named method with a prototype of ($@&) which could be called as method method_name => ('$attr1', '@attr2', '%attr3') { . . . };. This would then generate the regular Perl subroutine.

      I probably got the prototypes wrong, as I don't usually have a use for them.

      Alternatively, you can do what everybody else is doing: wait for Perl6 :)

      ----
      I wanted to explore how Perl's closures can be manipulated, and ended up creating an object system by accident.
      -- Schemer

      : () { :|:& };:

      Note: All code is untested, unless otherwise stated