NAME
Test::ModuleVersion - Module Version Test Generator (EXPERIMENTAL)
SYNOPSIS
use Test::ModuleVersion;
# Manually
my $tm = Test::ModuleVersion->new;
$tm->modules([
['DBIx::Custom' => '0.2108'],
['Validator::Custom' => '0.1426']
]);
print $tm->test_script;
# Automatically
my $tm = Test::ModuleVersion->new;
$tm->ignore([qw/Devel::NYTProf MySQL::Diff/]);
$tm->detect;
print $tm->test_script;
DESCRIPTION
It is very difficult to install same modules in development environment and production environment.
cpan
is single versioning system, so you can't install specified version module well.
Installation is very hard work if therer many modules. Test::ModuleVersion help you.
Create version checking test in development
environment.
At first, you create test script in development
environment.
Test::ModuleVersion create version checking test manually or automatically
This is manually
eamples.
my $tm = Test::ModuleVersion->new;
$tm->modules([
['DBIx::Custom' => '0.2108'],
['Validator::Custom' => '0.1426']
]);
print $tm->test_script;
You set modules
attribute which is list of module name and version number. You can get module test script by test_script
method.
run this script(name is mvt.pl
) to create test.
$ perl mvt.pl > t/module.t
the following-like test is created.
require_ok('DBIx::Custom');
module_version_is('DBIx::Custom', ExtUtils::Installed->version('DBIx::Custom'), '0.2108');
require_ok('Validator::Custom');
module_version_is('Validator::Custom', ExtUtils::Installed->version('Validator::Custom'), '0.1426');
Or you can create module test automatically
.
my $tm = Test::ModuleVersion->new;
$tm->ignore([qw/Devel::NYTProf MySQL::Diff/]);
$tm->detect;
print $tm->test_script;
ignore
attribute is set to modules you want to ignore. detect
method detect all installed module and modules
attribute is set properly.
Run test in production
environment.
Second, the test script is moved to production
environment, and run the test.
perl t/module.t
If the version in production
environment is different from development
one, test will fail.
ok 1 - require DBIx::Custom;
not ok 2 - DBIx::Custom version: 0.2108
# Failed test 'DBIx::Custom version: 0.2108'
# at module.t.pl line 13.
# got: '0.2106'
# expected: '0.2108'
ok 2 - require Validator::Custom;
ok 3 - Validator::Custom version: 0.1426
It is very useful because you can know the module differnce.
Get module URLs
If test fail, you usually install the module manually, it is very hard work. you can get module URLs by list
command.
$ perl module.t list
URLs of all module in test sciprt is printed.
http://cpan.metacpan.org/authors/id/K/KI/KIMOTO/DBIx-Custom-0.2108.tar.gz
...
Internally, metaCPAN api is used to get module URL. if you have proxy server, you can set $ENV{http_proxy}.
You can also get test failed module URL by --fail
option.
$ perl module.t list --fail
Module installation using cpanm is very easy if cpanm is in current directory.
$ perl t/module.t list --fail | perl cpanm -L extlib
Modules is installed into extlib
directory.
If LWP::UserAgent is available and version is 5.802+, test script use LWP::UserAgent for HTTP request. If LWP::UserAgent is not available, test script use HTTP::Tiny.
If you don't use LWP::UserAgent, use --no-lwp
option.
$ perl module.t list --no-lwp
If you force LWP::UserAgetn, use --lwp
option.
Have a fun to use Test::ModuleVersion.
ATTRIBUTES
before
my $code = $self->before;
$tm = $tm->before($code);
You can add some code before test script.
$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 is not same distribution name as module name, like LWP module.
LWP is module name, but distribution name is libwww-perl
. If right distribution name is unknown, Test::ModuleVersion can't get module URL, so you must set distnames
attribute when distribution name is not same as module name.
lib
my $lib = $self->lib;
$tm = $tm->lib('extlib/lib/perl5');
$tm = $tm->lib(['extlib/lib/perl5', ...]);
Module including pass from script directory. The following code is added to test script.
use lib "$FindBin::Bin/extlib/lib/perl5";
If the module is installed in this directory, module version test is success.
ignore
my $ignored_modules = $tm->ignore;
$tm = $tm->ignore([qw/Devel::NYTProf MySQL::Diff/]);
ignored modules you don't want to contain in test script.
default_ignore
my $ignored_modules = $tm->ignore;
$tm = $tm->ignore(['Perl', 'Test::ModuleVersion']);
Default ignored modules you don't want to contain in test script, default to ['Perl']
.
Don't use exculde_default
attribute usually. use ignore
attribute instead.
modules
my $modules = $tm->modules;
$tm = $tm->modules($modules);
List of Module name and version.
$tm->modules([
['DBIx::Custom' => '0.2108'],
['Validator::Custom' => '0.1426']
]);
Version number must be string like '0.1426'
, not 0.1426
.
If detect
method is executed, modules
attribute is set automatically.
privates
my $privates = $tm->privates;
$tm = $tm->privates({
'Some::Module' => 'http://localhost/~kimoto/%M.tar.gz'
});
Private repogitory URL. If you use privates
attribute, you don't need upload module to CPAN
. You upload module to some place you can access by http
protocal.
%M
is replaces module name and version number, like Some-Module-0.01. You also use this attribute with distnames
attribute.
METHODS
detect
$tm->detect;
Detect all installed module and modules
attribute is set.
get_module_url
my $url = $tm->get_module_url($module, $version);
my $url = $tm->get_module_url($module, $version, $option);
Get module URL by module name and version number.
# http://cpan.metacpan.org/authors/id/K/KI/KIMOTO/DBIx-Custom-0.2108.tar.gz
my $url = $tm->get_module_url('DBIx::Custom', '0.2108');
You must specify version number as string, not number. for example, 0.2110 is wrong, '0.2110' is right.
Option
You can set options
$tm->get_module_url($module, $version, {distnames => ..., ... => ...});
* distnames
distnames => {LWP => 'wwwlib-perl}
* privates
privates => {'Some::Module' => 'http://localhost/~kimoto/%M.tar.gz'}
* error
error => \$error
You can get error message.
* lwp
lwp => 'use'
lwp => 'no'
lwp => 'auto'
use LWP::UserAgent or not or automatically use
test_script
print $tm->test_script;
Test script which contains module version tests. modules
attirubtes is used to create test script.
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.
1 POD Error
The following errors were encountered while parsing the POD:
- Around line 3074:
You can't have =items (as at line 3082) unless the first thing after the =over is an =item