| 1 | # ABSTRACT: Specifies a distribution by author and archive | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | package Pinto::Target::Distribution; | ||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 66 | ▶ | use Moose; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | 66 | ▶ | use MooseX::MarkAsMethods ( autoclean => 1 ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 66 | ▶ | use MooseX::Types::Moose qw(ArrayRef Str); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||
| 9 | 66 | ▶ | use Pinto::Types qw(AuthorID); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 66 | ▶ | use Pinto::Util qw(throw author_dir); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 66 | ▶ | use overload ( '""' => 'to_string' ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | |||||||||||||||||||||||||||||
| 14 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 15 | |||||||||||||||||||||||||||||
| 16 | 66 | our $VERSION = '0.14'; # VERSION | |||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | 66 | has author => ( | |||||||||||||||||||||||||||
| 21 | is => 'ro', | ||||||||||||||||||||||||||||
| 22 | isa => AuthorID, | ||||||||||||||||||||||||||||
| 23 | coerce => 1, | ||||||||||||||||||||||||||||
| 24 | required => 1, | ||||||||||||||||||||||||||||
| 25 | ); | ||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||
| 27 | 66 | has archive => ( | |||||||||||||||||||||||||||
| 28 | is => 'ro', | ||||||||||||||||||||||||||||
| 29 | isa => Str, | ||||||||||||||||||||||||||||
| 30 | required => 1, | ||||||||||||||||||||||||||||
| 31 | ); | ||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||
| 33 | has subdirs => ( | ||||||||||||||||||||||||||||
| 34 | is => 'ro', | ||||||||||||||||||||||||||||
| 35 | isa => ArrayRef[Str], | ||||||||||||||||||||||||||||
| 36 | 0 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 37 | 66 | ); | |||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | 9 | ▶ | around BUILDARGS => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=5 SCAR=16.1
| |||||||||||||||||||||||||||||
| 42 | 9 | my $orig = shift; | |||||||||||||||||||||||||||
| 43 | 9 | my $class = shift; | |||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 9 | my @args = @_; | |||||||||||||||||||||||||||
| 46 | 9 | ▶ | if ( @args == 1 and not ref $args[0] ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@args == 1 and not ref $args[0]
MC/DC50%1/2
@args == 1 and not ref $args[0]
@args == 1
not ref $args[0]
Truth table66%2/3
A and not(B)
A= @args == 1B= not ref $args[0]
| |||||||||||||||||||||||||||||
| 47 | 8 | my @path_parts = split m{/+}x, $args[0]; | |||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||
| 49 | 8 | my $author = shift @path_parts; # First element | |||||||||||||||||||||||||||
| 50 | 8 | my $archive = pop @path_parts; # Last element | |||||||||||||||||||||||||||
| 51 | 8 | my $subdirs = [@path_parts]; # Everything else | |||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||
| 53 | 8 | ▶ | throw "Invalid distribution target: $args[0]" | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$author and $archive
MC/DC100%2/2
$author and $archive
$author
$archive
Truth table100%3/3
A and B
A= $authorB= $archive
| |||||||||||||||||||||||||||||
| 54 | if not( $author and $archive ); | ||||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 4 | @args = ( author => $author, subdirs => $subdirs, archive => $archive ); | |||||||||||||||||||||||||||
| 57 | } | ||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 5 | return $class->$orig(@args); | |||||||||||||||||||||||||||
| 60 | 66 | }; | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 63 | |||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 2 | ▶ | sub path { | ||||||||||||||||||||||||||
|
Subroutine
path: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 66 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||
| 68 | 2 | my $author_dir = author_dir($self->author); | |||||||||||||||||||||||||||
| 69 | 2 | my @subdirs = @{ $self->subdirs }; | |||||||||||||||||||||||||||
| 70 | 2 | my $archive = $self->archive; | |||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 2 | return join '/', $author_dir, @subdirs, $archive; | |||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 76 | |||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 2 | ▶ | sub to_string { | ||||||||||||||||||||||||||
|
Subroutine
to_string: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 79 | 2 | my ($self) = @_; | |||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 2 | my $author = $self->author; | |||||||||||||||||||||||||||
| 82 | 2 | my @subdirs = @{ $self->subdirs }; | |||||||||||||||||||||||||||
| 83 | 2 | my $archive = $self->archive; | |||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||
| 85 | 2 | return join '/', $author, @subdirs, $archive; | |||||||||||||||||||||||||||
| 86 | } | ||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 89 | |||||||||||||||||||||||||||||
| 90 | 66 | __PACKAGE__->meta->make_immutable; | |||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | #------------------------------------------------------------------------------ | ||||||||||||||||||||||||||||
| 93 | 66 | 1; | |||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||
| 95 | __END__ | ||||||||||||||||||||||||||||