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

Possible to override/overload "defined $var"?

Thread Next
August 6, 2022 15:35
Possible to override/overload "defined $var"?
Message ID:
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 (, 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.

Curtis "Ovid" Poe
CTO, All Around the World
World-class software development and consulting

Thread Next Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at | Group listing | About