Alien-ROOT
view release on metacpan or search on metacpan
inc/inc_File-Fetch/File/Fetch.pm view on Meta::CPAN
use File::Fetch;
### build a File::Fetch object ###
my $ff = File::Fetch->new(uri => 'http://some.where.com/dir/a.txt');
### fetch the uri to cwd() ###
my $where = $ff->fetch() or die $ff->error;
### fetch the uri to /tmp ###
my $where = $ff->fetch( to => '/tmp' );
### parsed bits from the uri ###
$ff->uri;
$ff->scheme;
$ff->host;
$ff->path;
$ff->file;
=head1 DESCRIPTION
File::Fetch is a generic file fetching mechanism.
It allows you to fetch any file pointed to by a C<ftp>, C<http>,
C<file>, or C<rsync> uri by a number of different means.
See the C<HOW IT WORKS> section further down for details.
=head1 ACCESSORS
A C<File::Fetch> object has the following accessors
=over 4
=item $ff->uri
The uri you passed to the constructor
=item $ff->scheme
The scheme from the uri (like 'file', 'http', etc)
=item $ff->host
The hostname in the uri. Will be empty if host was originally
'localhost' for a 'file://' url.
=item $ff->vol
On operating systems with the concept of a volume the second element
of a file:// is considered to the be volume specification for the file.
Thus on Win32 this routine returns the volume, on other operating
systems this returns nothing.
On Windows this value may be empty if the uri is to a network share, in
which case the 'share' property will be defined. Additionally, volume
specifications that use '|' as ':' will be converted on read to use ':'.
On VMS, which has a volume concept, this field will be empty because VMS
file specifications are converted to absolute UNIX format and the volume
information is transparently included.
=item $ff->share
On systems with the concept of a network share (currently only Windows) returns
the sharename from a file://// url. On other operating systems returns empty.
=item $ff->path
The path from the uri, will be at least a single '/'.
=item $ff->file
The name of the remote file. For the local file name, the
result of $ff->output_file will be used.
=item $ff->file_default
The name of the default local file, that $ff->output_file falls back to if
it would otherwise return no filename. For example when fetching a URI like
http://www.abc.net.au/ the contents retrieved may be from a remote file called
'index.html'. The default value of this attribute is literally 'file_default'.
=cut
##########################
### Object & Accessors ###
##########################
{
### template for autogenerated accessors ###
my $Tmpl = {
scheme => { default => 'http' },
host => { default => 'localhost' },
path => { default => '/' },
file => { required => 1 },
uri => { required => 1 },
vol => { default => '' }, # windows for file:// uris
share => { default => '' }, # windows for file:// uris
file_default => { default => 'file_default' },
_error_msg => { no_override => 1 },
_error_msg_long => { no_override => 1 },
};
for my $method ( keys %$Tmpl ) {
no strict 'refs';
*$method = sub {
my $self = shift;
$self->{$method} = $_[0] if @_;
return $self->{$method};
}
}
sub _create {
my $class = shift;
my %hash = @_;
my $args = check( $Tmpl, \%hash ) or return;
bless $args, $class;
( run in 1.889 second using v1.01-cache-2.11-cpan-8450f2e95f3 )