This patch ensures that the autogenerated datastructures are sorted.
Note that I sort the arrays too, since the data is coming from an external
source (filesystem) so we have to ensure that this will be sorted as well.
To perform the later I rely on the internal knowledge of the
datastructures.

Now given the same source files on different systems the same
diff-wise autogenerated code will be created. This will allow more than
one person to maintain these files under cvs using the 'make source_scan'
routine.

Doug, if this patch is OK with you. Can you create a fresh version of
everything that's autogenerated and commit (or send it to me), so I will
check that it actually does what I think it should. Of course after you
apply the patch :)

Oh, yeah, you need Tie::IxHash ;)

Index: lib/Apache/ParseSource.pm
===================================================================
RCS file: /home/cvs/modperl-2.0/lib/Apache/ParseSource.pm,v
retrieving revision 1.17
diff -b -u -r1.17 ParseSource.pm
--- lib/Apache/ParseSource.pm   2001/05/03 22:23:53     1.17
+++ lib/Apache/ParseSource.pm   2001/06/28 07:24:07
@@ -2,6 +2,7 @@

 use strict;
 use Apache::Build ();
+use Tie::IxHash;
 use Config ();

 our $VERSION = '0.02';
@@ -313,7 +314,9 @@
         push @functions, $func;
     }

-    $self->{$key} = \@functions;
+    # sort the functions by the 'name' attribute to ensure a
+    # consistent output on different systems.
+    $self->{$key} = [sort { $a->{name} cmp $b->{name} } @functions];
 }

 sub get_structs {
@@ -356,7 +359,9 @@
         push @structures, $struct;
     }

-    $self->{$key} = \@structures;
+    # sort the structs by the 'type' attribute to ensure a consistent
+    # output on different systems.
+    $self->{$key} = [sort { $a->{type} cmp $b->{type} } @structures];
 }

 sub write_functions_pm {
@@ -398,6 +403,9 @@

     open my $pm, '>', $file or die "open $file: $!";

+    # sort the hashes (including nested ones) for the consistent dump
+    canonized($data);
+
     my $dump = Data::Dumper->new([$data],
                                  [$name])->Dump;

@@ -419,6 +427,27 @@
 1;
 EOF
     close $pm;
+}
+
+
+# canonized($data);
+# sort nested hashes in the datastructure.
+# the datastructure itself gets modified
+sub canonized{
+    my $ref = ref $_[0];
+    return unless $ref;
+    if ($ref eq 'ARRAY') {
+        canonized($_) for @{$_[0]};
+    }
+    elsif ($ref eq 'HASH') {
+        canonized($_[0]->{$_}) for keys %{$_[0]};
+        tie my %hash, 'Tie::IxHash';
+        $hash{$_} = $_[0]->{$_} for sort keys %{$_[0]};
+        $_[0] = \%hash;
+    }
+    else {
+        # nothing
+    }
 }

 1;



_____________________________________________________________________
Stas Bekman              JAm_pH     --   Just Another mod_perl Hacker
http://stason.org/       mod_perl Guide  http://perl.apache.org/guide
mailto:[EMAIL PROTECTED]   http://apachetoday.com http://eXtropia.com/
http://singlesheaven.com http://perl.apache.org http://perlmonth.com/



---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to