You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl-cvs@perl.apache.org by st...@apache.org on 2003/04/09 08:23:38 UTC

cvs commit: modperl-docs/lib/DocSet Cache.pm Config.pm DocSet.pm

stas        2003/04/08 23:23:38

  Modified:    lib      DocSet.pm
               lib/DocSet Cache.pm Config.pm DocSet.pm
  Log:
  sync with DocSet-blead:
  
  - if the cache read fails rebuild the docset as if the cache file
    didn't exist (to solve the Storable binary incompatibilities probs)
  
  - purge cache files when the rebuild is forced
  
  Revision  Changes    Path
  1.9       +1 -1      modperl-docs/lib/DocSet.pm
  
  Index: DocSet.pm
  ===================================================================
  RCS file: /home/cvs/modperl-docs/lib/DocSet.pm,v
  retrieving revision 1.8
  retrieving revision 1.9
  diff -u -r1.8 -r1.9
  --- DocSet.pm	4 Sep 2002 16:01:18 -0000	1.8
  +++ DocSet.pm	9 Apr 2003 06:23:38 -0000	1.9
  @@ -1,6 +1,6 @@
   package DocSet;
   
  -$VERSION = '0.15';
  +$VERSION = '0.16';
   
   =head1 NAME
   
  
  
  
  1.7       +42 -12    modperl-docs/lib/DocSet/Cache.pm
  
  Index: Cache.pm
  ===================================================================
  RCS file: /home/cvs/modperl-docs/lib/DocSet/Cache.pm,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -r1.6 -r1.7
  --- Cache.pm	29 Jun 2002 19:13:49 -0000	1.6
  +++ Cache.pm	9 Apr 2003 06:23:38 -0000	1.7
  @@ -10,18 +10,28 @@
   
   my %attrs = map {$_ => 1} qw(toc meta order child_cache_path);
   
  +# $update == 1 marks the cache as dirty, so it'll be always written to the disk
  +# $purge == 1 deletes the existing cache file if such exists
   sub new {
  -    my($class, $path, $update) = @_;
  +    my($class, $path, $update, $purge) = @_;
   
       die "no cache path specified" unless defined $path;
   
       my $self = bless {
  -                      path   => $path,
  -                      dirty  => 0,
  -                     }, ref($class)||$class;
  -    $self->read();
  +        path       => $path,
  +        dirty      => 0,
  +        cache      => {},
  +        read_error => '',
  +    }, ref($class)||$class;
   
  -    if ($update) {
  +    if ($purge) {
  +        $self->purge();
  +    }
  +    else {
  +        $self->read();
  +    }
  +
  +    if ($purge || 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)
  @@ -43,15 +53,39 @@
       $self->{path};
   }
   
  +# returns the read error if any
  +sub read_error {
  +    shift->{read_error};
  +}
  +
  +# check whether the cache file exists and readable
  +sub can_read {
  +    -e shift->{path} && -r _;
  +}
  +
  +sub purge {
  +    if (-e $self->{path}) {
  +        note "!!! Removing cache file $self->{path}";
  +        unlink $self->{path};
  +    }
  +}
  +
   sub read {
       my($self) = @_;
   
       if (-w $self->{path} && DocSet::RunTime::has_storable_module()) {
           note "+++ Reading cache from $self->{path}";
  -        $self->{cache} = Storable::retrieve($self->{path});
  +        eval {
  +            $self->{cache} = Storable::retrieve($self->{path});
  +        };
  +        if ($@) {
  +            # nuke the cache file
  +            note "failed to retrieve $self->{path}: $@";
  +            $self->{read_error} = "$@";
  +            $self->purge();
  +        }
       } else {
           note "+++ Initializing a new cache for $self->{path}";
  -        $self->{cache} = {};
       }
   }
   
  @@ -102,10 +136,6 @@
           return $self->{cache}{$id}{$attr};
       }
   }
  -
  -
  -
  -
   
   # check whether a cached entry exists
   sub is_cached {
  
  
  
  1.11      +0 -4      modperl-docs/lib/DocSet/Config.pm
  
  Index: Config.pm
  ===================================================================
  RCS file: /home/cvs/modperl-docs/lib/DocSet/Config.pm,v
  retrieving revision 1.10
  retrieving revision 1.11
  diff -u -r1.10 -r1.11
  --- Config.pm	19 Aug 2002 06:56:44 -0000	1.10
  +++ Config.pm	9 Apr 2003 06:23:38 -0000	1.11
  @@ -612,8 +612,6 @@
   
   =back
   
  -=back
  -
   =head1 CONFIGURATION FILE
   
   Each DocSet has its own configuration file.
  @@ -1030,8 +1028,6 @@
   HTML, so the parser will be able to extract the body. Of course these
   can be POD or other formats as well. But all is taken from these files
   are their bodies, so the title and other meta-data are ignored.
  -
  -=back
   
   =head1 AUTHORS
   
  
  
  
  1.16      +14 -14    modperl-docs/lib/DocSet/DocSet.pm
  
  Index: DocSet.pm
  ===================================================================
  RCS file: /home/cvs/modperl-docs/lib/DocSet/DocSet.pm,v
  retrieving revision 1.15
  retrieving revision 1.16
  diff -u -r1.15 -r1.16
  --- DocSet.pm	14 Nov 2002 17:45:31 -0000	1.15
  +++ DocSet.pm	9 Apr 2003 06:23:38 -0000	1.16
  @@ -56,27 +56,27 @@
       my($self) = @_;
   
       my $src_root = $self->get_dir('src_root');
  -
  +    my $purge = DocSet::RunTime::get_opts('rebuild_all') ? 1 : 0;
  +    my $update = 1; # see DocSetCache::new
       # each output mode need its own cache, because of the destination
       # links which are different
       my $mode = $self->get('tmpl_mode');
  -
       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 _) {
  +
  +    # - create the new cache object for updates
  +    # - rebuild_all forces  the existing cache's purge
  +    my $cache = DocSet::Cache->new($cache_file, $update, $purge);
  +    $self->cache($cache); # add to the docset object
  +
  +    # a complete rebuild of the docset is done when:
  +    # - we are told to do so:
  +    # - if the cache file doesn't exist
  +    # - or the we failed to retrieve an existing cache
  +    if (DocSet::RunTime::get_opts('rebuild_all') ||
  +        $cache->read_error || !$cache->can_read) {
           $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
  -    $cache->invalidate if get_opts('rebuild_all');
   
       # cache the index node meta data
       $cache->index_node(id       => $self->get('id'),
  
  
  

Re: cvs commit: modperl-docs/lib/DocSet Cache.pm Config.pm DocSet.pm

Posted by Stas Bekman <st...@stason.org>.
stas@apache.org wrote:
> stas        2003/04/08 23:23:38
> 
>   Modified:    lib      DocSet.pm
>                lib/DocSet Cache.pm Config.pm DocSet.pm
>   Log:
>   sync with DocSet-blead:
>   
>   - if the cache read fails rebuild the docset as if the cache file
>     didn't exist (to solve the Storable binary incompatibilities probs)
>   
>   - purge cache files when the rebuild is forced

Bill, if you use DocSet elsewhere please see that this change doesn't break 
anything. If not, we will test it live here.

Certainly a test suite would be cool, but I don't even want to start to think 
about it ;)

__________________________________________________________________
Stas Bekman            JAm_pH ------> Just Another mod_perl Hacker
http://stason.org/     mod_perl Guide ---> http://perl.apache.org
mailto:stas@stason.org http://use.perl.org http://apacheweek.com
http://modperlbook.org http://apache.org   http://ticketmaster.com


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