Alien-ROOT
view release on metacpan or search on metacpan
inc/inc_File-Fetch/File/Fetch.pm view on Meta::CPAN
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;
if( lc($args->scheme) ne 'file' and not $args->host ) {
return $class->_error(loc(
"Hostname required when fetching from '%1'",$args->scheme));
}
for (qw[path]) {
unless( $args->$_() ) { # 5.5.x needs the ()
return $class->_error(loc("No '%1' specified",$_));
}
}
return $args;
}
}
=item $ff->output_file
The name of the output file. This is the same as $ff->file,
but any query parameters are stripped off. For example:
http://example.com/index.html?x=y
would make the output file be C<index.html> rather than
C<index.html?x=y>.
=back
=cut
sub output_file {
my $self = shift;
my $file = $self->file;
$file =~ s/\?.*$//g;
$file ||= $self->file_default;
return $file;
}
### XXX do this or just point to URI::Escape?
# =head2 $esc_uri = $ff->escaped_uri
#
# =cut
#
# ### most of this is stolen straight from URI::escape
# { ### Build a char->hex map
# my %escapes = map { chr($_) => sprintf("%%%02X", $_) } 0..255;
#
# sub escaped_uri {
# my $self = shift;
# my $uri = $self->uri;
#
# ### Default unsafe characters. RFC 2732 ^(uric - reserved)
# $uri =~ s/([^A-Za-z0-9\-_.!~*'()])/
# $escapes{$1} || $self->_fail_hi($1)/ge;
#
# return $uri;
# }
( run in 0.484 second using v1.01-cache-2.11-cpan-5735350b133 )