in reply to Re: Overriding Exporter::import
in thread Overriding Exporter::import

This method will usually not get called. Quoting "perldoc -f use":

If the VERSION argument is present between Module and LIST, then the `use' will call the VERSION method in class Module with the given version as an argument. The default VERSION method, inherited from the UNIVERSAL class, croaks if the given version is larger than the value of the variable `$Module::VERSION'.
The Exporter::require_version is only a fall-back for mistakes like: use My::Module qw( 5.5 MyFunc ); which should really be written as: use My::Module 5.5 qw( MyFunc ); Note how the version number doesn't have a comma after it.

So you need to have your module do some "sub VERSION" if you want to subvert the &UNIVERSAL::VERSION version of the sub.

        - tye (but my friends call me "Tye")

Replies are listed 'Best First'.
Re: (tye)Re: Overriding Exporter::import
by John M. Dlugosz (Monsignor) on Jul 19, 2001 at 22:26 UTC
    That's a relativly new feature, isn't it? I don't recall ever seeing the "indirect object" for use before.

    The perldoc you mentioned seems to be reciently updated, since it's not entirely consistant. It still says it's exactly the same as BEGIN { require Module; import Module LIST; } but doesn't mention VERSION. It should say BEGIN { require Module; Module::VERSION (VERSION); import Module LIST; } which is confusing because VERSION is used both as a actual token and as a placeholder, so whoever edits that should make other changes too.

    Who maintains the perldocs? I'd like to submit a correction or at least inform the proper person.

    —John

      Well, it isn't very new. It wasn't there in 5.001 but then "require VERSION" and "require Module VERSION" weren't either. There all were in 5.004. Unfortunately I don't have any versions between to check. But perl*delta.pod seems to imply that "use VERSION" and "use Module VERSION" were added at 5.004 and "require VERSION" before that.

      The docs could be updated to say BEGIN { require Module VERSION; import Module LIST; } rather than what you propose. (: Use perlbug to submit patches to documentation.

              - tye (but my friends call me "Tye")
        re :BEGIN { require Module VERSION; import Module LIST; }

        True, but less enlightening! It's telling you that import is being called, it ought to tell you that VERSION is being called, too.

        re "it was there...when?"

        According to perldelta, the v-string definitly wasn't in 5.005, and it's less clear whether it was changed between 5.6.0 and 5.6.1.

        If v-strings were not available, and the require Module version (list) requires a v-string literal, than it can't predate 5.6.x either, at least not in a way that's compatible with the current form.

        —John