develooper Front page | perl.perl6.language.objects | Postings from August 2000

Re: RFC 152 (v1) Replace $self in @_ with self() builtin (not $ME)

From:
Bart Lateur
Date:
August 24, 2000 13:45
Subject:
Re: RFC 152 (v1) Replace $self in @_ with self() builtin (not $ME)
Message ID:
f52bqskhom0r4guq9ma6u669a5emlst3eb@4ax.com
On Thu, 24 Aug 2000 13:27:01 -0700, Nathan Wiger wrote:

>It's a pain if you want to support both function-oriented and
>object-oriented calling forms, as CGI.pm does. For example, you can use
>both of these:
>
>   print header;
>   print $r->header;
>
>with CGI.pm. Now you need a self_of_default special method, since
>sometimes $_[0] has a class ref and sometimes it has the first method
>argument.

Don' forget to mention that if the sub can also be used as a class
method, the is NO WAY to distinguish between

	CGI->header
and
	header("CGI")

Hence, with some values for the functional argument, the detection
mechanism is unreliable.

Either $ME or self() (which, BTW, is more related to caller() than to
ref()) is 100% reliable.

-- 
	Bart.



nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About