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.000000';
3 1     1   102691 use Moo;
  1         9874  
  1         6  
4              
5 1     1   1821 use MetaCPAN::Client ();
  1         318629  
  1         33  
6 1     1   10 use Try::Tiny qw( try );
  1         2  
  1         70  
7 1     1   6 use Types::Standard qw( HashRef InstanceOf Maybe Str );
  1         2  
  1         23  
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   14674 my $self = shift;
46              
47             return $self->_latest_release
48             ? $self->_latest_release->resources->{repository}
49 4 50       67 : undef;
50             }
51              
52             sub _build_release_name {
53 5     5   4457 my $self = shift;
54              
55 5 100       61 return $self->name if $self->name !~ m{::};
56              
57 3         4 my $release_name;
58             try {
59 3     3   437 my $module = $self->_client->module( $self->name );
60 1 50       207474 $release_name = $module->distribution if $module;
61 3         31 };
62              
63 3 100       247740 if ( !$release_name ) {
64 2         31 die sprintf( "Cannot find a module named %s", $self->name );
65             }
66              
67 1         17 return $release_name;
68             }
69              
70             sub _build_latest_release {
71 4     4   73 my $self = shift;
72              
73 4         8 my $release;
74             try {
75 4     4   172 $release = $self->_client->release( $self->release_name );
76 4         35 };
77              
78 4 100       430658 if ( !$release ) {
79 2         120 die sprintf( "Cannot find a release named %s", $self->release_name );
80             }
81 2         35 return $release;
82             }
83              
84             1;
85              
86             # ABSTRACT: Get repository information for a CPAN module or release
87              
88             __END__