ViewVC Help
View File | Revision Log | Show Annotations | Root Listing
root/cvsroot/COMP/SCRAM/src/ActiveDoc/ActiveDoc.pm
(Generate patch)

Comparing COMP/SCRAM/src/ActiveDoc/ActiveDoc.pm (file contents):
Revision 1.20 by williamc, Fri Feb 11 14:55:22 2000 UTC vs.
Revision 1.24 by williamc, Wed Mar 1 11:47:39 2000 UTC

# Line 10 | Line 10
10   # new(ActiveConfig[,options])           : A new ActiveDoc object
11   # url()         : Return/set the docs url - essential
12   # file()        : Return the local filename of document
13 + # ProcessFile() : Return the filename of PreProcessed document
14   #
15   # parse(parselabel): Parse the document file for the given parse level
16 + # parent()         : return the object ref of the calling parent
17   # newparse(parselabel) : Create a new parse type
18   # addtag(parselabel,tagname,start,obj,text,obj,end,obj)
19   #                               : Add tags to the parse given by label
# Line 19 | Line 21
21   #                                       hashref from a tag call
22   # includeparse(local_parsename, objparsename, activedoc) : copy the parse from
23   #                                                       one object to another
24 + # currentparser() : return the current parser object
25   # currentparsename([name]) : get/set current parse name
26   # getfile(url)  : get a processedfile object given a url
27   # activatedoc(url) : Return the object ref for a doc described by the given url
# Line 39 | Line 42
42   # parseerror(string)  : Report an error during parsing a file
43   # line()              : Return the current line number of the document
44   #                       and the ProcessedFileObj it is in
45 + #
46 + # -- support for inheriting classes
47 + # _saveactivedoc(filehandle)
48 + # _restoreactivedoc(filehandle)
49  
50   package ActiveDoc::ActiveDoc;
51   require 5.004;
# Line 64 | Line 71 | sub new {
71             # --- is there a starter document?
72             my $basedoc=$self->config()->basedoc();
73             if ( defined $basedoc ) {
67             $self->verbose("Initialising from $basedoc");
74               $self->copydocquery($basedoc);
75 +             $self->verbose("Initialising from $basedoc");
76             }
77             else {
78               $self->error("ActiveDoc Error : No base doc found");
79             }
80          }
81 +        $self->verbose("New ActiveDoc (".ref($self).") Created");
82          $self->_init2();
83   }
84  
# Line 93 | Line 101 | sub verbose {
101  
102          if ( $self->option('verbose_all') ||
103                          $self->option('verbose_'.ref($self)) ) {
104 <          print ">".ref($self)." : ".$string."\n";
104 >          print ">".ref($self)."($self) : \n->".$string."\n";
105          }
106   }
107  
# Line 102 | Line 110 | sub parse {
110          my $self=shift;
111          $parselabel=shift;
112  
113 <        my $file=$self->file();
113 >        my $file=$self->ProcessFile();
114          if ( $file ) {
115            if ( exists $self->{parsers}{$parselabel} ) {
116 +            $self->verbose("Parsing $parselabel in file $file");
117              $self->{currentparsename}=$parselabel;
118              $self->{currentparser}=$self->{parsers}{$parselabel};
119              $self->{parsers}{$parselabel}->parse($file,@_);
120              delete $self->{currentparser};
121              $self->{currentparsename}="";
122 +            $self->verbose("Parse $parselabel Complete");
123            }
124          }
125          else {
126 <          print "Cannot parse - file not known\n";
126 >          $self->error("Cannot parse $parselabel - file not known");
127          }
128   }
129  
130   sub currentparsename {
131          my $self=shift;
132          @_?$self->{currentparsename}=shift
133 <          :$self->{currentparsename};
133 >          :(defined $self->{currentparsename}?$self->{currentparsename}:"");
134 > }
135 >
136 > sub currentparser {
137 >        my $self=shift;
138 >        return $self->{currentparser};
139   }
140  
141 +
142   sub newparse {
143          my $self=shift;
144          my $parselabel=shift;
# Line 181 | Line 197 | sub addurltags {
197   sub url {
198          my $self=shift;
199          # get file & preprocess
200 <        if ( @_  ) {$self->{File}=$self->getfile(shift)}
200 >        if ( @_  ) {
201 >                $self->{File}=$self->getfile(shift);
202 >                $self->verbose("url downloaded to $self->{File}");
203 >        }
204          $self->{File}->url();
205   }
206  
# Line 213 | Line 232 | sub config {
232  
233   sub basequery {
234          my $self=shift;
235 <        @_ ? $self->{Query}=shift
236 <           : $self->{Query};
218 <        return $self->{Query};
235 >        @_?$self->{Query}=shift
236 >           :$self->{Query};
237   }
238  
239   sub option {
# Line 252 | Line 270 | sub askuser {
270          return $self->userinterface()->askuser(@_);
271   }
272  
273 < sub getfile() {
273 > sub getfile {
274          my $self=shift;
275          my $origurl=shift;
276  
277          my $fileref;
278          my ($url, $file);
279 <        if ( defined $self->option('url_update') ) {
280 <           $self->verbose("Forced download of $origurl");
281 <           ($url, $file)=$self->{urlhandler}->download($origurl);
279 >        if ( (defined ($it=$self->option('url_update'))) &&
280 >                ( $it eq "1" || $origurl=~/^$it/ )) {
281 >             $self->verbose("Forced download of $origurl");
282 >             ($url, $file)=$self->{urlhandler}->download($origurl);
283          }
284          else {
285 +           $self->verbose("Attempting to get $origurl");
286             ($url, $file)=$self->{urlhandler}->get($origurl);
287          }
288          # do we already have an appropriate object?
# Line 277 | Line 297 | sub getfile() {
297             $self->parseerror("Unable to get $origurl");
298           }
299           #-- set up a new preprocess file
300 <         print "Making a new file $url----\n";
300 >         $self->verbose("Making a new preprocessed file $url");
301           $fileref=ActiveDoc::PreProcessedFile->new($self->config());
302           $fileref->url($url);
303           $fileref->update();
# Line 313 | Line 333 | sub activatedoc {
333          my $newobj=$tempdoc->{docobject}->new($self->config());
334          undef $tempdoc;
335          $newobj->url($url);
336 +        $newobj->parent($self);
337          $newobj->_initparse();
338          return $newobj;
339   }
340  
341 + sub parent {
342 +        my $self=shift;
343 +
344 +        @_?$self->{parent}=shift
345 +          :$self->{parent};
346 + }
347 +
348   sub _initparse {
349          my $self=shift;
350  
# Line 379 | Line 407 | sub file {
407          $self->{File}->file();
408   }
409  
410 + sub ProcessFile {
411 +        my $self=shift;
412 +
413 +        return $self->{File}->ProcessedFile();
414 + }
415 +
416   # --------------- Initialisation Methods ---------------------------
417  
418   sub init {
# Line 434 | Line 468 | sub userinterface {
468          @_?$self->{userinterface}=shift
469            :$self->{userinterface}
470   }
471 +
472 + sub _saveactivedoc {
473 +        my $self=shift;
474 +        my $fh=shift;
475 +        print "Storing $self\n";
476 +        print $fh $self->url()."\n";
477 + }
478 +
479 + sub _restoreactivedoc {
480 +        my $self=shift;
481 +        my $fh=shift;
482 +
483 +        my $url=<$fh>;
484 +        chomp $url;
485 +        $self->url($url);
486 + }

Diff Legend

Removed lines
+ Added lines
< Changed lines
> Changed lines