You're completely missing the point of using the VERSION directive with use; to locate and load a precise module irrespective of it's location within @INC.

That's completely wrong for the following two reasons:

Nowhere does it say that use or require will attempt to locate a module of the correct version. Furthermore, the Perl equivalent of these functions is included in the documentation, and there's no such functionality in it.

The standard strict.pm is now around version 1.03; if my very own ../strict.pm is at version 1.04 and i used this..

BEGIN { push @INC, ".." } use strict 1.04;

what do you think a subsequent strict->VERSION() or $strict::VERSION would report?? Note where ".." is placed in @INC. There's no two ways around this, 1.04 it is as ../strict.pm is loaded.

For the reasons explained above, that's wrong.

>type d\strict.pm

package strict; our $VERSION = '1.04'; 1;

>perl -e "BEGIN { push @INC, 'd' } use strict 1.04; print strict->VERSION"

strict version 1.04 required--this is only version 1.01 at -e line 1. BEGIN failed--compilation aborted at -e line 1.

I favour use; for it's advantage in compile time invocation (preemption again) as opposed to require; which is invoked at run-time,

All else being equal, eval "use Module VERSION"; and require Module; ... execute at exactly the same time.

But all else isn't equal here. Your use is executed at "run-time" (since the eval is executed at "run-time") and my require is executed at "compile-time" (since it's in a BEGIN block).

Well ok, want proof-of-concept and the problem fully addressed?

This still has problems. Given your misunderstandings about the fundementals of execution order and of use Module VERSION, and given your lack of willingness to listen (I already posted a working solution and you're not asking for advice), I don't feel like outlining the problems with this code.

Note: All tests have been run in Perl 5.6.1, 5.8.0 and 5.8.8 with similar results.


In reply to Re^6: BEGIN and compile-time by ikegami
in thread BEGIN and compile-time by jbert

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.