| 1 | package CPAN::Local::Distribution; | ||||||||||
| 2 | { | ||||||||||
| 3 | 3 | $CPAN::Local::Distribution::VERSION = '0.010'; | |||||||||
| 4 | } | ||||||||||
| 5 | |||||||||||
| 6 | # ABSTRACT: Base distribution class | ||||||||||
| 7 | |||||||||||
| 8 | 3 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 3 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | |||||||||||
| 11 | 3 | ▶ | use Path::Class (); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 3 | ▶ | use CPAN::DistnameInfo; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | 3 | ▶ | use URI; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 14 | 3 | ▶ | use Moose; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 15 | 3 | ▶ | use namespace::clean -except => 'meta'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 16 | |||||||||||
| 17 | 3 | has filename => ( is => 'ro', isa => 'Str', required => 1 ); | |||||||||
| 18 | 3 | has authorid => ( is => 'ro', isa => 'Str', required => 1 ); | |||||||||
| 19 | 3 | has path => ( is => 'ro', isa => 'Str', required => 1, lazy_build => 1 ); | |||||||||
| 20 | |||||||||||
| 21 | around BUILDARGS => sub | ||||||||||
| 22 | 15 | ▶ | { | ||||||||
|
Subroutine
__ANON__: called CC=3 SCAR=11.0
| |||||||||||
| 23 | 15 | my ( $orig, $class, %args ) = @_; | |||||||||
| 24 | |||||||||||
| 25 | # proceed as nomal if we already have authorid | ||||||||||
| 26 | 15 | ▶ | return $class->$orig(%args) if $args{authorid}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 27 | 4 | my $path = Path::Class::file($args{filename}); | |||||||||
| 28 | |||||||||||
| 29 | # calculate the path, e.g. ('authors', 'id', 'A', 'AD', 'ADAMK', 'File-Which-1.09.tar.gz') | ||||||||||
| 30 | 4 | my @path_parts = ( $path->dir->dir_list, $path->basename ); | |||||||||
| 31 | |||||||||||
| 32 | # get the last 6 parts of the path | ||||||||||
| 33 | 4 | ▶ | @path_parts = splice( @path_parts, -6 ) if @path_parts >= 6; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 34 | |||||||||||
| 35 | # make sure we use only forward slashes | ||||||||||
| 36 | 4 | my $distname = Path::Class::file(@path_parts)->as_foreign('Unix')->stringify; | |||||||||
| 37 | |||||||||||
| 38 | # get the authorid | ||||||||||
| 39 | 4 | my $distnameinfo = CPAN::DistnameInfo->new($distname); | |||||||||
| 40 | 4 | $args{authorid} = $distnameinfo->cpanid; | |||||||||
| 41 | |||||||||||
| 42 | 4 | return $class->$orig(%args); | |||||||||
| 43 | 3 | }; | |||||||||
| 44 | |||||||||||
| 45 | sub _build_path | ||||||||||
| 46 | 6 | ▶ | { | ||||||||
|
Subroutine
_build_path: called CC=1 SCAR=0.0
| |||||||||||
| 47 | 6 | my $self = shift; | |||||||||
| 48 | |||||||||||
| 49 | 6 | my $filename = Path::Class::file($self->filename)->basename; | |||||||||
| 50 | |||||||||||
| 51 | 6 | my @chars = split //, $self->authorid; | |||||||||
| 52 | 6 | my $path = Path::Class::dir( | |||||||||
| 53 | 'authors', | ||||||||||
| 54 | 'id', | ||||||||||
| 55 | $chars[0], | ||||||||||
| 56 | $chars[0] . $chars[1], | ||||||||||
| 57 | $self->authorid, | ||||||||||
| 58 | $filename, | ||||||||||
| 59 | ); | ||||||||||
| 60 | |||||||||||
| 61 | 6 | return $path->as_foreign('Unix')->stringify; | |||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | 3 | __PACKAGE__->meta->make_immutable; | |||||||||
| 65 | |||||||||||
| 66 | |||||||||||
| 67 | __END__ | ||||||||||