Hildo Biersma wrote:
> 
> > =head1 TITLE
> >
> > Replace $self in @_ with self() builtin (not $ME)
> >
> 
> Don't impose your religion on others.  If people want 'this' instead of
> 'self', that should be just fine.

Whoa! I'm not imposing religion on others. FAR FROM IT! Maybe the
examples I demonstrated were too tricky and missed the main point.

Right now, a sub would be written as:

   sub mymethod {
       my $this_is_my_name = shift;
       @args = @_;
   }

Under this RFC, you would write it as:

   sub mymethod {
       my $this_is_my_name = self;
       @args = @_;
   }

The key difference is this: $_[0] always contains the first method
argument, regardless of whether you're in an object-oriented or
function-oriented context. So, if you need to support both (like CGI.pm
and my own File::Remote must), you don't have to write some special
method that detects whether $_[0] is a valid class ref (see
self_or_default in CGI.pm).

Instead, you know that all the args are always in @_:

   sub mymethod {
       my $ME = self;
       @args = @_;
   }

And you can now call this as:

   Class->mymethod
   Class::mymethod
   mymethod

And all will work without having to rewrite your sub.

This fixes a lot of stuff. Plus, "self" is one char shorter than
"shift"! ;-)

-Nate

Reply via email to