1 |
williamc |
1.2 |
#
|
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[,DocVersionTag] : A new SimpleURLDoc object. You can also
|
12 |
|
|
# specify an alternative doc version tag
|
13 |
|
|
# addbasetags(parse) : Add Base Tags to the given parse
|
14 |
|
|
# urlget(urlstring[,location]) : get the given url - using the cache.
|
15 |
|
|
# Returns (url, filename)
|
16 |
|
|
# urldownload(urlstring[,location]) : get the given url ignoring any cached
|
17 |
|
|
# version. Returns (url, filename)
|
18 |
|
|
# expandurl(urlstring) : return a URLclass object of the given url expanded
|
19 |
|
|
# according to the base settings
|
20 |
|
|
# cache([cache]) : get/set the current URL cache
|
21 |
|
|
# doctype() : return the (type,version) of the document
|
22 |
|
|
# as specified by the DocVersionTag
|
23 |
|
|
|
24 |
|
|
package ActiveDoc::SimpleURLDoc;
|
25 |
|
|
use ActiveDoc::SimpleDoc;
|
26 |
|
|
use URL::URLhandler;
|
27 |
|
|
require 5.001;
|
28 |
|
|
@ISA=qw(ActiveDoc::SimpleDoc);
|
29 |
|
|
|
30 |
|
|
sub new {
|
31 |
|
|
my $class=shift;
|
32 |
|
|
my $self={};
|
33 |
|
|
bless $self, $class;
|
34 |
|
|
$self->cache(shift);
|
35 |
|
|
$self->_initdoc("doc",@_);
|
36 |
|
|
return $self;
|
37 |
|
|
}
|
38 |
|
|
|
39 |
|
|
sub addbasetags {
|
40 |
|
|
my $self=shift;
|
41 |
|
|
my $parse=shift;
|
42 |
|
|
|
43 |
|
|
$self->addtag($parse,"base", \&Base_start, $self,
|
44 |
|
|
"", $self,
|
45 |
|
|
\&Base_end,$self);
|
46 |
|
|
}
|
47 |
|
|
|
48 |
|
|
sub cache {
|
49 |
|
|
my $self=shift;
|
50 |
|
|
if ( @_ ) {
|
51 |
|
|
$self->{cache}=shift;
|
52 |
|
|
$self->{urlhandler}=URL::URLhandler->new($self->{cache});
|
53 |
|
|
}
|
54 |
|
|
return $self->{cache};
|
55 |
|
|
}
|
56 |
|
|
|
57 |
|
|
sub expandurl {
|
58 |
|
|
my $self=shift;
|
59 |
|
|
my $urlstring=shift;
|
60 |
|
|
|
61 |
|
|
return $self->{urlhandler}->expandurl($urlstring);
|
62 |
|
|
}
|
63 |
|
|
|
64 |
|
|
sub urldownload {
|
65 |
|
|
my $self=shift;
|
66 |
|
|
my $urlstring=shift;
|
67 |
|
|
|
68 |
|
|
($fullurl,$filename)=$self->{urlhandler}->download($urlstring, @_);
|
69 |
|
|
if ( ( ! defined $filename ) || ( $filename eq "" ) ) {
|
70 |
|
|
$self->parseerror("Failed to get $fullurl");
|
71 |
|
|
}
|
72 |
|
|
return ($fullurl,$filename);
|
73 |
|
|
}
|
74 |
|
|
|
75 |
|
|
sub urlget {
|
76 |
|
|
my $self=shift;
|
77 |
|
|
my $urlstring=shift;
|
78 |
|
|
|
79 |
|
|
($fullurl,$filename)=$self->{urlhandler}->get($urlstring, @_);
|
80 |
sashby |
1.5 |
|
81 |
williamc |
1.2 |
if ( ( ! defined $filename ) || ( $filename eq "" ) ) {
|
82 |
|
|
$self->parseerror("Failed to get $fullurl");
|
83 |
|
|
}
|
84 |
|
|
return ($fullurl,$filename);
|
85 |
|
|
}
|
86 |
|
|
|
87 |
|
|
# ------------------------ Support Routines ---------------------------
|
88 |
|
|
|
89 |
|
|
# ------------------------ Tag Routines -------------------------------
|
90 |
|
|
|
91 |
|
|
sub Base_start {
|
92 |
|
|
my $self=shift;
|
93 |
|
|
my $name=shift;
|
94 |
|
|
my $hashref=shift;
|
95 |
|
|
|
96 |
|
|
$self->checktag($name, $hashref, "url");
|
97 |
|
|
my $url=$self->{urlhandler}->setbase($$hashref{'url'});
|
98 |
sashby |
1.4 |
# Add store for url of the file currently being parsed. This info can
|
99 |
|
|
# then be extracted in Requirements objects
|
100 |
|
|
$self->{configurl}=$url;
|
101 |
williamc |
1.2 |
push @{$self->{basestack}}, $url->type();
|
102 |
|
|
}
|
103 |
|
|
|
104 |
|
|
sub Base_end {
|
105 |
|
|
my $self=shift;
|
106 |
|
|
if ( $#{$self->{basestack}} >= 0 ) {
|
107 |
|
|
my $type=pop @{$self->{basestack}};
|
108 |
|
|
$self->{urlhandler}->unsetbase($type);
|
109 |
|
|
}
|
110 |
|
|
else {
|
111 |
|
|
$self->parseerror("Unmatched <$name>");
|
112 |
|
|
}
|
113 |
|
|
}
|