> sub do_stuff {
> my $self = self;
> $self->{STATE}->{something} = @_;
> }
>
> sub error {
> carp @_ if self->config('VerboseErrors');
> }
I've never really seen anything like this before in other languages (Is that
good or bad?). The closest is Java's odd use of the super function as the
first line of a constructor.
The first problem I see with this is in [my understanding of] how perl
handles objects currently.
func class csv;
is the same as
class->func( csv )
Which internally becomes a lookup for the proper func based on @ISA, but
ultimatly class gets unshifted onto the stack of parameters.
The only way I can see an easy way of hiding the passage of $self is by
offsetting @_ by one, making $_[ -1 ] = $self. Which is obviously
unaddressible. Self would simply make the internal c array-lookup to
[ -1 ]. Either this sort of space would always have to be available, or the
function itself would have to be flagged for it... As in:
sub do_stuff: method {
my $this = self; # I'm old fashioned, leave me alone
} # end do_stuff
All accesses to methods would then require the method function-attribute.
Otherwise self could just be an alias for shift. In this way, you maintain
compatibility (except for those poor souls that currently use method,
locked)
-Michael