On 3/2/06, Jonathan Lang <[EMAIL PROTECTED]> wrote:
> Can subs be declared within classes?  Can methods be declared without
> classes?  If the answers to both of these questions are "no", then it
> occurs to me that you _could_ unify the two under a single name, using
> the class boundary as the distinguishing factor (e.g., a method is
> merely a sub declared within a class).  If the answer to either is
> "yes", I'd be curious to know how it would work.

I would say "yes".

Having subs inside classes makes creating small utility functions
easier. You could also use private methods for this, but if I dont
need to pass the object instance, why make me? I will say that I think
this distinction will be difficult at first for people steeped in Perl
5 OO.

Having methods outside of classes is less useful, and most of it's
uses are pretty esoteric, however I see no good reason not to allow it
(especially anon methods, as they are critical to being able to do
some of the cooler meta-model stuff).

A method probably cannot be invoked without first being attached to a
class somehow because it needs something to SMD off of.  But you could
almost look at a bare (and named) method as a mini-role, so that:

method unattached_method ($::CLASS $self:) { ... }

is essentially equivalent to this:

role unattached_method {
    method unattached_method ($::CLASS $self:) { ... }
}

which of course brings up the possibility of this syntax:

$object does unattached_method;
^Object does unattached_method;

as a means of adding methods to a class or object (ruby-style
singleton methods).

Of course, this could also just be my not-quite-caffinated-enough
brain talking too.

Stevan

Reply via email to