develooper Front page | perl.perl5.porters | Postings from December 2015

Re: Proposal: Add {-as => 'new_name'} feature to Exporter.pm

Thread Previous | Thread Next
From:
Abigail
Date:
December 18, 2015 10:14
Subject:
Re: Proposal: Add {-as => 'new_name'} feature to Exporter.pm
Message ID:
20151218101426.GA23870@almanda.fritz.box
On Fri, Dec 18, 2015 at 02:33:17AM +0100, demerphq wrote:
> On 18 December 2015 at 02:15, Lukas Mai <plokinom@gmail.com> wrote:
> > Am 18.12.2015 um 01:39 schrieb demerphq:
> >>
> >> On 18 December 2015 at 00:14, Chad Granum <exodist7@gmail.com> wrote:
> >>>
> >>> new patch
> >>>
> >>> On Thu, Dec 17, 2015 at 2:57 PM, Chad Granum <exodist7@gmail.com> wrote:
> >>>>
> >>>>
> >>>> No sooner did I send that then I realize did could do it better with 1
> >>>> less loop. Will attach new patch shortly.
> >>
> >>
> >> I have one concern with the patch. It uses ref($foo) eq "HASH".
> >>
> >> I think it should import reftype() from Scalar::Util and use reftype()
> >> instead.
> >>
> >> Or possibly be switched to use UNIVERSAL::isa($foo,"HASH").
> >>
> >> IOW, what happens if $foo is blessed?
> >
> >
> > reftype is for deliberately breaking encapsulation of objects.
> 
> That is one view, but one I consider unperlish.
> 
> If someone wants to pass you a blessed hashref where you ask for a
> hashref why should you care? Its their code. Its their encapsulation
> that is being violated, or not. IMO its not a libraries job to decide
> whether such things are ok or not.
> 
> How does the line go? "Perl would prefer you dont enter its living
> room without permission, but it isnt going to stand at the door with a
> shotgun to make sure you dont."


Hmm. Not sure whether that line is relevant here -- it's more 
"We'll enter your living room, because you don't have a gun".


Disallowing blessed references means you keep that slot open 
for objects. That is,

    use Some::Module 'some_method' => $obj;

remains available for some future use.


But I guess this is all just a theoretical exercise. How many people
would pass in "bless {-as => 'fnord'}, 'Whatever'" anyway?


Abigail

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