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 - return the url object |
9 |
|
# unsetbase(type) : deactivate a previously set base |
10 |
|
# currentbase(type) : return the current base for the given type |
11 |
+ |
# expandurl(urlstring) : return the base expanded URLclass of the given string |
12 |
|
# |
13 |
|
# ---------------------------------------------------------------------- |
14 |
|
|
17 |
|
use Utilities::AddDir; |
18 |
|
use URL::URLcache; |
19 |
|
use URL::URLclass; |
21 |
– |
use URL::URLbase; |
20 |
|
use Carp; |
21 |
|
|
22 |
|
sub new { |
33 |
|
my $self=shift; |
34 |
|
my $cache=shift; |
35 |
|
$self->{cache}=$cache; |
38 |
– |
$self->{dummybase}=URL::URLbase->new({}); |
36 |
|
$self->{cachestore}=$self->{cache}->filestore(); |
37 |
|
use URL::URL_cvs; |
41 |
– |
use URL::URL_cvsfile; |
38 |
|
use URL::URL_file; |
39 |
|
use URL::URL_test; |
44 |
– |
use URL::URL_filed; |
40 |
|
$self->{urlmodules}={ |
46 |
– |
'cvsfile' => 'URL::URL_cvsfile', |
41 |
|
'cvs' => 'URL::URL_cvs', |
42 |
|
'file' => 'URL::URL_file', |
49 |
– |
'filed' => 'URL::URL_filed', |
43 |
|
'test' => 'URL::URL_test' |
44 |
|
}; |
45 |
|
} |
51 |
|
|
52 |
|
my $url=URL::URLclass->new($origurl); |
53 |
|
my $type=$url->type(); |
54 |
< |
$url->expandurl($self->currentbase($type)); |
54 |
> |
$url->merge($self->currentbase($type)); |
55 |
|
my $fullurl=$url->url(); |
56 |
|
|
57 |
|
$file=$self->{cache}->file($fullurl); |
69 |
|
my $url=URL::URLclass->new($origurl); |
70 |
|
my $type=$url->type(); |
71 |
|
$urltypehandler=$self->_typehandler($type); |
72 |
< |
$url->expandurl($self->currentbase($type)); |
72 |
> |
$url->merge($self->currentbase($type)); |
73 |
> |
print "Attempting download of ".$url->url()."\n"; |
74 |
|
|
75 |
|
# Generate a location name if not provided |
76 |
< |
$nocache=1; |
76 |
> |
my $nocache=1; |
77 |
|
if ( @_ ) { |
78 |
|
$location=shift; |
79 |
|
$nocache=0; # dont cache if downloaded to an external location |
89 |
|
|
90 |
|
# now register it in the cache if successful |
91 |
|
if ( $file && $nocache) { |
92 |
< |
$self->{cache}->store($url->url(), $location); |
92 |
> |
#$self->{cache}->store($url->url(), $location); |
93 |
> |
$self->{cache}->store($url->url(), $file); |
94 |
|
} |
95 |
|
return ($url->url(), $file); |
96 |
|
} |
97 |
|
|
98 |
+ |
sub expandurl { |
99 |
+ |
my $self=shift; |
100 |
+ |
my $urlstring=shift; |
101 |
+ |
|
102 |
+ |
my $url=URL::URLclass->new($urlstring); |
103 |
+ |
my $type=$url->type(); |
104 |
+ |
$url->merge($self->currentbase($type)); |
105 |
+ |
return $url; |
106 |
+ |
} |
107 |
+ |
|
108 |
|
sub setbase { |
109 |
|
my $self=shift; |
110 |
< |
my $type=shift; |
106 |
< |
my @args=@_; |
107 |
< |
my $oref; |
110 |
> |
my $partialurl=shift; |
111 |
|
|
112 |
+ |
my $base=URL::URLclass->new($partialurl); |
113 |
+ |
my $type=$base->type(); |
114 |
|
$self->checktype($type); |
115 |
< |
# make a new base object |
111 |
< |
my $base=URL::URLbase->new(@_); |
115 |
> |
# make a new base-url object |
116 |
|
push @{$self->{"basestack"}{$type}}, $base; |
117 |
+ |
return $base; |
118 |
|
} |
119 |
|
|
120 |
|
sub unsetbase { |
146 |
|
$rv=${$self->{basestack}{$type}}[$#{$self->{basestack}{$type}}]; |
147 |
|
} |
148 |
|
else { |
149 |
< |
$rv=$self->{dummybase}; |
149 |
> |
$rv=undef; |
150 |
|
} |
151 |
|
return $rv; |
152 |
|
} |