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