HaukeX already explained that constant folding is happening.
This means the value is inlined at compile time, and you'd need to intercept the compilation between sub declaration and first call.
The default answer is that you need to a hard patch of the code (no monkey patch, copy it into another namespace)
I can't remember a clean possibility to register a callback to be called right after the sub declaration.
- salva already tried to tie the STASH, but this would surprise me.
- maybe it's possible to hack the attribute mechanism such that an invisible attribute is activated sub DOMAIN_PORT :magic_attribute but I'm not optimistic.
- Another approach would be to use the debugger with a watch expression which redefines the sub after the breakpoint. But this would require to deactivate the debugger afterwards. I seem to remember that it's possible to dynamically (de)activate the debugger via a special CPAN module. something like "enbugger"
- IMHO the most likely approach is to trigger error handling. In case you define your own sub prior to loading the module, Perl should throw a "redefined" warning and you can intercept that via $SIG{__WARN__} -handler. I would try that.
Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
Read Where should I post X? if you're not absolutely sure you're posting in the right place.
Please read these before you post! —
Posts may use any of the Perl Monks Approved HTML tags:
- a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
| |
For: |
|
Use: |
| & | | & |
| < | | < |
| > | | > |
| [ | | [ |
| ] | | ] |
Link using PerlMonks shortcuts! What shortcuts can I use for linking?
See Writeup Formatting Tips and other pages linked from there for more info.