5 |
|
# new() : |
6 |
|
# new(cachedir) : A new urlhandler with a defined default cahce directory |
7 |
|
# get(url) : download from the specified url to the default cache |
8 |
< |
# get(url,location) : download to the specified directory |
9 |
< |
# setbase(type,@args) : set the url defaults for a specific url type |
10 |
< |
# arguments are dependent on type |
11 |
< |
# http: |
12 |
< |
# file: |
13 |
< |
# cvs: servername,servertype [ ,user,passkey ] |
14 |
< |
# label: |
8 |
> |
# get(url,dirlocation) : download to the specified directory |
9 |
> |
# setbase(type,variablehash) : set the url defaults for a specific url type |
10 |
> |
# arguments are dependent on type |
11 |
|
# unsetbase(type) : deactivate a previously set base |
12 |
+ |
# setcache(dir) : set the default cache location |
13 |
|
# |
14 |
|
# ---------------------------------------------------------------------- |
15 |
|
# returns file location - or crashes out |
19 |
|
package URLhandler; |
20 |
|
require 5.004; |
21 |
|
use Utilities::AddDir; |
22 |
+ |
use URL::URL_base; |
23 |
|
use Carp; |
24 |
|
|
25 |
|
sub new { |
48 |
|
$self->setbase("file", {}); # Base file as default |
49 |
|
} |
50 |
|
|
51 |
+ |
sub setcache { |
52 |
+ |
my $self=shift; |
53 |
+ |
my $cache=shift; |
54 |
+ |
|
55 |
+ |
$self->{cache}=$cache; |
56 |
+ |
} |
57 |
+ |
|
58 |
|
sub get ($@) { |
59 |
|
my $self=shift; |
60 |
|
my $origurl=shift; |
61 |
< |
my $filename=shift; |
61 |
> |
my $dirname=shift; |
62 |
|
my $rest; |
63 |
|
my $type; |
64 |
|
my $url; |
65 |
|
my $version; |
66 |
+ |
my $rv=""; |
67 |
|
|
68 |
< |
if ( ! defined $filename ) { |
69 |
< |
$filename=$self->{cache}; |
68 |
> |
if ( ! defined $dirname ) { |
69 |
> |
$dirname=$self->{cache}; |
70 |
|
} |
71 |
+ |
print "dirname = $dirname \n"; |
72 |
+ |
chdir $dirname or carp "Unable to Enter Directory $dirname $!\n"; |
73 |
|
chomp $origurl; |
74 |
|
# get our version info from the url (after last ??) |
75 |
|
( $url, $version) = split /\?\?/, $origurl; |
85 |
|
carp; |
86 |
|
} |
87 |
|
else { |
88 |
< |
eval{${$self->{urlostack}{$type}}[$#{$self->{urlostack}{$type}}]}-> |
89 |
< |
get($rest, $filename); |
88 |
> |
if ( $#{$self->{urlostack}{$type}} < 0 ) { |
89 |
> |
print "URLhandler : base not set for type $type \n"; |
90 |
> |
} |
91 |
> |
else { |
92 |
> |
$rv= |
93 |
> |
eval{${$self->{urlostack}{$type}}[$#{$self->{urlostack}{$type}}]}-> |
94 |
> |
get($rest); |
95 |
> |
} |
96 |
> |
} |
97 |
> |
if ( $rv ne "" ) { |
98 |
> |
$rv=$dirname."/".$rv; |
99 |
|
} |
100 |
+ |
return $rv; |
101 |
|
} |
102 |
|
|
103 |
|
sub setbase { |