Oberon has asked for the wisdom of the Perl Monks concerning the following question:
O wise and benevolent masters, I humbly lay my unworthy question at your feet:
My module exports a compile-time constant to its caller. It's important that it be a compile-time constant so the optimizer can take advantage of that. So I create it thusly (in my import):
eval "sub ${caller_package}::DEBUG () { $debug_value }";
The problem is that now Pod::Coverage calls DEBUG a naked subroutine in the caller, which of course fails the ubiquitous Test::Pod::Coverage tests. I decided to look and see how Pod::Coverage was figuring out whether a sub was imported or not, and discovered this bit of Black Magic:
# see if said method wasn't just imported from elsewhere my $glob = do { no strict 'refs'; \*{$sym} }; my $o = B::svref_2object($glob); # in 5.005 this flag is not exposed via B, though it exists my $imported_cv = eval { B::GVf_IMPORTED_CV() } || 0x80; next if $o->GvFLAGS & $imported_cv;
After my head stopped hurting, I decided to just give up and change my code so it really is imported, like so:
eval "sub DEBUG () { $debug_value }"; *{ join('::', $caller_package, 'DEBUG') } = \&DEBUG;
Sure enough, that shuts up Pod::Coverage, but now my compile-time constant isn't a compile-time constant any more. :-/
Now, obviously I know that I can just tell Test::Pod::Coverage to ignore that routine, but I don't think it's reasonable to tell anyone who uses my module to do so. I'm willing to set that bitflag that Pod::Coverage is relying on manually, but I have no idea how to go about that ... that's perlguts stuff, which is a bit beyond my skill level (although I'm willing to attempt it, if anyone could point me in the right direction).
Any thoughts on the best way to get Pod::Coverage to ignore my routine when it's exported to other packages?
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re: How to get Pod::Coverage to stop calling my export naked (closure)
by tye (Sage) on Feb 04, 2012 at 20:12 UTC | |
by Oberon (Monk) on Feb 04, 2012 at 21:28 UTC | |
by tobyink (Canon) on Feb 06, 2012 at 08:37 UTC | |
|
Re: How to get Pod::Coverage to stop calling my export naked
by educated_foo (Vicar) on Feb 05, 2012 at 04:48 UTC | |
|
Re: How to get Pod::Coverage to stop calling my export naked
by LanX (Saint) on Feb 05, 2012 at 12:00 UTC | |
by Oberon (Monk) on Feb 06, 2012 at 01:07 UTC | |
|
Re: How to get Pod::Coverage to stop calling my export naked
by Xiong (Hermit) on Feb 05, 2012 at 04:16 UTC |