Acme::CPANAuthors::Utils::Kwalitee - Acme::CPANAuthors::Utils::Kwalitee documentation


Acme-CPANAuthors documentation Contained in the Acme-CPANAuthors distribution.

Index


Code Index:

NAME

Top

Acme::CPANAuthors::Utils::Kwalitee

SYNOPSIS

Top

    use Acme::CPANAuthors::Utils::Kwalitee;

    my $info = Acme::CPANAuthors::Utils::Kwalitee->fetch('ISHIGAKI');

    # then, $info will have keys/values like this
    # (though this may change without notices)

    {
      info => {
        Average_Kwalitee => "144.333",
        CPANTS_Game_Kwalitee => "98.833",
        Email => "ishigaki\@cpan.org",
        Liga => "5 or more",
        Rank => 47,
      },
      distributions => {
        "Acme-CPANAuthors" => {
          details  => { "use_strict" => "ok", ... },
          kwalitee => "144.000",
        },
        ...
      },
    }

DESCRIPTION

Top

This is mainly to create some local kwalitee rankings for you :)

METHODS

Top

fetch

returns kwalitee information for the author of the id. This information is scraped from http://cpants.perl.org/.

AUTHOR

Top

Kenichi Ishigaki, <ishigaki at cpan.org>

COPYRIGHT AND LICENSE

Top


Acme-CPANAuthors documentation Contained in the Acme-CPANAuthors distribution.

package Acme::CPANAuthors::Utils::Kwalitee;

use strict;
use warnings;
use LWP::UserAgent;
use JSON ();

my $ua;

sub _uri { "http://api.cpanauthors.org/kwalitee/" . shift }

sub _ua {
  my $class = shift;
  $ua = $_[0] if @_;
  $ua ||= LWP::UserAgent->new(env_proxy => 1);
  $ua;
}

sub fetch {
  my ($class, $id) = @_;

  return unless $id;

  my $res = $class->_ua->get(_uri(lc $id));
  unless ($res->is_success && $res->code == 200) {
    $class->_error($res->status_line);
  }

  my $json = eval { JSON::decode_json($res->content) };
  if ($@) {
    $class->_error($@);
  }
  return $json;
}

sub _error {
  my ($class, $error) = @_;

  die "API SERVER ERROR\n"
    . "Couldn't parse kwalitee info from the api server\n"
    . "  $error\n"
    . "Sorry for the inconvenience. If this lingers long,\n"
    . "please drop a line to <ishigaki\@cpan.org>.\n";
}

1;

__END__