develooper Front page | perl.perl5.porters | Postings from August 2022

Possible to override/overload "defined $var"?

Thread Next
From:
Ovid
Date:
August 6, 2022 15:35
Subject:
Possible to override/overload "defined $var"?
Message ID:
CA+M4CHunQ8tnJwMKEMJci57EC6w1dSH8_jRGo2OwLzs16kgt1w@mail.gmail.com
Hi all,

Currently, it doesn't appear that defined has a prototype, and thus cannot
be overridden.

    $ perl -lwe 'print prototype "CORE::defined"'
    Use of uninitialized value in print at -e line 1.

It would be useful to use overload defined (or overriding the non-existent
CORE::defined). For example, for a the NULL object pattern, having defined
$object return false could be very useful. For Unknown::Values (
https://metacpan.org/pod/Unknown::Values), having an "unknown" instance
return false for a defined check would tremendously improve the utility of
that code. This is espeicially true if the unknown value escapes the
namespace it's generated in and thus encounters code which doesn't know
about unknown values.

I haven't found a CPAN module which provides this, nor is it clear to me
how I could even begin to tinker with XS to implement this.

Any pointers would be appreciated.

Best,
Curtis "Ovid" Poe
CTO, All Around the World
World-class software development and consulting
https://allaroundtheworld.fr/

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