1 |
– |
# url handler -> returns the location of the file |
1 |
|
# Interface |
2 |
|
# --------- |
3 |
|
# new(cache) : A new urlhandler with a defined default cahce directory |
5 |
|
# get(url,[location]) : download from the specified url to cache or location |
6 |
|
# return the full url path name incl. any base expansion |
7 |
|
# and the filename downloaded to |
8 |
< |
# setbase(type,variablehash) : set the url defaults for a specific url type |
10 |
< |
# arguments are dependent on type |
8 |
> |
# setbase(urlstring) : set a base url type |
9 |
|
# unsetbase(type) : deactivate a previously set base |
10 |
|
# currentbase(type) : return the current base for the given type |
11 |
|
# |
16 |
|
use Utilities::AddDir; |
17 |
|
use URL::URLcache; |
18 |
|
use URL::URLclass; |
21 |
– |
use URL::URLbase; |
19 |
|
use Carp; |
20 |
|
|
21 |
|
sub new { |
32 |
|
my $self=shift; |
33 |
|
my $cache=shift; |
34 |
|
$self->{cache}=$cache; |
38 |
– |
$self->{dummybase}=URL::URLbase->new({}); |
35 |
|
$self->{cachestore}=$self->{cache}->filestore(); |
36 |
|
use URL::URL_cvs; |
41 |
– |
use URL::URL_cvsfile; |
37 |
|
use URL::URL_file; |
38 |
|
use URL::URL_test; |
44 |
– |
use URL::URL_filed; |
39 |
|
$self->{urlmodules}={ |
46 |
– |
'cvsfile' => 'URL::URL_cvsfile', |
40 |
|
'cvs' => 'URL::URL_cvs', |
41 |
|
'file' => 'URL::URL_file', |
49 |
– |
'filed' => 'URL::URL_filed', |
42 |
|
'test' => 'URL::URL_test' |
43 |
|
}; |
44 |
|
} |
50 |
|
|
51 |
|
my $url=URL::URLclass->new($origurl); |
52 |
|
my $type=$url->type(); |
53 |
< |
$url->expandurl($self->currentbase($type)); |
53 |
> |
$url->merge($self->currentbase($type)); |
54 |
|
my $fullurl=$url->url(); |
55 |
|
|
56 |
|
$file=$self->{cache}->file($fullurl); |
68 |
|
my $url=URL::URLclass->new($origurl); |
69 |
|
my $type=$url->type(); |
70 |
|
$urltypehandler=$self->_typehandler($type); |
71 |
< |
$url->expandurl($self->currentbase($type)); |
71 |
> |
$url->merge($self->currentbase($type)); |
72 |
|
|
73 |
|
# Generate a location name if not provided |
74 |
|
$nocache=1; |
94 |
|
|
95 |
|
sub setbase { |
96 |
|
my $self=shift; |
97 |
< |
my $type=shift; |
106 |
< |
my @args=@_; |
107 |
< |
my $oref; |
97 |
> |
my $partialurl=shift; |
98 |
|
|
99 |
+ |
my $base=URL::URLclass->new($partialurl); |
100 |
+ |
my $type=$base->type(); |
101 |
|
$self->checktype($type); |
102 |
< |
# make a new base object |
111 |
< |
my $base=URL::URLbase->new(@_); |
102 |
> |
# make a new base-url object |
103 |
|
push @{$self->{"basestack"}{$type}}, $base; |
104 |
|
} |
105 |
|
|
132 |
|
$rv=${$self->{basestack}{$type}}[$#{$self->{basestack}{$type}}]; |
133 |
|
} |
134 |
|
else { |
135 |
< |
$rv=$self->{dummybase}; |
135 |
> |
$rv=undef; |
136 |
|
} |
137 |
|
return $rv; |
138 |
|
} |