File Coverage

blib/lib/Alien/Base/ModuleBuild/Repository.pm
Criterion Covered Total %
statement 51 54 94.4
branch 21 26 80.7
condition 9 9 100.0
subroutine 10 13 76.9
pod 0 8 0.0
total 91 110 82.7


line stmt bran cond sub pod time code
1             package Alien::Base::ModuleBuild::Repository;
2              
3 5     5   235076 use strict;
  5         18  
  5         153  
4 5     5   39 use warnings;
  5         33  
  5         128  
5 5     5   24 use Carp;
  5         11  
  5         316  
6 5     5   2235 use Alien::Base::ModuleBuild::File;
  5         16  
  5         180  
7 5     5   1745 use Alien::Base::ModuleBuild::Utils qw/pattern_has_capture_groups/;
  5         25  
  5         3287  
8              
9             # ABSTRACT: Private class
10             our $VERSION = '1.15'; # VERSION
11              
12             sub new {
13 21     21 0 50421 my $class = shift;
14 21 100       194 my (%self) = ref $_[0] ? %{ shift() } : @_;
  9         112  
15              
16 21         86 my $obj = bless \%self, $class;
17              
18             $obj->{c_compiler_required} = 1
19 21 100       122 unless defined $obj->{c_compiler_required};
20              
21 21 100 100     104 if($obj->{exact_filename} && $obj->{location} !~ m{/$}) {
22 3         10 $obj->{location} .= '/'
23             }
24              
25 21         85 return $obj;
26             }
27              
28 8     8 0 22 sub protocol { return shift->{protocol} }
29              
30             sub host {
31 1     1 0 2 my $self = shift;
32 1 50       5 $self->{host} = shift if @_;
33 1         3 return $self->{host};
34             }
35              
36             sub location {
37 27     27 0 140 my $self = shift;
38 27 100       85 $self->{location} = shift if @_;
39 27         122 return $self->{location};
40             }
41              
42             sub probe {
43 8     8 0 337 my $self = shift;
44              
45 8         20 my $pattern = $self->{pattern};
46              
47 8         17 my @files;
48              
49 8 100       28 if ($self->{exact_filename}) {
50             # if filename provided, use that specific file
51 2         5 @files = ($self->{exact_filename});
52             } else {
53 6         60 @files = $self->list_files();
54              
55 6 100       157 if ($pattern) {
56 2         6 @files = grep { $_ =~ $pattern } @files;
  110         300  
57             }
58              
59 6 50       19 carp "Could not find any matching files" unless @files;
60             }
61              
62 8         26 @files = map { +{
63             repository => $self,
64             platform => $self->{platform},
65 94         268 filename => $_,
66             } } @files;
67              
68 8 100 100     80 if ($self->{exact_filename} and $self->{exact_version}) {
    100 100        
69             # if filename and version provided, use a specific version
70 1         3 $files[0]->{version} = $self->{exact_version};
71 1 50       5 $files[0]->{sha1} = $self->{sha1} if defined $self->{sha1};
72 1 50       4 $files[0]->{sha256} = $self->{sha256} if defined $self->{sha256};
73             } elsif ($pattern and pattern_has_capture_groups($pattern)) {
74 1         5 foreach my $file (@files) {
75             $file->{version} = $1
76 17 50       86 if $file->{filename} =~ $pattern;
77             }
78             }
79              
80             @files =
81 8         20 map { Alien::Base::ModuleBuild::File->new($_) }
  94         272  
82             @files;
83              
84 8         45 return @files;
85             }
86              
87             # subclasses are expected to provide
88 0     0 0   sub connection { croak "$_[0] doesn't provide 'connection' method" }
89 0     0 0   sub list_files { croak "$_[0] doesn't provide 'list_files' method" }
90             # get_file must return filename actually used
91 0     0 0   sub get_file { croak "$_[0] doesn't provide 'get_files' method" }
92              
93             1;
94              
95             __END__