The London Perl and Raku Workshop takes place on 26th Oct 2024. If your company depends on Perl, please consider sponsoring and/or attending.

NAME

Module::CPANTS::Metrics - Metric object for CPANTS data

SYNOPSIS

  my $metric=$cpants->unpack($path_to_package);

  $metric->add(version=>'1.42');
  $metric->add(size=>{packed=>1234,unpacked=>12345});
  $metric->add(prereq=>[
                        {requires=>'Foo::Bar',version=>'0.25'},
                        {requires=>'Baz',version=>'0'},
                       ]);

Or, all in one call:

  $metric->add(version=>'1.42',
               size=>{packed=>1234,unpacked=>12345},
               prereq=>[
                        {requires=>'Foo::Bar',version=>'0.25'},
                        {requires=>'Baz',version=>'0'},
                       ]);

  $metric->report;

DESCRIPTION

Module::CPANTS::Metrics objects store information gathered by CPANTS. Those objects are used by Module::CPANTS::Reporter subclasses to report the information in various ways

Each Metric objects represents one package.

METHODS

Main Methods

new

Initiate a new Module::CPANTS::Metrics

Takes a Module::CPANTS::Generator object as an argument, which is available later through $metric->cpants.

new is usually called from Module::CPANTS::Generates unpack

add

  $metric->add(%data);

Add data to the metric object.

Data must be a plain hash, i.e. not a HASREF.

Depending on the value-type of each key, add behaves differently.

  • If the value is a SCALAR or a SCALARREF, the key and value are added to the Metric objects data. Duplicate occurances of the same keyword will overwrite old values.

  • If the value is an ARRAYREF, the values of the array will be push'ed onto the array referenced by the keyword.

  • If the value is a HASHREF, the contents of this hash will be added to the hash referenced by the keyword.

  • Other value types result in an error.

Please note that the generated data structure is used by Module::CPANTS::Reporter subclasses to generate meaningfull output. See Module::CPANTS::Reporter::DB for a discussion on how this data structure is dumped to a SQL database

report

Calculate total and relative kwalitee for the package.

Afterwards, for each loaded Module::CPANTS::Reporter subclass, call it's report method, passing the Metrics object as an argument.

note

  $metric->note($test_value,$kwalitee_definition);

note is called from Module::CPANTS::Generator subclasses to add kwalitee or a flaw.

$test_value is a boolean value. $kwalitee_definition a key in the global kwalitee definition, e.g. 'no_version'.

If $test_value is true, than the kwalitee provided by this test will be added to the total kwalitee.

If $test_value is false, this kwalitee definition will be stored in the flaws-array of the Metrics object.

add_flaw

Convient method to add a flaw to the list of flaws. Most of the time you should use note instead.

Accessor Methods provided by Class::Accessor

cpants

Module::CPANTS::Generator object

distnameinfo

CPAN::DistnameInfo object

dist

The name of the distribution, as returned by CPAN::DistnameInfo->distvname, i.e.: Foo-Bar-1.43. This is the unique indentifier used throughout CPANTS

data

The data-hash (where add stores its values)

files

ARRAYREF of all files in the distribution.

unpacked

Path to unpacked distribution

kwalitee

Current kwalitee. Makes most sense after all test are run.

flaws

ARRAYREF of the list of flaws

error

Set to a true value if an error occured during unpacking.

AUTHOR

Thomas Klausner <domm@zsi.at> http://domm.zsi.at

COPYRIGHT

Module::CPANTS::Metrics 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.