Skip to content
This repository
Fetching contributors…

Octocat-spinner-32-eaf2f5

Cannot retrieve contributors at this time

file 36 lines (32 sloc) 1.067 kb
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35
package MetaCPAN::Document::Rating;
use Moose;
use ElasticSearchX::Model::Document;
use ElasticSearchX::Model::Document::Types qw(:all);
use MooseX::Types::Structured qw(Dict Tuple Optional);
use MooseX::Types::Moose qw(Int Num Bool Str ArrayRef HashRef Undef);

has details => ( is => 'ro', isa => Dict [ documentation => Str ] );
has rating =>
    ( required => 1, is => 'ro', isa => Num, builder => '_build_rating' );
has [qw(distribution release author user)] =>
    ( required => 1, is => 'ro', isa => Str );
has date => (
    required => 1,
    is => 'ro',
    isa => 'DateTime',
    default => sub { DateTime->now }
);
has helpful => (
    required => 1,
    is => 'ro',
    isa => ArrayRef [ Dict [ user => Str, value => Bool ] ],
    default => sub { [] }
);

sub _build_rating {
    my $self = shift;
    die "Provide details to calculate a rating";
    my %details = %{ $self->details };
    my $rating = 0;
    $rating += $_ for ( values %details );
    return $rating / scalar keys %details;
}

__PACKAGE__->meta->make_immutable;
Something went wrong with that request. Please try again.