develooper Front page | perl.perl5.porters | Postings from September 2011

Re: Package:: still ambiguous

Thread Previous | Thread Next
From:
Zefram
Date:
September 14, 2011 05:55
Subject:
Re: Package:: still ambiguous
Message ID:
20110914125515.GP18211@lake.fysh.org
Rafael Garcia-Suarez wrote:
>>        $obj = $pkg->new();   # unambiguously call class method
>
>That works with $pkg being a string, right now.

No, that's how I started this thread.  If $pkg is, say, the string
"Foo::Bar", then it is ambiguous between the package Foo::Bar and the
I/O handle *Foo::Bar{IO}.  The I/O handle meaning takes precedence,
if there is a handle of that name.

$ perl -E 'package Foo::Bar { sub say { say "Foo::Bar::say(@_)" } } open(\*Foo::Bar, ">&STDOUT"); $pkg = "Foo::Bar"; $pkg->say(123)' 
123

>I would prefer avoiding thinking about $pkg as a special kind of
>object.

You're thinking of "object" in the OO sense.  I meant it in the looser
sense, of anything that the language can manipulate by first-class
mechanisms.  It's an object in the same sense in which an (unblessed)
array is an object.  We could well call it merely a "package".  It would
probably end up implemented as an svtype, SVt_PVPK.

-zefram

Thread Previous | Thread Next


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