File Coverage

blib/lib/URI/cpan/distfile.pm
Criterion Covered Total %
statement 30 30 100.0
branch 3 4 75.0
condition n/a
subroutine 10 10 100.0
pod 0 5 0.0
total 43 49 87.7


line stmt bran cond sub pod time code
1 1     1   7 use strict;
  1         2  
  1         35  
2 1     1   5 use warnings;
  1         1  
  1         55  
3              
4             package URI::cpan::distfile 1.009;
5             # ABSTRACT: cpan:///distfile/AUTHOR/Dist-1.234.tar.gz
6              
7 1     1   7 use parent qw(URI::cpan);
  1         2  
  1         4  
8              
9 1     1   64 use Carp ();
  1         2  
  1         16  
10 1     1   1095 use CPAN::DistnameInfo;
  1         1055  
  1         312  
11              
12             #pod =head1 SYNOPSIS
13             #pod
14             #pod This URL refers to a file in an author directory on the CPAN, and expects the
15             #pod format AUTHOR/DISTFILE
16             #pod
17             #pod =head1 METHODS
18             #pod
19             #pod =cut
20              
21             sub validate {
22 3     3 0 6 my ($self) = @_;
23              
24 3         10 my (undef, undef, $author, $filename) = split m{/}, $self->path, 4;
25              
26 3 50       95 Carp::croak "invalid cpan URI: invalid author part in $self"
27             unless $author =~ m{\A[A-Z][-0-9A-Z]*\z};
28             }
29              
30             #pod =head1 dist_name
31             #pod
32             #pod This returns the name of the dist, like F or F.
33             #pod
34             #pod =cut
35              
36             sub dist_name {
37 3     3 0 7 my ($self) = @_;
38 3         11 my $dist = CPAN::DistnameInfo->new($self->_p_rel);
39 3         222 my $name = $dist->dist;
40              
41 3 100       19 $name =~ s/-undef$// if ! defined $dist->version;
42              
43 3         35 return $name;
44             }
45              
46             #pod =head1 dist_version
47             #pod
48             #pod This returns the version of the dist, or undef if the version can't be found or
49             #pod is the string "undef"
50             #pod
51             #pod =cut
52              
53             sub dist_version {
54 3     3 0 7 my ($self) = @_;
55 3         9 CPAN::DistnameInfo->new($self->_p_rel)->version;
56             }
57              
58             #pod =head1 dist_filepath
59             #pod
60             #pod This returns the path to the dist file. This is the whole URL after the
61             #pod C part.
62             #pod
63             #pod =cut
64              
65             sub dist_filepath {
66 1     1 0 618 my ($self) = @_;
67 1         5 $self->_p_rel;
68             }
69              
70             #pod =head1 author
71             #pod
72             #pod This returns the name of the author whose file is referred to.
73             #pod
74             #pod =cut
75              
76             sub author {
77 3     3 0 1294 my ($self) = @_;
78 3         12 my ($author) = $self->_p_rel =~ m{^([A-Z]+)/};
79 3         15 return $author;
80             }
81              
82             1;
83              
84             __END__