in reply to Heresy
This wasn't as syntactically sexy as I had been hoping for, due to the fact that you can't pass named subs to a function like you can pass anonymous ones.method 'somemethod', sub { # ... }
Any 'sub' within a 'class' declaration will always have a variable '$self' defined. If the sub is called bare, as in: my ($thing) = new Thing(); If no existing variable is referenced, then a new $self is created, and is populated with any 'our' declarations from the module. This avoids the problem that plagues 'OO' programs now where an object sub may be called with no object, meaning that the first item in the stack is not actually $self, but the first parameter, forcing you to check that the first param is actually an object.class Thing; our ($property,$size); sub new { return $self; # Returns a handle to this object } sub Implode { $size = 0; # Local to this object instance }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
(bbfu) Re: 'class' syntax (was: Heresy)
by bbfu (Curate) on May 09, 2001 at 03:31 UTC |