in reply to Re: How to redefine a modules private function?
in thread How to redefine a modules private function?

AnyEvent::DNS::DOMAIN_PORT is a constant function, which means it gets inlined, and within AnyEvent::DNS, the instances of DOMAIN_PORT are replaced by 53...

I didn't know about this, and I don't want to hijack this thread, but I do have a tangential question.
I'm wondering if there is essentially no difference between doing:
sub DOMAIN_PORT() { 53 }
and
use constant DOMAIN_PORT => 53;
Is there any difference at all ?

Cheers,
Rob

Replies are listed 'Best First'.
Re^3: How to redefine a modules private function?
by haukex (Archbishop) on Mar 08, 2022 at 10:48 UTC
    I'm wondering if there is essentially no difference between doing: sub DOMAIN_PORT() { 53 } and use constant DOMAIN_PORT => 53; Is there any difference at all ?

    AFAIK not really, other than that constant does some checks on the constant names and that it keeps track of declared constants in %constant::declared - but they should both produce a constant function. (Even today you can still find the line *$full_name = sub () { $scalar }; in constant.pm.)