Test::ModuleVersion - Module version test generator
(2013/3/20)
Sorry. This module is DEPRECATED because cpanm and cpanfile is much better.
If you want to install moudles, use cpanm and cpanfile instead.
See https://github.com/kraih/mojo/wiki/Installation-of-cpan-modules-by-cpanm-and-cpanfile
If you want to test module version, you write test by yourself.
is($DBIx::Custom::VERSION, '0.2108');
This module will be removed from CPAN on 2018/3/1
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');
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.
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.
modules
test_script
t/module.t
Run mvt.pl
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.
$ 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
You can list moudle URLs by list command
list
$ perl t/module.t list
All module URLs in version test is output to STDOUT.
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
--fail
$ perl t/module.t list --fail
$ 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.
extlib
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.
--lwp
$ perl t/module.t list --lwp
--no-lwp option force HTTP::Tiny.
--no-lwp
$ perl t/module.t list --no-lwp
export http_proxy=http://hostname:3001
http_proxy environment variable enable you to use proxy server.
http_proxy
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.
# Directory t / mvt.pl / module.t extlib / lib / perl5 / Object / Simple.pm / Validator / Custom.pm
features:
extlib/lib/perl5
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");
# Directory t / mvt.pl / module.t extlib / lib / perl5 / LWP.pm
LWP module distribution name is libwww-perl. If module name is different from distribution name, you can use distnames attribute.
libwww-perl
distnames
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");
# Directory t / mvt.pl / module.t extlib / lib / perl5 / SomeModule.pm
SomeModule is private module. If module exist in some URL, you can use privates attribute.
privates
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");
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
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
use lib "$FindBin::Bin/../extlib/lib/perl5";
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).
'0.1426'
0.1426
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.
%M
module-version
SomeModule-0.01
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.
ignore
Note that ExtUtils::Installed is used internally. This information will be not accurate in some cases.
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.
output
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.
Yuki Kimoto, <kimoto.yuki at gmail.com>
<kimoto.yuki at gmail.com>
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.
To install Test::ModuleVersion, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Test::ModuleVersion
CPAN shell
perl -MCPAN -e shell install Test::ModuleVersion
For more information on module installation, please visit the detailed CPAN module installation guide.