File Coverage

blib/lib/MetaCPAN/Client/Distribution.pm
Criterion Covered Total %
statement 12 13 92.3
branch 2 4 50.0
condition n/a
subroutine 6 7 85.7
pod 3 3 100.0
total 23 27 85.1


line stmt bran cond sub pod time code
1 19     19   116 use strict;
  19         34  
  19         508  
2 19     19   86 use warnings;
  19         34  
  19         725  
3             package MetaCPAN::Client::Distribution;
4             # ABSTRACT: A Distribution data object
5             $MetaCPAN::Client::Distribution::VERSION = '2.030000';
6 19     19   88 use Moo;
  19         35  
  19         119  
7              
8             with 'MetaCPAN::Client::Role::Entity';
9              
10             my %known_fields = (
11             scalar => [qw< name >],
12             arrayref => [],
13             hashref => [qw< bugs river >]
14             );
15              
16             my %__known_fields_ex = (
17             map { my $k = $_; $k => +{ map { $_ => 1 } @{ $known_fields{$k} } } }
18             keys %known_fields
19             );
20              
21             my @known_fields = map { @{ $known_fields{$_} } } keys %known_fields;
22              
23             foreach my $field ( @known_fields ) {
24             has $field => (
25             is => 'ro',
26             lazy => 1,
27             default => sub {
28             my $self = shift;
29             return (
30             exists $self->data->{$field} ? $self->data->{$field} :
31             exists $__known_fields_ex{hashref}{$field} ? {} :
32             exists $__known_fields_ex{arrayref}{$field} ? [] :
33             exists $__known_fields_ex{scalar}{$field} ? '' :
34             undef
35             );
36             },
37             );
38             }
39              
40 2     2   6 sub _known_fields { return \%known_fields }
41              
42 1 50   1 1 26 sub rt { $_[0]->bugs->{rt} || {} }
43 1 50   1 1 22 sub github { $_[0]->bugs->{github} || {} }
44              
45 0     0 1   sub metacpan_url { "https://metacpan.org/release/" . $_[0]->name }
46              
47             1;
48              
49             __END__