The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.


only::matching - Check that two Perl files are version-locked


At the start of your application's main module...

  package Foo;
  use strict;
  use vars qw{$VERSION};
      $VERSION = '1.00';

  # ...code...

And at the top of your front-end script that loads the module...

  use strict;
  use vars qw{$VERSION};
      $VERSION = '1.00';
  # Load our matching module
  use only::matching 'Foo';
  # ...code...


The only module provides a great deal of interesting and rich functionality, allowing you to install multiple copies of modules and limit the version of a module you load to various arbitrary patterns.

However, installing it creates some additional directories to your library tree for the multi-version support, and you have to be explicit about the versions you want to be compatible with.

This means for the case where you have a script and a module and it is important that no matter what happens with system paths or @INC paths, the script always loads the matching module, you need to change the code each revision to refer to the new version, or you have to do something like...

  use only 'Foo' => $VERSION;

Like only::latest, only::matching is a task-specific version of only for the specific case of having version-locked script to module loading.

Instead of the above, you say...

  use only::matching 'Foo';

... and you are guaranteed to get the correctly matching module version.

Because it only needs such limited and specific functionality only::matching also removes the multiversion support and is contained entirely in one small .pm file, to make bundling it a little easier as well.

Providing Params

The syntax for only::matching is the same as for only, except without the version number string.

Thus to load a module with default imports:

  # These are equivalent
  use Foo;
  use only::matching 'Foo';

To load a module passing params

  # These are also equivalent
  use Foo => 'bar', 'baz';
  use only::matching Foo => 'bar', 'baz';

To load a module explicitly without calling import

  # And these are equivalent
  use Foo ();
  use only::matching 'Foo', [];

Other than this, there's very little that you need to know.


This module is stored in an Open Repository at the following address.

Write access to the repository is made available automatically to any published CPAN author, and to most other volunteers on request.

If you are able to submit your bug report in the form of new (failing) unit tests, or can apply your fix directly instead of submitting a patch, you are strongly encouraged to do so as the author currently maintains over 100 modules and it can take some time to deal with non-Critcal bug reports or patches.

This will guarentee that your issue will be addressed in the next release of the module.

If you cannot provide a direct test or fix, or don't have time to do so, then regular bug reports are still accepted and appreciated via the CPAN bug tracker.

For other issues, for commercial enhancement or support, or to have your write access enabled for the repository, contact the author at the email address above.


Adam Kennedy <>


only, only::latest


Copyright 2006 Adam Kennedy.

This program is free software; you can redistribute it and/or modify it under the same terms as Perl itself.

The full text of the license can be found in the LICENSE file included with this module.