dougm       01/09/06 09:40:11

  Modified:    lib/Apache ParseSource.pm
  Log:
  only generate table .pm's if content has changed
  Submitted by:  Stas Bekman <[EMAIL PROTECTED]>
  Reviewed by:  dougm
  
  Revision  Changes    Path
  1.26      +26 -4     modperl-2.0/lib/Apache/ParseSource.pm
  
  Index: ParseSource.pm
  ===================================================================
  RCS file: /home/cvs/modperl-2.0/lib/Apache/ParseSource.pm,v
  retrieving revision 1.25
  retrieving revision 1.26
  diff -u -r1.25 -r1.26
  --- ParseSource.pm    2001/09/06 05:26:52     1.25
  +++ ParseSource.pm    2001/09/06 16:40:11     1.26
  @@ -410,8 +410,6 @@
           $file = "$tdir/$subdir/$file";
       }
   
  -    open my $pm, '>', $file or die "open $file: $!";
  -
       # sort the hashes (including nested ones) for a consistent dump
       canonsort(\$data);
   
  @@ -422,7 +420,7 @@
       my $version = $self->VERSION;
       my $date = scalar localtime;
   
  -    print $pm <<EOF;
  +    my $new_content = << "EOF";
   package $name;
   
   # !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  @@ -435,7 +433,31 @@
   
   1;
   EOF
  -    close $pm;
  +
  +    my $old_content = '';
  +    if (-e $file) {
  +        open my $pm, '<', $file or die "open $file: $!";
  +        local $/ = undef; # slurp the file
  +        $old_content = <$pm>;
  +        close $pm;
  +    }
  +
  +    my $overwrite = 1;
  +    if ($old_content) {
  +        # strip the date line, which will never be the same before
  +        # comparing
  +        my $table_header = qr{^\#\s!.*};
  +        (my $old = $old_content) =~ s/$table_header//mg;
  +        (my $new = $new_content) =~ s/$table_header//mg;
  +        $overwrite = 0 if $old eq $new;
  +    }
  +
  +    if ($overwrite) {
  +        open my $pm, '>', $file or die "open $file: $!";
  +        print $pm $new_content;
  +        close $pm;
  +    }
  +
   }
   
   # canonsort(\$data);
  
  
  

Reply via email to