perl-docs-cvs mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From s...@apache.org
Subject cvs commit: modperl-docs/lib/DocSet Cache.pm Config.pm DocSet.pm
Date Sun, 21 Apr 2002 15:36:53 GMT
stas        02/04/21 08:36:53

  Modified:    lib/DocSet Cache.pm Config.pm DocSet.pm
  Log:
  - force rebuild of the docset if the cache file is missing, even if
    the target files aren't older than the source files. (this is the
    case where for some reason the cache file was deleted)
  
  - set the 'stitle' attr to 'title' for 'links' type, if missing.
  
  - handle the case where docsets, links or chapters get removed
    from docset. The cache uses only active items (listed in config.cfg)
    changed the way the ordered list of items is constructed
  
  - fix the bug where a change in the main config.cfg won't indicate a
    modified docset and therefore a rebuild.
  
  Revision  Changes    Path
  1.4       +40 -10    modperl-docs/lib/DocSet/Cache.pm
  
  Index: Cache.pm
  ===================================================================
  RCS file: /home/cvs/modperl-docs/lib/DocSet/Cache.pm,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- Cache.pm	5 Feb 2002 10:27:19 -0000	1.3
  +++ Cache.pm	21 Apr 2002 15:36:53 -0000	1.4
  @@ -11,7 +11,7 @@
   my %attrs = map {$_ => 1} qw(toc meta order);
   
   sub new {
  -    my($class, $path) = @_;
  +    my($class, $path, $update) = @_;
   
       die "no cache path specified" unless defined $path;
   
  @@ -21,6 +21,20 @@
                        }, ref($class)||$class;
       $self->read();
   
  +    if ($update) {
  +        # we will reconstruct the ids order to make sure to reflect the
  +        # changes in added and removed items (and those who have changed
  +        # their order)
  +        $self->{cache}{_ordered_ids} = [];
  +
  +        # XXX: because we rewrite _order_ids on each invocation, we have to sync
  +        # the cache to the disk, even if it didn't really change. In the
  +        # future we may do somechecksum check and write the file only if
  +        # the checksum has changed, so at this moment the dirty mechanism
  +        # does nothing
  +        $self->{dirty} = 1;
  +    }
  +
       return $self;
   }
   
  @@ -51,6 +65,12 @@
       }
   }
   
  +sub add {
  +    my($self, $id) = @_;
  +    push @{ $self->{cache}{_ordered_ids} }, $id;
  +    $self->{cache}{$id}{seq} = $#{ $self->{cache}{_ordered_ids} };
  +}
  +
   # set a cache entry (overrides a prev entry if any exists)
   sub set {
       my($self, $id, $attr, $data, $hidden) = @_;
  @@ -59,11 +79,12 @@
       croak "must specify an attribute" unless defined $attr;
       croak "unknown attribute $attr"   unless exists $attrs{$attr};
   
  -    # remember the addition order (unless it's an update)
  -    unless (exists $self->{cache}{$id}) {
  -        push @{ $self->{cache}{_ordered_ids} }, $id;
  -        $self->{cache}{$id}{seq} = $#{ $self->{cache}{_ordered_ids} };
  -    }
  +#    # remember the addition order (unless it's an update)
  +#    unless (exists $self->{cache}{$id}) {
  +#        push @{ $self->{cache}{_ordered_ids} }, $id;
  +#        $self->{cache}{$id}{seq} = $#{ $self->{cache}{_ordered_ids} };
  +#    }
  +
       $self->{cache}{$id}{$attr} = $data;
       $self->{cache}{$id}{_hidden} = $hidden;
       $self->{dirty} = 1;
  @@ -144,7 +165,7 @@
       my($self, $seq) = @_;
   
       croak "must specify a seq number"  unless defined $seq;
  -    if ($self->{cache}{_ordered_ids}) {
  +    if ($self->{cache}{_ordered_ids} && defined $self->{cache}{_ordered_ids}->[$seq])
{
           return $self->{cache}{_ordered_ids}->[$seq];
       }
       else {
  @@ -244,15 +265,24 @@
   
     use DocSet::Cache ();
   
  -  my $cache = DocSet::Cache->new($cache_path);
  -  $cache->read;
  +  my $cache = DocSet::Cache->new($cache_path, 1);
  +
  +  # $cache->read; # read by new() already
     $cache->write;
   
  +  # add a cache item to the ordered list
  +  $cache->add($id);
  +
  +  # set/unset cached item's attributes
     $cache->set($id, $attr, $data);
  +  $cache->unset($id, $attr)
  +
  +  # get cached item's attributes
     my $data = $cache->get($id, $attr);
     print "$id is cached" if $cache->is_cached($id);
  +
  +  # invalidate cache (deletes all items)
     $cache->invalidate();
  -  $cache->unset($id, $attr)
   
     my $seq = $cache->id2seq($id);
     my $id = $cache->seq2id($seq);
  
  
  
  1.7       +25 -3     modperl-docs/lib/DocSet/Config.pm
  
  Index: Config.pm
  ===================================================================
  RCS file: /home/cvs/modperl-docs/lib/DocSet/Config.pm,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Config.pm	21 Apr 2002 07:25:18 -0000	1.6
  +++ Config.pm	21 Apr 2002 15:36:53 -0000	1.7
  @@ -118,8 +118,8 @@
   
       # - make sure that at least title or stitle were specified
       # - alias one to another if only one was specified
  -    $self->{title}  ||= $self->{stitle};
  -    $self->{stitle} ||= $self->{title};
  +    $self->{title}  = $self->{stitle} unless exists $self->{title};
  +    $self->{stitle} = $self->{title}  unless exists $self->{stitle};
       die "Either 'title' or 'stitle' must appear in $config_file"
           unless $self->{title};
   
  @@ -127,7 +127,8 @@
       # so this value is relevant only for the real top parent node
       $self->{dir}{abs_doc_root} = '.';
   
  -    $self->{dir}{path_from_base} ||= '';
  +    $self->{dir}{path_from_base} = '' 
  +        unless exists $self->{dir}{path_from_base};
   
       $self->{dir}{src_root} = File::Basename::dirname $config_file;
   
  @@ -209,6 +210,27 @@
       }
       return $self->{modified};
   
  +}
  +
  +# similar to DocSet::RunTime::get_opts('rebuild_all');
  +# but can be set for the scope of a single docset (which affects only
  +# the immediate children)
  +sub rebuild {
  +    my $self = shift;
  +    if (@_) {
  +        my $status = shift;
  +
  +        # protect from 'rebuild' status reset (once it's set to any
  +        #value it cannot be reset to 0), must be a mistake. If we
  +        # don't check this, it's possible that in one place the object
  +        # is marked to rebuild the docset, but somewhere later a logic mistake
  +        # resets this value to 0, (non-dirty).
  +        if (exists $self->{rebuild} && !$status) {
  +            Carp::croak("Cannot reset the 'rebuild' status");
  +        }
  +        $self->{rebuild} = $status;
  +    }
  +    return $self->{rebuild};
   }
   
   #
  
  
  
  1.9       +39 -17    modperl-docs/lib/DocSet/DocSet.pm
  
  Index: DocSet.pm
  ===================================================================
  RCS file: /home/cvs/modperl-docs/lib/DocSet/DocSet.pm,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DocSet.pm	21 Apr 2002 07:25:18 -0000	1.8
  +++ DocSet.pm	21 Apr 2002 15:36:53 -0000	1.9
  @@ -33,18 +33,19 @@
       }
   
       # we assume that the docset was not modified since the last run.
  -    # if at least one source doc was modified, the docset is considered
  -    # modified as well and should be rebuild. It's the responsibility
  -    # of the modified object to make its parent docset as modified.
  +    # if at least one source doc/config file was modified, the docset
  +    # is considered modified as well and should be rebuild. It's the
  +    # responsibility of the modified object to make its parent docset
  +    # as modified.
       $self->modified(0);
   
  -    # currently there are 4 reasons why the docset is considered
  +    # currently there are 5 reasons why the docset is considered
       # 'modified', if at least one of these is 'modified':
       # 1. the included docset
       # 2. the included chapter
       # 3. the included 'copy as-is' files
       # 4. config.cfg is newer than corresponding index.html
  -    # 
  +    # 5. the cache file is missing
   
   }
   
  @@ -56,7 +57,19 @@
       # each output mode need its own cache, because of the destination
       # links which are different
       my $mode = $self->get('tmpl_mode');
  -    my $cache = DocSet::Cache->new("$src_root/cache.$mode.dat");
  +
  +    my $cache_file = "$src_root/cache.$mode.dat";
  +    # rebuild of the docset is forced if the cache file doesn't exist
  +    unless (-e $cache_file && -r _) {
  +        $self->modified(1);
  +        $self->rebuild(1);
  +    }
  +
  +    # rebuild forces all objects to be rebuilt
  +    $self->rebuild(1) if DocSet::RunTime::get_opts('rebuild_all');
  +
  +    # create the new cache object for updates 
  +    my $cache = DocSet::Cache->new($cache_file, 1);
       $self->cache($cache); # store away
   
       # cleanup the cache or rebuild
  @@ -137,6 +150,15 @@
   
       $cache->node_groups($self->node_groups);
   
  +    # compare whether the config file is newer than the index.html
  +    my $dst_root = $self->get_dir('dst_root');
  +    my $config_file = $self->{config_file};
  +
  +    my $dst_index = "$dst_root/index.html";
  +    my($should_update, $reason) = 
  +        $self->should_update($config_file, $dst_index);
  +    $self->modified(1) if $should_update;
  +
       # sync the cache
       $cache->write;
   
  @@ -158,12 +180,13 @@
       my($self, $src_rel_dir, $hidden) = @_;
   
       my $src_root = $self->get_dir('src_root');
  -    my $cfg_file =  "$src_root/$src_rel_dir/config.cfg";
  -    my $docset = $self->new($cfg_file, $self, $src_rel_dir);
  +    my $config_file =  "$src_root/$src_rel_dir/config.cfg";
  +    my $docset = $self->new($config_file, $self, $src_rel_dir);
       $docset->scan;
   
       # cache the children meta data
       my $id = $docset->get('id');
  +    $self->cache->add($id);
       my $meta = {
                   stitle   => $docset->get('stitle'),
                   title    => $docset->get('title'),
  @@ -172,23 +195,20 @@
                  };
       $self->cache->set($id, 'meta', $meta, $hidden);
   
  -    # compare whether the config file is newer than the index.html
  -    my $dst_root = $self->get_dir('dst_root');
  -    my $dst_index = "$dst_root/$src_rel_dir/index.html";
  -    my($should_update, $reason) = 
  -        $self->should_update($cfg_file, $dst_index);
  -    $docset->modified(1) if $should_update;
  -
       note "\n"; # mark the end of scan
   
       return $docset;
   }
   
   
  +
   sub link_scan_n_cache {
       my($self, $link, $hidden) = @_;
       my %meta = %$link; # make a copy
       my $id = delete $meta{id};
  +    $meta{title} = $meta{stitle} unless exists $meta{title};
  +    $meta{stitle} = $meta{title} unless exists $meta{stitle};
  +    $self->cache->add($id);
       $self->cache->set($id, 'meta', \%meta, $hidden);
   }
   
  @@ -196,6 +216,9 @@
   sub chapter_scan_n_cache {
       my($self, $src_file, $hidden) = @_;
   
  +    my $id = $src_file;
  +    $self->cache->add($id);
  +
       my $trg_ext = $self->trg_ext();
   
       my $src_root      = $self->get_dir('src_root');
  @@ -252,7 +275,6 @@
       $chapter->scan();
   
       # cache the chapter's meta and toc data
  -    my $id = $src_file;
       $self->cache->set($id, 'meta', $chapter->meta, $hidden);
       $self->cache->set($id, 'toc',  $chapter->toc,  $hidden);
   
  @@ -364,7 +386,7 @@
           (-e $dst_path and -M $dst_path < -M $src_path) ? 1 : 0;
   
       my $reason = $not_modified ? 'not modified' : 'modified';
  -    if (DocSet::RunTime::get_opts('rebuild_all')) {
  +    if ($self->rebuild()) {
           return (1, "$reason / forced");
       }
       else {
  
  
  

---------------------------------------------------------------------
To unsubscribe, e-mail: docs-cvs-unsubscribe@perl.apache.org
For additional commands, e-mail: docs-cvs-help@perl.apache.org


Mime
View raw message