| 1 | package CPAN::Local::Distribution::Role::FromURI; | ||||||||||||||||||||||||||||
| 2 | { | ||||||||||||||||||||||||||||
| 3 | 2 | $CPAN::Local::Distribution::Role::FromURI::VERSION = '0.010'; | |||||||||||||||||||||||||||
| 4 | } | ||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | # ABSTRACT: Allow distributions to be fetched from remote uris | ||||||||||||||||||||||||||||
| 7 | |||||||||||||||||||||||||||||
| 8 | 2 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 2 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 2 | ▶ | use Carp qw(croak); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 2 | ▶ | use Path::Class qw(file dir); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 2 | ▶ | use File::Temp qw(tempdir); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 2 | ▶ | use LWP::Simple qw(is_error getstore); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | 2 | ▶ | use Moose::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 15 | 2 | ▶ | use namespace::clean -except => 'meta'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||
| 17 | 2 | has uri => ( is => 'ro', isa => 'Str' ); | |||||||||||||||||||||||||||
| 18 | 2 | has cache => ( is => 'ro', isa => 'Str' ); | |||||||||||||||||||||||||||
| 19 | |||||||||||||||||||||||||||||
| 20 | around BUILDARGS => sub | ||||||||||||||||||||||||||||
| 21 | 7 | ▶ | { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=12 SCAR=26.0
| |||||||||||||||||||||||||||||
| 22 | 7 | my ( $orig, $class, %args ) = @_; | |||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||
| 24 | 7 | ▶ | return $class->$orig(%args) unless $args{uri}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||
| 26 | croak "Please specify either 'filename' or 'uri', not both" | ||||||||||||||||||||||||||||
| 27 | 3 | ▶ | if $args{uri} and $args{filename}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$args{"uri"} and $args{"filename"}
MC/DC0%0/2
$args{"uri"} and $args{"filename"}
$args{"uri"}
$args{"filename"}
Truth table33%1/3
A and B
A= $args{"uri"}B= $args{"filename"}
| |||||||||||||||||||||||||||||
| 28 | |||||||||||||||||||||||||||||
| 29 | 3 | my $uri = URI->new($args{uri}); | |||||||||||||||||||||||||||
| 30 | 3 | my $fake_filename = file($uri->path_segments)->stringify; | |||||||||||||||||||||||||||
| 31 | |||||||||||||||||||||||||||||
| 32 | 3 | ▶ | unless ( $args{path} and $args{authorid} ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$args{"path"} and $args{"authorid"}
MC/DC0%0/2
$args{"path"} and $args{"authorid"}
$args{"path"}
$args{"authorid"}
Truth table33%1/3
A and B
A= $args{"path"}B= $args{"authorid"}
| |||||||||||||||||||||||||||||
| 33 | { | ||||||||||||||||||||||||||||
| 34 | my $fake_distro = CPAN::Local::Distribution->new( | ||||||||||||||||||||||||||||
| 35 | filename => $fake_filename, | ||||||||||||||||||||||||||||
| 36 | 3 | ▶ | $args{authorid} ? ( authorid => $args{authorid} ) : (), | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | ); | ||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||
| 39 | 3 | ▶ | $args{authorid} = $fake_distro->authorid unless $args{authorid}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 40 | 3 | ▶ | $args{path} = $fake_distro->path unless $args{path}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||
| 42 | |||||||||||||||||||||||||||||
| 43 | 3 | ▶ | $args{cache} = tempdir( CLEANUP => 1 ) unless $args{cache}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 44 | |||||||||||||||||||||||||||||
| 45 | 3 | my $filename = file($args{cache}, $args{path}); | |||||||||||||||||||||||||||
| 46 | 3 | $filename->dir->mkpath; | |||||||||||||||||||||||||||
| 47 | |||||||||||||||||||||||||||||
| 48 | 3 | ▶ | if ( not -e $filename ) | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 49 | { | ||||||||||||||||||||||||||||
| 50 | 3 | my $result = getstore( $uri->as_string, $filename->stringify ); | |||||||||||||||||||||||||||
| 51 | 3 | ▶ | croak "Error fetching " . $uri->as_string if is_error $result; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 3 | $args{filename} = $filename->stringify; | |||||||||||||||||||||||||||
| 55 | |||||||||||||||||||||||||||||
| 56 | 3 | return $class->$orig(%args); | |||||||||||||||||||||||||||
| 57 | 2 | }; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 2 | 1; | |||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | __END__ | ||||||||||||||||||||||||||||