in reply to Re^2: Why eval $version?
in thread Why eval $version?

This works for the same reason, why eval $VERSION works, when numifying a string Perl accepts all digits till it encounters a non-digit.

So when comparing numerically the strings won't pose a problem.

That behavior is inherited from a C function a can't recall something like atonumber().

Cheers Rolf
(addicted to the Perl Programming Language :)
Wikisyntax for the Monastery

Replies are listed 'Best First'.
Re^4: Why eval $version?
by Haarg (Priest) on Jul 09, 2020 at 18:33 UTC
    No, it works because on perl 5.10 and newer, version comparisons done by a use are performed using version (or an equivalent core routine) that accounts for the underscores, as well as multi-part versions (e.g. v1.2.3).
      So use is compiling the module found in @INC first and checks the executed package var $VERSION then?

      Hence no a priori static parsing of the source ?

      Cheers Rolf
      (addicted to the Perl Programming Language :)
      Wikisyntax for the Monastery

        Correct. use Module 1.2; is equivalent to:

        BEGIN {
            require Module;
            Module->VERSION(1.2);
            Module->import;
        }
        

        The ->VERSION method on perl 5.8 just uses a simple numeric comparison against $VERSION. On modern perls, it understands both numeric versions and multi-part versions, as well as underscores. The version.pm module can be loaded on perl 5.8 to allow it to understand these versions.

        "Static" parsing is done by the toolchain modules that are concerned with installing, updating, and indexing perl modules. These modules don't want to have to load the entire module to be able to compare versions. They also need to be able to work with modules that are not able to be loaded, such as not having their dependencies available or requiring an XS component that is not compiled yet. With a use call, you are already telling perl to load the file, so there's no need for the extra work involved in "static" parsing.