1 |
williamc |
1.1.2.1 |
#
|
2 |
|
|
# SimpleURLDoc.pm. - Extends SimpleDoc with URL download functionality
|
3 |
|
|
#
|
4 |
|
|
# Originally Written by Christopher Williams
|
5 |
|
|
#
|
6 |
|
|
# Description
|
7 |
|
|
# -----------
|
8 |
|
|
#
|
9 |
|
|
# Interface
|
10 |
|
|
# ---------
|
11 |
|
|
# new(URLcache) : A new SimpleURLDoc object
|
12 |
|
|
# addbasetags(parse) : Add Base Tags to the given parse
|
13 |
|
|
# urlget(urlstring) : get the given url. Returns (url, filename)
|
14 |
|
|
|
15 |
|
|
package ActiveDoc::SimpleURLDoc;
|
16 |
|
|
use ActiveDoc::SimpleDoc;
|
17 |
|
|
use URL::URLhandler;
|
18 |
|
|
require 5.001;
|
19 |
|
|
|
20 |
|
|
sub new {
|
21 |
|
|
my $class=shift;
|
22 |
|
|
my $self={};
|
23 |
|
|
bless $self, $class;
|
24 |
|
|
$self->{cache}=shift;
|
25 |
|
|
$self->{urlhandler}=URL::URLhandler->new($self->{cache});
|
26 |
|
|
$self->{switch}=ActiveDoc::SimpleDoc->new();
|
27 |
|
|
return $self;
|
28 |
|
|
}
|
29 |
|
|
|
30 |
|
|
sub addbasetags {
|
31 |
|
|
my $self=shift;
|
32 |
|
|
my $parse=shift;
|
33 |
|
|
|
34 |
|
|
$self->{switch}->addtag($parse,"base", \&Base_start, $self,
|
35 |
|
|
"", $self,
|
36 |
|
|
\&Base_end,$self);
|
37 |
|
|
}
|
38 |
|
|
|
39 |
|
|
sub urlget {
|
40 |
|
|
my $self=shift;
|
41 |
|
|
my $urlstring=shift;
|
42 |
|
|
($fullurl,$filename)=$self->{urlhandler}->get($urlstring);
|
43 |
|
|
if ( ( ! defined $filename ) || ( $filename eq "" ) ) {
|
44 |
|
|
$self->{switch}->parseerror("Failed to get $fullurl");
|
45 |
|
|
}
|
46 |
|
|
return ($fullurl,$filename);
|
47 |
|
|
}
|
48 |
|
|
|
49 |
|
|
sub AUTOLOAD {
|
50 |
|
|
my $self=shift;
|
51 |
|
|
|
52 |
|
|
# dont propogate destroy methods
|
53 |
|
|
return if $AUTOLOAD=~/::DESTROY/;
|
54 |
|
|
|
55 |
|
|
# remove this package name
|
56 |
|
|
($name=$AUTOLOAD)=~s/ActiveDoc::SimpleURLDoc:://;
|
57 |
|
|
|
58 |
|
|
# pass the message to SimpleDoc
|
59 |
|
|
$self->{switch}->$name(@_);
|
60 |
|
|
}
|
61 |
|
|
|
62 |
|
|
# ------------------------ Support Routines ---------------------------
|
63 |
|
|
|
64 |
|
|
# ------------------------ Tag Routines -------------------------------
|
65 |
|
|
|
66 |
|
|
sub Base_start {
|
67 |
|
|
my $self=shift;
|
68 |
|
|
my $name=shift;
|
69 |
|
|
my $hashref=shift;
|
70 |
|
|
|
71 |
|
|
$self->{switch}->checktag($name, $hashref, "url");
|
72 |
|
|
my $url=$self->{urlhandler}->setbase($$hashref{'url'});
|
73 |
|
|
push @{$self->{basestack}}, $url->type();
|
74 |
|
|
}
|
75 |
|
|
|
76 |
|
|
sub Base_end {
|
77 |
|
|
my $self=shift;
|
78 |
|
|
if ( $#{$self->{basestack}} >= 0 ) {
|
79 |
|
|
my $type=pop @{$self->{basestack}};
|
80 |
|
|
$self->{urlhandler}->unsetbase($type);
|
81 |
|
|
}
|
82 |
|
|
else {
|
83 |
|
|
$self->{switch}->parseerror("Unmatched <$name>");
|
84 |
|
|
}
|
85 |
|
|
}
|
86 |
|
|
|