1package Alien::Build::Plugin::Fetch::Local; 2 3use strict; 4use warnings; 5use 5.008004; 6use Alien::Build::Plugin; 7use File::chdir; 8use Path::Tiny (); 9 10# ABSTRACT: Plugin for fetching a local file 11our $VERSION = '2.45'; # VERSION 12 13 14has '+url' => ''; 15 16 17has root => undef; 18 19 20has ssl => 0; 21 22sub init 23{ 24 my($self, $meta) = @_; 25 26 $meta->prop->{start_url} ||= $self->url; 27 $self->url($meta->prop->{start_url} || 'patch'); 28 29 if($self->url =~ /^file:/) 30 { 31 $meta->add_requires('share' => 'URI' => 0 ); 32 $meta->add_requires('share' => 'URI::file' => 0 ); 33 $meta->add_requires('share' => 'URI::Escape' => 0 ); 34 } 35 36 { 37 my $root = $self->root; 38 if(defined $root) 39 { 40 $root = Path::Tiny->new($root)->absolute->stringify; 41 } 42 else 43 { 44 $root = "$CWD"; 45 } 46 $self->root($root); 47 } 48 49 $meta->register_hook( fetch => sub { 50 my($build, $path, %options) = @_; 51 52 $build->log("plugin Fetch::Local does not support http_headers option") if $options{http_headers}; 53 54 $path ||= $self->url; 55 56 if($path =~ /^file:/) 57 { 58 my $root = URI::file->new($self->root); 59 my $url = URI->new_abs($path, $root); 60 $path = URI::Escape::uri_unescape($url->path); 61 $path =~ s{^/([a-z]:)}{$1}i if $^O eq 'MSWin32'; 62 } 63 64 $path = Path::Tiny->new($path)->absolute($self->root); 65 66 if(-d $path) 67 { 68 return { 69 type => 'list', 70 list => [ 71 map { { filename => $_->basename, url => $_->stringify } } 72 sort { $a->basename cmp $b->basename } $path->children, 73 ], 74 }; 75 } 76 elsif(-f $path) 77 { 78 return { 79 type => 'file', 80 filename => $path->basename, 81 path => $path->stringify, 82 tmp => 0, 83 }; 84 } 85 else 86 { 87 die "no such file or directory $path"; 88 } 89 90 91 }); 92} 93 941; 95 96__END__ 97 98=pod 99 100=encoding UTF-8 101 102=head1 NAME 103 104Alien::Build::Plugin::Fetch::Local - Plugin for fetching a local file 105 106=head1 VERSION 107 108version 2.45 109 110=head1 SYNOPSIS 111 112 use alienfile; 113 share { 114 start_url 'patch/libfoo-1.00.tar.gz'; 115 plugin 'Fetch::Local'; 116 }; 117 118=head1 DESCRIPTION 119 120Note: in most case you will want to use L<Alien::Build::Plugin::Download::Negotiate> 121instead. It picks the appropriate fetch plugin based on your platform and environment. 122In some cases you may need to use this plugin directly instead. 123 124This fetch plugin fetches files from the local file system. It is mostly useful if you 125intend to bundle packages (as tarballs or zip files) with your Alien. If you intend to 126bundle a source tree, use L<Alien::Build::Plugin::Fetch::LocalDir>. 127 128=head1 PROPERTIES 129 130=head2 url 131 132The initial URL to fetch. This may be a C<file://> style URL, or just the path on the 133local system. 134 135=head2 root 136 137The directory from which the URL should be relative. The default is usually reasonable. 138 139=head2 ssl 140 141This property is for compatibility with other fetch plugins, but is not used. 142 143=head1 SEE ALSO 144 145=over 4 146 147=item L<Alien::Build::Plugin::Download::Negotiate> 148 149=item L<Alien::Build::Plugin::Fetch::LocalDir> 150 151=item L<Alien::Build> 152 153=item L<alienfile> 154 155=item L<Alien::Build::MM> 156 157=item L<Alien> 158 159=back 160 161=head1 AUTHOR 162 163Author: Graham Ollis E<lt>plicease@cpan.orgE<gt> 164 165Contributors: 166 167Diab Jerius (DJERIUS) 168 169Roy Storey (KIWIROY) 170 171Ilya Pavlov 172 173David Mertens (run4flat) 174 175Mark Nunberg (mordy, mnunberg) 176 177Christian Walde (Mithaldu) 178 179Brian Wightman (MidLifeXis) 180 181Zaki Mughal (zmughal) 182 183mohawk (mohawk2, ETJ) 184 185Vikas N Kumar (vikasnkumar) 186 187Flavio Poletti (polettix) 188 189Salvador Fandiño (salva) 190 191Gianni Ceccarelli (dakkar) 192 193Pavel Shaydo (zwon, trinitum) 194 195Kang-min Liu (劉康民, gugod) 196 197Nicholas Shipp (nshp) 198 199Juan Julián Merelo Guervós (JJ) 200 201Joel Berger (JBERGER) 202 203Petr Písař (ppisar) 204 205Lance Wicks (LANCEW) 206 207Ahmad Fatoum (a3f, ATHREEF) 208 209José Joaquín Atria (JJATRIA) 210 211Duke Leto (LETO) 212 213Shoichi Kaji (SKAJI) 214 215Shawn Laffan (SLAFFAN) 216 217Paul Evans (leonerd, PEVANS) 218 219Håkon Hægland (hakonhagland, HAKONH) 220 221nick nauwelaerts (INPHOBIA) 222 223=head1 COPYRIGHT AND LICENSE 224 225This software is copyright (c) 2011-2020 by Graham Ollis. 226 227This is free software; you can redistribute it and/or modify it under 228the same terms as the Perl 5 programming language system itself. 229 230=cut 231