Ignore:
Timestamp:
2015-01-09T14:50:58+13:00 (9 years ago)
Author:
Jeremy Symon
Message:

Switch to an Ordered Hash to stop the XML files from being scrambled

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/package-kits/scripts/gs-servlet.pl

    r29678 r29679  
    1111use Greenstone::XML::Tidy;
    1212
    13 my $hash;
     13my $hash = Hash::Ordered->new;
    1414my %commands;
    1515# Command structure:
     
    3232        'Clears the internal state',
    3333        sub {
    34             undef $hash;
    35             $hash = {};
     34            $hash = Hash::Ordered->new;
    3635        }
    3736    ],
     
    4140            my $new = read_xml shift @ARGV;
    4241            # Append the new data to the current data
    43             for my $key (keys %$new) {
    44                 if ($key eq '.attr' and exists $hash->{'.attr'}) {
    45                     for my $attr ($new->{'.attr'}) {
    46                         $hash->{'.attr'}->{$attr} = $new->{'.attr'}->{$attr};
     42            for my $key ($new->keys) {
     43                if ($key eq '.attr' and $hash->exists ('.attr')) {
     44                    my $existing_attr = $hash->get ('.attr');
     45                    my $new_attr      = $new->get ('.attr');
     46                    for my $attr ($new_attr->keys) {
     47                        $existing_attr->set ($attr => $new_attr->get ($attr));
    4748                    }
    48                 } elsif (exists $hash->{$key}) {
    49                     if (ref $hash->{$key} ne 'ARRAY') {
    50                         $hash->{$key} = [ $hash->{$key} ];
     49                } elsif ($hash->exists ($key)) {
     50                    my $existing = $hash->get ($key);
     51                    if (ref $existing ne 'ARRAY') {
     52                        $existing = [ $existing ];
     53                        $hash->set ($key => $existing);
    5154                    }
    52                     push @{$hash->{$key}},
    53                         (ref $new->{$key} eq 'ARRAY' ? @{$new->{$key}} : $new->{$key});
     55                    my $new_val = $new->get ($key);
     56                    push @{$existing},
     57                        (ref $new_val eq 'ARRAY' ? @{$new_val} : $new_val);
    5458                } else {
    55                     $hash->{$key} = $new->{$key};
     59                    $hash->set ($key => $new->get ($key));
    5660                }
    5761            }
Note: See TracChangeset for help on using the changeset viewer.