Module::CPANTS::Generator - Generate CPANTS statistics
my $cpants=Module::CPANTS::Generator->new; my $metric=$cpants->unpack($path_to_package); foreach my $testclass (@test_classes) { print "\trunning $testclass\n"; $testclass->generate($metric); } $metric->report;
Or see examples/*.pl for some scripts
Module::CPANTS::Generator is BETA code, so things might change in future releases.
Module::CPANTS::Generator
Please note that CPAN::DistnameInfo Version 0.04 is needed, which is not released yet. You can get it from here: http://svn.mutatus.co.uk/browse/CPAN-DistnameInfo/trunk/
CPANTS consists of three basic classes, some of which require subclassing to work. There is one main object, $cpants (provided by Module::CPANTS::Generator), and one object for each distribution that is tested called $metric (provided by Module::CPANTS::Metrics). Module::CPANTS::Reporter does not create objects but uses class methods.
First, a Module:CPANTS:Generator object is created, called $cpants It contains a configuration object (AppConfig) and is responsible for loading testing and reporting modules. It might use a CPANPLUS::Backend to connect to CPAN.
$cpants
Each testing module (which must be a subclass of Module:CPANTS:Generator) contains information on the tests it is going to run. From this information, $cpants calculates the total kwalitee available and generates some metadata (which test are there, what exaclty do they test).
While testing each distribution, a Metrics Object for this distribution is created. This object contains information on the distribution (name, unpacked location, etc), a link to the $cpants object (to access config values etc) and a data structure of the test results.
During and after testing, all loaded reporter modules (subclasses of M:C:Reporter) are called.
Module:CPANTS:Generator uses AppConfig for reading command line options and config files.
From the commandline, use
-option value
In a config file, use
option = value
See AppConfig for detailed information.
Here is a list of options:
Please note that all CPAN-releated config values are only needed if you want to test distributions on CPAN and thus are not needed in "lint"-mode.
Supress output
Default: undef
Force testing of all distributions reported by CPANPLUS (instead of only testing previously untested distributions)
Call reload_indices on the CPANPLUS::Backend object. This will establish a connection to your CPAN mirror and fetch a new filelist.
reload_indices
Path to a temp directory. This shouldn't be /tmp, but a custom temp directory only used by CPANTS (as it might be deleted)
Default: catdir($FindBin::Bin,'temp')
Path to a directory where all unpacked distributions will be stored. This should be on a big enough disk to handle about 3 Gigs.
Default: catdir($FindBin::Bin,'unpacked')
Path to a local CPAN mirror. I hope nobody is crazy enough to use CPANTS over the network.
Maximum number of distributions to test. Mainly usefull when developing new tests to limit running time.
A list of Module::CPANTS::Reporter subclasses. Do not include "Module::CPANTS::Reporter" here, it will be appended when the reporter modules are loaded.
You should add at least one Reporter module, or else you'll spend some CPU cycles for nothing...
A list of Module::CPANTS::Generator subclasses. Do not include "Module::CPANTS::Generator" here, it will be appended when the test modules are loaded.
Add or remove tests as you wish, but keep the Init-test active, or else strange things might happen.
Init
It's very handy to only load those testing modules you're currently developing.
Default: ['Init']
DBI connect information (data source, username, password). This array will be passed as-is to DBIs connect method.
connect
Initiate a new cpants object. Configuration is set up using AppConfig.
new calls load_tests and load_reporter after setting up the object.
new
Load testing modules. Called by new, so do not call it directly.
The config value reporter contains a list of testing module names. 'Module::CPANTS::Generator::' will be prepended to each module name. (eg. 'Files' is changed to 'Module::CPANTS::Generator::Files'
Each module is loaded. Each's module package global hash %kwalitee is used to generate the global kwalitee definitions and to calculate the total kwalitee available.
%kwalitee
Load reporter modules. Called by new, so do not call it directly.
The config value reporter contains a list of reporter module names. 'Module::CPANTS::Reporter::' will be prepended to each module name. (eg. 'DB' is changed to 'Module::CPANTS::Reporter::DB'
Each module is loaded and the class method init called.
init
my $metric=$cpants->unpack($path_to_package);
Unpack does quite a lot:
initiate a new Module::CPANTS::Metrics object for the to be tested package.
initate a new CPAN::DistnameInfo object from the package filename.
extract the package
check if the package extracts nicely
move the extracted package to unpack_dir
add some first information (size_packed, extracts_nicely, data provided by CPAN::DistnameInfo) to the metrics object
Returns a Module::CPANTS::Metrics object.
my $metric=$cpants->unpack_cpanplus($module_object);
Wrapper around unpack.
$module_object must be a CPANPLUS module object.
$module_object
unpack_cpanplus will use CPANPLUS::Backend to fetch the package from CPAN (hopefully from a local mirror) and call unpack on it.
unpack_cpanplus
Additionally, $metric->cpan_author will be set to the value of $module_object->author.
These Methods must be implemented in subclasse of Module::CPANTS::Generator
This method does the actual testing and generating of data. See Module::CPANTS::Generator::Init and Module::CPANTS::Generator::Files for more info / examples.
Return a ARRAYREF containing SQL-statments to create tables that can store all information generated by the module.
Return the AppConfig object.
You can do $cpants->conf->config_key to access config values directly.
return total wwalitee.
Return arrayref of loaded test modules (Subclasses of Module::CPANTS::Generator). This are the fully qualified namespaces, i.e. Module::CPANTS::Generator::Prereq
Module::CPANTS::Generator::Prereq
Return arrayref of loaded reporter modules (Subclasses of Module::CPANTS::Reporter). This are the fully qualified namespaces, i.e. Module::CPANTS::Reporter::DB)
Module::CPANTS::Reporter::DB
The CPAN Testing Service.
See http://www.pobox.com/~schwern/talks/CPANTS/full_slides/ and http://domm.zsi.at/talks/vienna_pm200309/ for more info.
Module::CPANTS::Metrics
Module::CPANTS::Reporter
More Tests
Better Tests
Thomas Klausner <domm@zsi.at> http://domm.zsi.at
Please use the perl-qa mailing list for discussing all things CPANTS: http://lists.perl.org/showlist.cgi?name=perl-qa
based on work by Leon Brocard <acme@astray.com> and the original idea proposed by Michael G. Schwern <schwern@pobox.com>
Module::CPANTS::Generator is Copyright (c) 2003 Thomas Klausner, ZSI. All rights reserved.
You may use and distribute this module according to the same terms that Perl is distributed under.
To install Module::CPANTS::Generator, copy and paste the appropriate command in to your terminal.
cpanm
cpanm Module::CPANTS::Generator
CPAN shell
perl -MCPAN -e shell install Module::CPANTS::Generator
For more information on module installation, please visit the detailed CPAN module installation guide.