Front page | perl.perl5.porters |
Postings from July 2012
Re: Objects without stashes?
Thread Previous
From:
Father Chrysostomos
Date:
July 29, 2012 19:04
Subject:
Re: Objects without stashes?
Message ID:
AE05F084-9E2A-4D4B-8BBA-C4D00EC15305@cpan.org
On Jul 29, 2012, at 6:58 PM, Rev. Chip wrote:
> On Sun, Jul 29, 2012 at 07:00:10PM -0500, Jesse Luehrs wrote:
>> On Sun, Jul 29, 2012 at 04:44:14PM -0700, Rev. Chip wrote:
>>> On Sun, Jul 29, 2012 at 01:40:16PM -0700, Father Chrysostomos wrote:
>>>> Rev. Chip said:
>>>>> I didn't use the term "stash" or "glob", and that was on purpose. I would
>>>>> like to see this work, where the RHS of bless is a simple hash that stays
>>>>> simple:
>>>>>
>>>>> bless [0], { inc => sub { ++$_[0][0] },
>>>>> dec => sub { --$_[0][0] },
>>>>> DESTROY => sub { print "BYE\n" } };
>>>>
>>>> bless [0], package { sub inc { ++$_[0][0] },
>>>> sub dec { --$_[0][0] },
>>>> DESTROY { print "BYE\n" } };
>>>
>>> Sweet. How would one go about inspecting this stash, given $obj = <that expression>?
>>
>> The same way you'd inspect any other stash, I'd imagine.
>
> You'd have to get access to it. The return value of blessed() is a name.
Would it be?
> So how?
my $package = package { ... };
my $obj = bless [0], $package;
# ... do stuff with $package ...
Or:
my $obj = bless [0], package {
sub package { __PACKAGE __ } # returns ref
};
# ... do stuff with $obj->package ...
Anyone want to file an RT ticket? :-)
Thread Previous