Ratings.pm

filter: Statementstmt 97.2% 35 / 36 Branchbran 75.0% 3 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 9 / 9 Podpod 100% 2 / 2 totaltotal 96.0% 49 / 51 CC 3 SCAR 4.4
CC
3
Cov
95%
_build_db
3.0
BEGIN
1.0
BEGIN
1.0
CRAP 1.6
↑ Summary Ratings/Rating.pm »
1 package Parse::CPAN::Ratings;
2 2 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 2 ▶use MooseX::StrictConstructor;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use MooseX::Types::Path::Class;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use Parse::CPAN::Ratings::Rating;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Parse::CSV;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 2 our $VERSION = '0.33';
8  
9 2 has 'filename' =>
10 ( is => 'ro', isa => 'Path::Class::File', required => 1, coerce => 1 );
11  
12 2 has 'db' => (
13 is => 'ro',
14 isa => 'HashRef[Parse::CPAN::Ratings::Rating]',
15 lazy_build => 1,
16 );
17  
18 2 ▶no Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 2 __PACKAGE__->meta->make_immutable;
21  
22 1 ▶sub _build_db {
Subroutine _build_db: called CC=3 SCAR=11.1
23 1 my $self = shift;
24 1 my $filename = $self->filename;
25 1 my %db;
26  
27 1 my $parser = Parse::CSV->new(
28 file => $filename->stringify,
29 fields => 'auto',
30 );
31 1 ▶ while ( my $rating = $parser->fetch ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $rating = $parser->fetch) 99 1 100
32 $db{ $rating->{distribution} } = Parse::CPAN::Ratings::Rating->new(
33 distribution => $rating->{distribution},
34 rating => $rating->{rating},
35 review_count => $rating->{review_count},
36 99 );
37 }
38 1 ▶ if ( $parser->errstr ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($parser->errstr) 0 1 1
39 0 confess( "Error parsing CSV: " . $parser->errstr );
40 }
41 1 return \%db;
42 }
43  
44 2 ▶sub rating {
Subroutine rating: called CC=1 SCAR=0.0
Pod documented
45 2 my ( $self, $distribution ) = @_;
46 2 return $self->db->{$distribution};
47 }
48  
49 1 ▶sub ratings {
Subroutine ratings: called CC=1 SCAR=0.0
Pod documented
50 1 my $self = shift;
51 1 return values %{ $self->db };
52 }
53  
54 __END__
↑ Summary Ratings/Rating.pm »