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 = '1.000001';
3 1     1   123737 use Moo;
  1         17472  
  1         7  
4              
5 1     1   2937 use MetaCPAN::Client 2.029000 ();
  1         431561  
  1         38  
6 1     1   8 use Try::Tiny qw( try );
  1         2  
  1         69  
7 1     1   8 use Types::Standard qw( HashRef InstanceOf Maybe Str );
  1         3  
  1         21  
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   18343 my $self = shift;
46              
47             return $self->_latest_release
48             ? $self->_latest_release->resources->{repository}
49 4 50       78 : undef;
50             }
51              
52             sub _build_release_name {
53 5     5   5642 my $self = shift;
54              
55 5 100       74 return $self->name if $self->name !~ m{::};
56              
57 3         8 my $release_name;
58             try {
59 3     3   153 my $module = $self->_client->module( $self->name );
60 1 50       302124 $release_name = $module->distribution if $module;
61 3         39 };
62              
63 3 100       248032 if ( !$release_name ) {
64 2         53 die sprintf( "Cannot find a module named %s", $self->name );
65             }
66              
67 1         24 return $release_name;
68             }
69              
70             sub _build_latest_release {
71 4     4   67 my $self = shift;
72              
73 4         11 my $release;
74             try {
75 4     4   207 $release = $self->_client->release( $self->release_name );
76 4         34 };
77              
78 4 100       456133 if ( !$release ) {
79 2         116 die sprintf( "Cannot find a release named %s", $self->release_name );
80             }
81 2         47 return $release;
82             }
83              
84             1;
85              
86             # ABSTRACT: Get repository information for a CPAN module or release
87              
88             __END__