On Oct 13, 2005, at 9:47 AM, Matt Fowles wrote:
On 10/13/05, Brent 'Dax' Royal-Gordon <[EMAIL PROTECTED]> wrote:
Luke Palmer <[EMAIL PROTECTED]> wrote:
Okay, I seriously have to see an example of a submethod in use.

Likewise.  As far as I've seen, submethods are a kludge wedged in for
cases where you're actually calling all the way up the inheritence
tree. Personally, I've always thought a "cascade method" syntax would
be better for that:

    post method BUILD($foo, $bar) { ... }
    pre method DESTROY() { ... }

Cascade methods would be called (before|after) the indicated method in
a superclass was called.

I don't think there is a need to restrict it to the wrapping superclasses methods only, there is no reason that you could not also have them wrap a local method too if you wanted.

This might actually be a legitimate use for a submethod too.

pre method  foo () { ... } # this is inherited
submethod   foo () { ... } # this is not inherited
post method foo () { ... } # this is inherited

I could see this construct being quite useful in a "Template Method" pattern sort of way.

Their return values would probably be thrown
away.  I think they might actually be a sort of syntactic sugar for
inserting `call` in the method body, but that's an implementation
detail, really...

I have always wondered about the absence of these.  CLOS has them and
they look quite useful.

CLOS has "before", "after" and "around" method qualifiers actually. AFAIK, the return values of these methods are thrown away too, as Brent suggests.

One thing to keep in mind is that CLOS has generic functions instead of the usual methods-attached-to-a-class scheme. It also has no (simple) means of calling superclass methods and capturing the return values (at least AFAIK, I am sure someone has hacked the abilities, but I don't think it is part of the spec). The method qualifiers were added to CLOS to allow for this kind of behavior.

Since Perl 6 does not suffer from this same issue, method qualifiers are not *needed* like they are in CLOS. That said, they are a nice bit of syntactic sugar (as Brent points out).

Maybe this could be done with traits?

method BUILD ($foo, $bar) is post { ... }
method DESTROY () is pre { ... }

Or possibly with some kind of name-mangling:

method BUILD:post ($foo, $bar) { ... }
method DESTROY:pre () { ... }

Stevan











Reply via email to