File Coverage

blib/lib/Alien/Build/Plugin/Fetch/LocalDir.pm
Criterion Covered Total %
statement 34 45 75.5
branch 5 12 41.6
condition 2 5 40.0
subroutine 8 8 100.0
pod 1 1 100.0
total 50 71 70.4


line stmt bran cond sub pod time code
1             package Alien::Build::Plugin::Fetch::LocalDir;
2              
3 3     3   1497 use strict;
  3         13  
  3         109  
4 3     3   18 use warnings;
  3         7  
  3         82  
5 3     3   79 use 5.008004;
  3         12  
6 3     3   366 use Alien::Build::Plugin;
  3         7  
  3         28  
7 3     3   522 use File::chdir;
  3         2782  
  3         539  
8 3     3   29 use Path::Tiny ();
  3         12  
  3         1599  
9              
10             # ABSTRACT: Plugin for fetching a local directory
11             our $VERSION = '2.45'; # VERSION
12              
13              
14             has root => undef;
15              
16              
17             has ssl => 0;
18              
19             sub init
20             {
21 2     2 1 7 my($self, $meta) = @_;
22              
23 2   50     10 my $url = $meta->prop->{start_url} || 'patch';
24              
25 2         17 $meta->add_requires('configure' => 'Alien::Build::Plugin::Fetch::LocalDir' => '0.72' );
26              
27 2 50       9 if($url =~ /^file:/)
28             {
29 0         0 $meta->add_requires('share' => 'URI' => 0 );
30 0         0 $meta->add_requires('share' => 'URI::file' => 0 );
31             }
32              
33             {
34 2         5 my $root = $self->root;
  2         19  
35 2 50       12 if(defined $root)
36             {
37 0         0 $root = Path::Tiny->new($root)->absolute->stringify;
38             }
39             else
40             {
41 2         17 $root = "$CWD";
42             }
43 2         61 $self->root($root);
44             }
45              
46             $meta->register_hook(
47             fetch => sub {
48 2     2   6 my($build, $path, %options) = @_;
49              
50 2 50       18 $build->log("plugin Fetch::LocalDir does not support http_headers option") if $options{http_headers};
51              
52 2   33     25 $path ||= $url;
53              
54 2 50       15 if($path =~ /^file:/)
55             {
56 0         0 my $root = URI::file->new($self->root);
57 0         0 my $url = URI->new_abs($path, $root);
58 0         0 $path = $url->path;
59 0 0       0 $path =~ s{^/([a-z]:)}{$1}i if $^O eq 'MSWin32';
60             }
61              
62 2         21 $path = Path::Tiny->new($path)->absolute($self->root);
63              
64 2 50       272 if(-d $path)
65             {
66             return {
67 2         57 type => 'file',
68             filename => $path->basename,
69             path => $path->stringify,
70             tmp => 0,
71             };
72             }
73             else
74             {
75 0           $build->log("path $path is not a directory");
76 0           $build->log("(you specified $url with root @{[ $self->root ]})");
  0            
77 0           die "$path is not a directory";
78             }
79             }
80 2         25 );
81             }
82              
83             1;
84              
85             __END__