ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/ActiveDoc/SimpleURLDoc.pm
Revision: 1.1.2.6
Committed: Mon Aug 21 15:19:50 2000 UTC (24 years, 8 months ago) by williamc
Content type: text/plain
Branch: HPWbranch
CVS Tags: BuildSystemProto1, V0_18_0, V0_18_0model, V0_17_1, V0_18_0alpha, V0_17_0, V0_16_4, V0_16_3, V0_16_2, V0_16_1, V0_16_0, V0_15_1, V0_15_0, V0_15_0beta
Branch point for: V0_17branch, V0_16branch, V0_15branch
Changes since 1.1.2.5: +15 -13 lines
Log Message:
Move to inheritance model for error handling :(

File Contents

# User Rev Content
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 williamc 1.1.2.4 # new(URLcache[,DocVersionTag] : A new SimpleURLDoc object. You can also
12     # specify an alternative doc version tag
13 williamc 1.1.2.1 # addbasetags(parse) : Add Base Tags to the given parse
14 williamc 1.1.2.5 # 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 williamc 1.1.2.3 # expandurl(urlstring) : return a URLclass object of the given url expanded
19     # according to the base settings
20 williamc 1.1.2.2 # cache([cache]) : get/set the current URL cache
21 williamc 1.1.2.4 # doctype() : return the (type,version) of the document
22     # as specified by the DocVersionTag
23 williamc 1.1.2.1
24     package ActiveDoc::SimpleURLDoc;
25     use ActiveDoc::SimpleDoc;
26     use URL::URLhandler;
27     require 5.001;
28 williamc 1.1.2.6 @ISA=qw(ActiveDoc::SimpleDoc);
29 williamc 1.1.2.1
30     sub new {
31     my $class=shift;
32     my $self={};
33     bless $self, $class;
34 williamc 1.1.2.2 $self->cache(shift);
35 williamc 1.1.2.6 $self->_initdoc("doc",@_);
36     #$self->{switch}=ActiveDoc::SimpleDoc->new(@_);
37 williamc 1.1.2.1 return $self;
38     }
39    
40     sub addbasetags {
41     my $self=shift;
42     my $parse=shift;
43    
44 williamc 1.1.2.6 $self->addtag($parse,"base", \&Base_start, $self,
45 williamc 1.1.2.1 "", $self,
46     \&Base_end,$self);
47     }
48    
49 williamc 1.1.2.2 sub cache {
50     my $self=shift;
51     if ( @_ ) {
52     $self->{cache}=shift;
53     $self->{urlhandler}=URL::URLhandler->new($self->{cache});
54     }
55     return $self->{cache};
56 williamc 1.1.2.3 }
57    
58     sub expandurl {
59     my $self=shift;
60     my $urlstring=shift;
61    
62     return $self->{urlhandler}->expandurl($urlstring);
63 williamc 1.1.2.5 }
64    
65     sub urldownload {
66     my $self=shift;
67     my $urlstring=shift;
68    
69     ($fullurl,$filename)=$self->{urlhandler}->download($urlstring, @_);
70     if ( ( ! defined $filename ) || ( $filename eq "" ) ) {
71 williamc 1.1.2.6 $self->parseerror("Failed to get $fullurl");
72 williamc 1.1.2.5 }
73     return ($fullurl,$filename);
74 williamc 1.1.2.2 }
75    
76 williamc 1.1.2.1 sub urlget {
77     my $self=shift;
78     my $urlstring=shift;
79 williamc 1.1.2.2
80     ($fullurl,$filename)=$self->{urlhandler}->get($urlstring, @_);
81 williamc 1.1.2.1 if ( ( ! defined $filename ) || ( $filename eq "" ) ) {
82 williamc 1.1.2.6 $self->parseerror("Failed to get $fullurl");
83 williamc 1.1.2.1 }
84     return ($fullurl,$filename);
85     }
86    
87 williamc 1.1.2.6 #sub AUTOLOAD {
88     # my $self=shift;
89     #
90 williamc 1.1.2.1 # dont propogate destroy methods
91 williamc 1.1.2.6 # return if $AUTOLOAD=~/::DESTROY/;
92 williamc 1.1.2.1
93     # remove this package name
94 williamc 1.1.2.6 # ($name=$AUTOLOAD)=~s/ActiveDoc::SimpleURLDoc:://;
95 williamc 1.1.2.1
96     # pass the message to SimpleDoc
97 williamc 1.1.2.6 # $self->{switch}->$name(@_);
98     #}
99 williamc 1.1.2.1
100     # ------------------------ Support Routines ---------------------------
101    
102     # ------------------------ Tag Routines -------------------------------
103    
104     sub Base_start {
105     my $self=shift;
106     my $name=shift;
107     my $hashref=shift;
108    
109 williamc 1.1.2.6 $self->checktag($name, $hashref, "url");
110 williamc 1.1.2.1 my $url=$self->{urlhandler}->setbase($$hashref{'url'});
111     push @{$self->{basestack}}, $url->type();
112     }
113    
114     sub Base_end {
115     my $self=shift;
116     if ( $#{$self->{basestack}} >= 0 ) {
117     my $type=pop @{$self->{basestack}};
118     $self->{urlhandler}->unsetbase($type);
119     }
120     else {
121 williamc 1.1.2.6 $self->parseerror("Unmatched <$name>");
122 williamc 1.1.2.1 }
123     }