"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


In reply to Re: List::BinarySearch and conditional tests with Test::More by davido
in thread List::BinarySearch and conditional tests with Test::More by glasswalk3r

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • 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:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.