Skip to content
This repository has been archived by the owner on Mar 7, 2019. It is now read-only.

Commit

Permalink
Merge pull request #31 from zmughal/fix/http-abs-uri
Browse files Browse the repository at this point in the history
fix for repository paths that are not relative
  • Loading branch information
jberger committed Dec 15, 2013
2 parents 9115727 + 0c506a6 commit 4a7f13b
Show file tree
Hide file tree
Showing 6 changed files with 21 additions and 5 deletions.
2 changes: 1 addition & 1 deletion lib/Alien/Base/ModuleBuild/File.pm
Expand Up @@ -23,7 +23,7 @@ sub has_version {
sub get {
my $self = shift;
my $filename = $self->filename;
$self->repository->get_file($filename);
$filename = $self->repository->get_file($filename);
return $filename;
}

Expand Down
1 change: 1 addition & 0 deletions lib/Alien/Base/ModuleBuild/Repository.pm
Expand Up @@ -80,6 +80,7 @@ sub probe {
# subclasses are expected to provide
sub connection { croak "$_[0] doesn't provide 'connection' method" }
sub list_files { croak "$_[0] doesn't provide 'list_files' method" }
# must return filename if different from the one passed in
sub get_file { croak "$_[0] doesn't provide 'get_files' method" }

1;
Expand Down
2 changes: 1 addition & 1 deletion lib/Alien/Base/ModuleBuild/Repository/FTP.pm
Expand Up @@ -48,7 +48,7 @@ sub get_file {

$ftp->get( $file ) or croak "Download failed: " . $ftp->message();

return 1;
return $file;
}

sub list_files {
Expand Down
9 changes: 7 additions & 2 deletions lib/Alien/Base/ModuleBuild/Repository/HTTP.pm
Expand Up @@ -43,10 +43,12 @@ sub get_file {
my $from = $self->location;

my $uri = $self->build_uri($host, $from, $file);
# if it is an absolute URI, then use the filename from the URI
$file = ($uri->path_segments())[-1] if $file =~ /^http:/;
my $response = $self->connection->mirror($uri, $file);
croak "Download failed: " . $response->{reason} unless $response->{success};

return 1;
return $file;
}

sub list_files {
Expand Down Expand Up @@ -112,10 +114,13 @@ sub build_uri {
my $self = shift;
my ($host, $path, $file) = @_;

my $uri = URI->new($file);
return $uri if $uri->scheme; # if an absolute URI

unless ( $host =~ m'^http://' ) {
$host = "http://$host";
}
my $uri = URI->new( $host );
$uri = URI->new( $host );
return $uri unless defined $path;

$path =~ s'/$'';
Expand Down
2 changes: 1 addition & 1 deletion lib/Alien/Base/ModuleBuild/Repository/Local.pm
Expand Up @@ -50,7 +50,7 @@ sub get_file {

copy $full_file, $CWD;

return 1;
return $file;
}

1;
Expand Down
10 changes: 10 additions & 0 deletions t/http_uri.t
Expand Up @@ -32,5 +32,15 @@ my $repo = Alien::Base::ModuleBuild::Repository::HTTP->new;
is $uri, 'http://host.com/path/file.ext', 'file with path';
}

{
my $uri = $repo->build_uri('host.com/', '/path/', 'http://host.com/other/file.ext');
is $uri, 'http://host.com/other/file.ext', 'absolute URI found in link';
}

{
my $uri = $repo->build_uri('host.com/', '/path/', 'http://example.org/other/file.ext');
is $uri, 'http://example.org/other/file.ext', 'absolute URI on different host';
}

done_testing;

0 comments on commit 4a7f13b

Please sign in to comment.