CPANTS-Kwalitee-Report

 view release on metacpan or  search on metacpan

lib/CPANTS/Kwalitee/Report.pm  view on Meta::CPAN

package CPANTS::Kwalitee::Report;

$CPANTS::Kwalitee::Report::VERSION   = '0.11';
$CPANTS::Kwalitee::Report::AUTHORITY = 'cpan:MANWAR';

=head1 NAME

CPANTS::Kwalitee::Report - CPANTS Kwalitee Report.

=head1 VERSION

Version 0.11

=cut

use 5.006;
use Data::Dumper;
use File::Temp qw/tempdir/;

use LWP::Simple;
use XML::RSS::Parser;
use Parse::CPAN::Packages;
use Module::CPANTS::Analyse;
use Module::CPANTS::Kwalitee;

use CPANTS::Kwalitee::Report::Score;
use CPANTS::Kwalitee::Report::Generator;
use CPANTS::Kwalitee::Report::Indicator;
use CPANTS::Kwalitee::Report::Distribution;

use Moo;
use namespace::autoclean;

our $PAUSE_INDEX = 'http://www.cpan.org/modules/02packages.details.txt.gz';
our $RECENT_MODS = 'https://metacpan.org/feed/recent';
our $MIN_COUNT   = 5;
our $MAX_COUNT   = 100;

has [ qw(parser generators indicators recent_dists verbose) ] => (is => 'rw');
has [ qw(index recent rss kwalitee) ] => (is => 'lazy');

sub _build_index    { get($PAUSE_INDEX)             }
sub _build_recent   { get($RECENT_MODS)             }
sub _build_rss      { XML::RSS::Parser->new         }
sub _build_kwalitee { Module::CPANTS::Kwalitee->new }
sub _build_verbose  { 0                             }

=head1 DESCRIPTION

This work is  inspired  by L<Module::CPANTS::Analyse> and  L<Test::Kwalitee>. The
main objective of this module  is to provide simple API to query Kwalitee scores.

I came across a script C<kwalitee-metrics>, part of  L<Test::Kwalitee>, where the
author wish there was an API to do what the author was doing. That prompted me to
begin the journey.

This is what it would look like now, if using this module:

    use strict; use warnings;
    use CPANTS::Kwalitee::Report;

    my $verbose = @ARGV && ($ARGV[0] eq '--verbose' || $ARGV[0] eq '-v');
    my $report  = CPANTS::Kwalitee::Report->new({ verbose => $verbose });

    print sprintf("%s\n\n", join("\n", @{$report->get_generators}));

Interesting comparison by L<Devel::Timer> shown below:

    Devel::Timer Report -- Total time: 0.1557 secs
    Interval  Time    Percent
    ----------------------------------------------
    00 -> 01  0.1458  93.62%  INIT -> old way
    01 -> 02  0.0099   6.38%  old way -> new way

It comes with a handy  script  C<kwalitee-report>, which can be used to query the
kwalitee scores of any distribution.

    $ kwalitee-score --dist=Map::Tube

More detailed options shown below:

    $ kwalitee-report -h
    USAGE: kwalitee-report [-hn] [long options...]

         --dist=String              Distribution name to generate Kwalitee
                                    report.
         --metrics                  Show CPANTS Kwalitee metrics.
         --recently_uploaded_dists  Lookup recently uploaded distributions.
         -n=Int                     Distribution count to generate Kwalitee
                                    report. Default is 5.
         --verbose                  Be more descriptive. Default is OFF.



( run in 0.956 second using v1.01-cache-2.11-cpan-8f98c5d2c55 )