blib/lib/Perl/Dist/Asset.pm

filter: Statementstmt 80.9% 51 / 63 Branchbran 43.7% 7 / 16 Conditioncond 16.6% 1 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 93.3% 14 / 15 Podpod 0.0% 0 / 3 totaltotal 68.2% 73 / 107 CC 11 SCAR 23.5
CC
11
Cov
69%
new
24.3
trace
2.1
cpan
2.0
CRAP 10.4
« blib/lib/Perl/Dist/Inno/System.pm ↑ Summary blib/lib/auto/share/dist/Perl-Dist/default/perl-5.10.0/lib/ExtUtils/Command.pm »
1 package Perl::Dist::Asset;
2  
3 # Convenience base class for Perl::Dist assets
4  
5 3 ▶use 5.006;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 3 ▶use Carp 'croak';
Subroutine BEGIN: called CC=1 SCAR=0.0
9 3 ▶use File::Spec ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use File::Spec::Unix ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use File::ShareDir ();
Subroutine BEGIN: called CC=1 SCAR=0.0
12 3 ▶use URI::file ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13 3 ▶use Params::Util qw{ _STRING _CODELIKE };
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 3 ▶use vars qw{$VERSION};
Subroutine BEGIN: called CC=1 SCAR=0.0
16 3 ▶BEGIN {
Subroutine BEGIN: called CC=1 SCAR=0.0
17 3 $VERSION = '1.16';
18 }
19  
20 3 ▶use Object::Tiny qw{
Subroutine BEGIN: called CC=1 SCAR=0.0
21 parent
22 file
23 url
24 share
25 dist
26 3 };
27  
28  
29  
30  
31  
32 #####################################################################
33 # Constructor
34  
35 3 ▶sub new {
Subroutine new: called CC=10 SCAR=31.9
Pod undocumented
36 3 my $self = shift->SUPER::new(@_);
37  
38 3 ▶ unless ( $self->url ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->url) 1 2 3
39 1 ▶ if ( $self->share ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($self->share) { } 1 0 1
elsif ($self->dist) { } 0 0 0
elsif ($self->can('name') and $self->name) { } 0 0 0
40 # Map share to url vis File::ShareDir
41 1 my ($dist, $name) = split /\s+/, $self->share;
42 1 $self->trace("Finding $name in $dist... ");
43 1 my $file = File::Spec->rel2abs(
44 File::ShareDir::dist_file( $dist, $name )
45 );
46 1 ▶ unless ( -f $file ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-f $file) 0 1 1
47 0 croak("Failed to find $file");
48 }
49 1 $self->{url} = URI::file->new($file)->as_string;
50 1 $self->trace(" found\n");
51  
52 } elsif ( $self->dist ) {
53 # Map CPAN dist path to url
54 0 my $dist = $self->dist;
55 0 $self->trace("Using distribution path $dist\n");
56 0 my $one = substr( $self->dist, 0, 1 );
57 0 my $two = substr( $self->dist, 1, 1 );
58 0 my $path = File::Spec::Unix->catfile(
59 'authors', 'id', $one, "$one$two", $dist,
60 );
61 0 $self->{url} = URI->new_abs( $path, $self->cpan )->as_string;
62  
63 ▶ } elsif ( $self->can('name') and $self->name ) {
Condition0%0/3
$self->can("name") and $self->name
!ll&&!rl&&r
000
MC/DC0%0/2
$self->can("name") and $self->name
$self->can("name") $self->name
Truth table0%0/3
A and B
A= $self->can("name")B= $self->name
ABresult
0X0
100
111
64 # Map name to URL via the default package path
65 0 $self->{url} = $self->parent->binary_url($self->name);
66 }
67 }
68  
69 # Check params
70 3 ▶ unless ( _STRING($self->url) ) {
Branch: 1 branch
BranchTrueFalseTotal
unless (&_STRING(scalar $self->url)) 0 3 3
71 0 croak("Missing or invalid url param");
72 }
73  
74 # Create the filename from the url
75 3 $self->{file} = $self->url;
76 3 $self->{file} =~ s|.+/||;
77 3 ▶ unless ( $self->file and length $self->file ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->file and length $self->file) 0 3 3
Condition33%1/3
$self->file and length $self->file
!ll&&!rl&&r
003
MC/DC0%0/2
$self->file and length $self->file
$self->file length $self->file
Truth table33%1/3
A and B
A= $self->fileB= length $self->file
ABresult
0X0
100
111
78 0 croak("Missing or invalid file");
79 }
80  
81 3 return $self;
82 }
83  
84 0 ▶sub cpan {
Subroutine cpan: not called CC=1 SCAR=6.9
Pod undocumented
85 0 $_[0]->parent->cpan;
86 }
87  
88  
89  
90  
91  
92 #####################################################################
93 # Support Methods
94  
95 2 ▶sub trace {
Subroutine trace: called CC=2 SCAR=7.6
Pod undocumented
96 2 my $self = shift;
97 2 ▶ if ( _CODELIKE($self->{trace}) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (&_CODELIKE($self->{'trace'})) { } 0 2 2
98 0 $self->{trace}->(@_);
99 } else {
100 2 print $_[0];
101 }
102 }
103  
104 3 1;
« blib/lib/Perl/Dist/Inno/System.pm ↑ Summary blib/lib/auto/share/dist/Perl-Dist/default/perl-5.10.0/lib/ExtUtils/Command.pm »