develooper Front page | perl.perl5.porters | Postings from October 2003

Re: [PATCH pod/perlfunc.pod] ref can return false on references

Thread Previous | Thread Next
From:
Nick Ing-Simmons
Date:
October 7, 2003 00:21
Subject:
Re: [PATCH pod/perlfunc.pod] ref can return false on references
Message ID:
20031007072041.2484.2@llama.elixent.com
Gisle Aas <gisle@ActiveState.com> writes:
>Graham Barr <gbarr@pobox.com> writes:
>
>> On 6 Oct 2003, at 17:52, Gisle Aas wrote:
>> 
>> > Graham Barr <gbarr@pobox.com> writes:
>> >
>> >>>>    $ perl -wle 'print ref bless [] => 0'
>> >>>>    0
>> >>>
>> >>> I would be tempted to make that bless illegal.
>> >>
>> >> I dont see why we should treat that specially. People can always bless
>> >> into a package which has overload and have that return false.
>> >
>> > I don't think you are able to overload on the class name.  The HvNAME
>> > is just a char*.
>> 
>> I did not mean overload the package name itself, but rather
>> 
>> package False;
>> 
>> use overload bool => sub { 0 }
>> 
>> 1;
>> 
>> Any reference blessed into that package will be false in a boolean
>> context.
>
>Sure.  But since that does not make ref(bless [], "False") false so I
>don't see how this is relevant to whether bless $something, "0" should
>be allowed.

I was thinking of something like final clause below:

PP(pp_bless)
{
    dSP;
    HV *stash;

    if (MAXARG == 1)
	stash = CopSTASH(PL_curcop);
    else {
	SV *ssv = POPs;
	STRLEN len;
	char *ptr;

	if (ssv && !SvGMAGICAL(ssv) && !SvAMAGIC(ssv) && SvROK(ssv))
	    Perl_croak(aTHX_ "Attempt to bless into a reference");
        if (!SvTRUE(ssv)) 
	    Perl_croak(aTHX_ "Attempt to bless to a false value");


But frankly if anyone wants to bless into "0" that is their problem.

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