in reply to Overriding Exporter::import

You can override the require_version() routine in your Exporter-derived modules. It gets passed the version. See the Exporter manpage, in the section labeled Module Version Checking.

Replies are listed 'Best First'.
(tye)Re: Overriding Exporter::import
by tye (Sage) on Jul 19, 2001 at 09:00 UTC

    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")
      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")