11 |
|
# currentbase(type) : return the current base for the given type |
12 |
|
# |
13 |
|
# ---------------------------------------------------------------------- |
14 |
– |
# returns file location - or crashes out |
15 |
– |
# can pass a file name for the item to be stored as |
16 |
– |
# if not then stores in a default cache. |
14 |
|
|
15 |
|
package URL::URLhandler; |
16 |
|
require 5.004; |
46 |
|
'file' => 'URL::URL_file', |
47 |
|
'filed' => 'URL::URL_filed' |
48 |
|
}; |
52 |
– |
$self->{filebase}=""; |
53 |
– |
$self->setbase("file", {}); # Base file as default |
54 |
– |
$self->setbase("filed", {}); # Base file as default |
49 |
|
} |
50 |
|
|
51 |
|
sub get { |
65 |
|
else { |
66 |
|
$location=$self->{cache}->filename($url->url()); |
67 |
|
} |
74 |
– |
|
68 |
|
# -- get the file form the appropriate handler |
69 |
|
if ( defined $urltypehandler ) { |
70 |
|
# Call the download module |
73 |
|
|
74 |
|
# now register it in the cache if successful |
75 |
|
if ( $file ) { |
76 |
< |
$self->{cache}->store($fullurl, $rv); |
76 |
> |
$self->{cache}->store($url->url(), $file); |
77 |
|
} |
78 |
< |
return ($fullurl, $file); |
78 |
> |
return ($url->url(), $file); |
79 |
|
} |
80 |
|
|
81 |
|
sub setbase { |
87 |
|
$self->checktype($type); |
88 |
|
# make a new base object |
89 |
|
my $base=URL::URLbase->new(@_); |
90 |
< |
push @{$self->{basestack}{$type}}, $base; |
90 |
> |
push @{$self->{"basestack"}{$type}}, $base; |
91 |
|
} |
92 |
|
|
93 |
|
sub unsetbase { |
104 |
|
else { |
105 |
|
die "URLhandler error: Unable to unset type $type\n"; |
106 |
|
} |
107 |
+ |
# remove the stack if its empty |
108 |
+ |
if ( $#{$self->{basestack}{$type}} == -1 ) { |
109 |
+ |
delete $self->{basestack}{$type}; |
110 |
+ |
} |
111 |
|
} |
112 |
|
|
113 |
|
sub currentbase { |
116 |
|
my $rv; |
117 |
|
|
118 |
|
if ( exists $self->{basestack}{$type} ) { |
119 |
< |
$rv=$self->{basestack}{$type}[$#$self->{basestack}{$type}]; |
119 |
> |
$rv=${$self->{basestack}{$type}}[$#{$self->{basestack}{$type}}]; |
120 |
|
} |
121 |
|
else { |
122 |
|
$rv=$self->{dummybase}; |
141 |
|
$self->checktype($type); |
142 |
|
|
143 |
|
# instantiate only if it dosnt already exist; |
144 |
< |
(exists $self->{urlobjs}{$type})?$self->{urlobjs}{$type} |
145 |
< |
:$self->{urlobjs}{$type}=$self->{urlmodules}{$type}->new(); |
144 |
> |
if ( exists $self->{'urlobjs'}{$type} ) { |
145 |
> |
$self->{'urlobjs'}{$type}; |
146 |
> |
} |
147 |
> |
else { |
148 |
> |
$self->{'urlobjs'}{$type}=$self->{urlmodules}{$type}->new(); |
149 |
> |
} |
150 |
|
} |