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:
use Module VERSION loads the first module in @INC, regardless of it's version.
>type a\Module.pm
package Module; our $VERSION = '1.00'; 1;
>type b\Module.pm
package Module; our $VERSION = '1.01'; 1;
>perl -e "BEGIN { @INC = qw( a b ); } use Module 1.01;"
Module version 1.01 required--this is only version 1.00 at -e line 1. BEGIN failed--compilation aborted at -e line 1.
It works this way because Perl doesn't know what the module will store in $VERSION until the module has run.
use Module VERSION will successfully load a module whose version is greater than VERSION. A precise match is NOT needed.
>type c\Module.pm
package Module; our $VERSION = '1.02'; 1;
>perl -le "BEGIN { @INC = qw( c ); } use Module 1.01; print values %INC"
c/Module.pm
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
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |