in reply to List::BinarySearch and conditional tests with Test::More
"Am I missing something here, or should I contact the module author? :-)"
Knowingly or not, you just did! :)
tobyink is on the right track, though you should be passing the haystack array by reference if you override the prototypes because the prototype is (&$\@), so pass by ref is what the function expects. ...I mention this in a followup to tobyink's otherwise perfect solution.
As for the funky import override: I used goto &subroutine instead of calling SUPER::subroutine() because the former fixes up the call stack nicely so that Exporter::import never knows something else came first. But in retrospect, it probably wouldn't hurt to just call SUPER::....
Oh, and the reason that we're overriding import in the first place is because in Perl versions prior to 5.20 there was a problem where a single use of $a and $b in your script (except if affiliated with sort) would trigger some unwanted "used only once" warnings. This little import trick assured that $a and $b weren't used only once. ...an ugly hack. Come to think of it, I should probably only be overriding if I detect the Perl version predates 5.20, rather than the logic currently in place.
So if you aren't importing anything, it is probably a good idea to put no warnings 'once'; inside of the callback subroutine. If this seems even more ugly, it is... and it is not unique to List::BinarySearch either. List::Util and List::MoreUtils were suffering from the same nuisance as well, until Perl 5.20 came along, allowing $a and $b to become exempt from this warning.
If you feel strongly enough that the override/goto code should be done differently please (and I mean this in all honesty), submit an issue at https://github.com/daoswald/List-BinarySearch/issues. Issues that include code, tests, and a strong argument are highly compelling to me. ;)
At any rate, if this discussion doesn't lead you to a workable solution, please do post a GitHub issue so that it remains enough of an annoyance to me that I fix it. I despise leaving issues unresolved. :)
Dave
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: List::BinarySearch and conditional tests with Test::More
by glasswalk3r (Friar) on Nov 30, 2014 at 17:42 UTC | |
by davido (Cardinal) on Dec 01, 2014 at 16:58 UTC |