NAME
Test::ModuleVersion - Module version test generator
SYNOPSIS
use Test::ModuleVersion;
my $tm = Test::ModuleVersion->new;
$tm->modules([
['DBIx::Custom' => '0.2108'],
['Validator::Custom' => '0.1426']
]);
$tm->test_script(output => 't/module.t');
DESCRIPTION
Test::ModuleVersion is test generator for module version check. If you run the test generated by Test::ModuleVersion, you can check the module version.
If module version test is failed, you can list module URLs.
Create version test
Let's create version test.
# mvt.pl
my $tm = Test::ModuleVersion->new;
$tm->modules([
['DBIx::Custom' => '0.2108'],
['Validator::Custom' => '0.1426']
]);
$tm->test_script(output => 't/module.t');
modules
attribute is set to the pairs of module and version. test_script
method print version test into t/module.t
file.
Run mvt.pl
$ perl mvt.pl
Test script t/module.t
is created.
...
$require_ok = require_ok('DBIx::Custom');
$version_ok = is($DBIx::Custom::VERSION, '0.2108', 'DBIx::Custom version: 0.2108');
$require_ok = require_ok('Validator::Custom');
$version_ok = is($Validator::Custom::VERSION, '0.1426', 'DBIx::Custom version: 0.1426');
...
Run version test
Run version test.
$ perl t/module.t
If module is not installed or version is different, test fail.
ok 1 - require DBIx::Custom;
not ok 2 - DBIx::Custom version: 0.2108
# Failed test 'DBIx::Custom version: 0.2108'
# at t/module.t.pl line 13.
# got: '0.2106'
# expected: '0.2108'
ok 2 - require Validator::Custom;
ok 3 - Validator::Custom version: 0.1426
List module URLs
You can list moudle URLs by list
command
$ perl t/module.t list
All module URLs in version test is output to STDOUT
.
http://cpan.metacpan.org/authors/id/K/KI/KIMOTO/DBIx-Custom-0.2108.tar.gz
...
You can list only test failed module URLs by --fail
option
$ perl t/module.t list --fail
Advanced
Module installation by cpanm
$ perl t/module.t list --fail | perl cpanm -L extlib
Module installation is very easy. Test failed module is installed into extlib
directory by cpanm.
HTTP client
Test::Module version switch two HTTP client as necessary.
These module is used to get module URLs from metaCPAN.
If LWP::UserAgent 5.802+ is installed, LWP::UserAgent is seleced. If not, HTTP::Tiny is selected.
--lwp
option force LWP::UserAgent.
$ perl t/module.t list --lwp
--no-lwp
option force HTTP::Tiny.
$ perl t/module.t list --no-lwp
HTTP proxy
export http_proxy=http://hostname:3001
http_proxy
environment variable enable you to use proxy server.
HTTP proxy authentication
export http_proxy=http://username:password@hostname:3001
If LWP::UserAgent 5.802+ is installed, proxy authentication is available. HTTP::Tiny don't support proxy authentication.
EXAMPELS
Basic1
# Directory
t / mvt.pl
/ module.t
extlib / lib / perl5 / Object / Simple.pm
/ Validator / Custom.pm
features:
- 1. Module is installed in
extlib/lib/perl5
- 2. Perl 5.008007+ is required
- 3. Object::Simple 3.625, Validator::Custom 0.1401
use Test::ModuleVersion;
use FindBin;
my $tm = Test::ModuleVersion->new;
$tm->lib('../extlib/lib/perl5');
$tm->before(<<'EOS');
use 5.008007;
=pod
run mvt.pl to create this module version test(t/module.t).
perl mvt.pl
=cut
EOS
$tm->modules([
['Object::Simple' => '3.0625'],
['Validator::Custom' => '0.1401']
]);
$tm->test_script(output => "$FindBin::Bin/t/module.t");
Basic2
# Directory
t / mvt.pl
/ module.t
extlib / lib / perl5 / LWP.pm
features:
- 1. LWP 6.03
-
LWP module distribution name is
libwww-perl
. If module name is different from distribution name, you can usedistnames
attribute.
use Test::ModuleVersion;
use FindBin;
my $tm = Test::ModuleVersion->new;
$tm->lib('../extlib/lib/perl5');
$tm->distnames({
'LWP' => 'libwww-perl',
});
$tm->modules([
['LWP' => '6.03'],
]);
$tm->test_script(output => "$FindBin::Bin/t/module.t");
Basic3
# Directory
t / mvt.pl
/ module.t
extlib / lib / perl5 / SomeModule.pm
features:
- 1. SomeModule 0.03 don't exist in CPAN
- 2. SomeModule exist in http://myhost/SomeModule-0.03.tar.gz
-
SomeModule is private module. If module exist in some URL, you can use
privates
attribute.
use Test::ModuleVersion;
use FindBin;
my $tm = Test::ModuleVersion->new;
$tm->lib('../extlib/lib/perl5');
$tm->privates({
'SomeModule' => 'http://myhost/%M.tar.gz',
});
$tm->modules([
['SomeModule' => '0.03'],
]);
$tm->test_script(output => "$FindBin::Bin/t/module.t");
ATTRIBUTES
before
my $code = $self->before;
$tm = $tm->before($code);
You can add some code before version test.
$tm->before(<<'EOS');
use 5.008007;
=pod
You can create this script(t/module.t) by the following command.
perl mvt.pl
=cut
EOS
distnames
my $distnames = $self->distnames;
$tm = $tm->distnames({
'LWP' => 'libwww-perl',
'IO::Compress::Base' => 'IO-Compress',
'Cwd' => 'PathTools',
'File::Spec' => 'PathTools',
'List::Util' => 'Scalar-List-Utils',
'Scalar::Util' => 'Scalar-List-Utils'
...
});
Module distribution name corresponding to module name. Some module have different distribution name. For example, LWP module distribution name is libwww-perl
.
you must set distnames
attribute to get module URL.
lib
my $lib = $self->lib;
$tm = $tm->lib('../extlib/lib/perl5');
$tm = $tm->lib(['../extlib/lib/perl5', ...]);
Module including pass from version test directory. use lib
is added to version test.
use lib "$FindBin::Bin/../extlib/lib/perl5";
modules
my $modules = $tm->modules;
$tm = $tm->modules($modules);
Pairs of module and version.
$tm->modules([
['DBIx::Custom' => '0.2108'],
['Validator::Custom' => '0.1426']
]);
Note that version must be string('0.1426'
), not number(0.1426
).
privates
my $privates = $tm->privates;
$tm = $tm->privates({
'SomeModule' => 'http://localhost/~kimoto/%M.tar.gz'
});
Private module URLs. you can get module URL if the module don't exist in CPAN. %M
is replaced by module-version
like SomeModule-0.01
.
METHODS
detect
my $modules = $tm->detect;
my $modules = $tm->detect(ignore => ['Perl', 'Test::ModuleVersion']);
Get all installed module. If you set ignore
option, the module is ignored.
Note that ExtUtils::Installed is used internally. This information will be not accurate in some cases.
test_script
my $test_script = $tm->test_script;
$tm->test_script(output => 't/module.t');
Return version test as string. If output
option is set, test is output to the file.
BACKWARDS COMPATIBILITY POLICY
If a functionality is DEPRECATED, you can know it by DEPRECATED warnings except for attribute method. You can check all DEPRECATED functionalities by document. DEPRECATED functionality is removed after five years, but if at least one person use the functionality and tell me that thing I extend one year each time he tell me it.
EXPERIMENTAL functionality will be changed without warnings.
AUTHOR
Yuki Kimoto, <kimoto.yuki at gmail.com>
LICENSE AND COPYRIGHT
Copyright 2012 Yuki Kimoto.
This program is free software; you can redistribute it and/or modify it under the terms of either: the GNU General Public License as published by the Free Software Foundation; or the Artistic License.
See http://dev.perl.org/licenses/ for more information.