File Coverage

blib/lib/Git/Helpers/CPAN.pm
Criterion Covered Total %
statement 30 30 100.0
branch 8 10 80.0
condition n/a
subroutine 9 9 100.0
pod n/a
total 47 49 95.9


line stmt bran cond sub pod time code
1             package Git::Helpers::CPAN;
2             our $VERSION = '0.000021';
3 1     1   125008 use Moo;
  1         12606  
  1         7  
4              
5 1     1   3174 use MetaCPAN::Client ();
  1         403493  
  1         40  
6 1     1   13 use Try::Tiny qw( try );
  1         3  
  1         81  
7 1     1   7 use Types::Standard qw( HashRef InstanceOf Maybe Str );
  1         3  
  1         32  
8              
9             has _client => (
10             is => 'ro',
11             isa => InstanceOf ['MetaCPAN::Client'],
12             lazy => 1,
13             default => sub { MetaCPAN::Client->new },
14             );
15              
16             has _latest_release => (
17             is => 'ro',
18             isa => InstanceOf ['MetaCPAN::Client::Release'],
19             lazy => 1,
20             builder => '_build_latest_release',
21             );
22              
23             has release_name => (
24             is => 'ro',
25             isa => Str,
26             lazy => 1,
27             builder => '_build_release_name',
28             );
29              
30             has name => (
31             is => 'ro',
32             isa => Str,
33             required => 1,
34             );
35              
36             has repository => (
37             is => 'ro',
38             isa => Maybe [HashRef],
39             lazy => 1,
40             init_arg => undef,
41             builder => '_build_repository',
42             );
43              
44             sub _build_repository {
45 4     4   17181 my $self = shift;
46              
47             return $self->_latest_release
48             ? $self->_latest_release->resources->{repository}
49 4 50       79 : undef;
50             }
51              
52             sub _build_release_name {
53 5     5   5658 my $self = shift;
54              
55 5 100       71 return $self->name if $self->name !~ m{::};
56              
57 3         7 my $release_name;
58             try {
59 3     3   174 my $module = $self->_client->module( $self->name );
60 1 50       239510 $release_name = $module->distribution if $module;
61 3         38 };
62              
63 3 100       259653 if ( !$release_name ) {
64 2         54 die sprintf( "Cannot find a module named %s", $self->name );
65             }
66              
67 1         22 return $release_name;
68             }
69              
70             sub _build_latest_release {
71 4     4   49 my $self = shift;
72              
73 4         8 my $release;
74             try {
75 4     4   198 $release = $self->_client->release( $self->release_name );
76 4         38 };
77              
78 4 100       445897 if ( !$release ) {
79 2         160 die sprintf( "Cannot find a release named %s", $self->release_name );
80             }
81 2         48 return $release;
82             }
83              
84             1;
85              
86             # ABSTRACT: Get repository information for a CPAN module or release
87              
88             __END__