in reply to Re: Re: How about class Foo {...} definition for Perl?
in thread How about class Foo {...} definition for Perl?
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
|
|---|