Ignore:
Timestamp:
2015-01-07T14:12:12+13:00 (9 years ago)
Author:
Jeremy Symon
Message:

Added ability to concatenate XML (which provides a basic way to add a servlet: 'servlet.pl read servlets.xml read - write servlets.xml' - read from the original file, then read from STDIN (where the new servlet can be added), then write to the original file)

File:
1 edited

Legend:

Unmodified
Added
Removed
  • main/trunk/package-kits/linux/files/servlet.pl

    r29670 r29671  
    178178        sub {
    179179            undef $hash;
     180            $hash = {};
    180181        }
    181182    ],
     
    184185        sub {
    185186            my $file = shift @ARGV;
     187            my $new;
    186188            if ($file eq '-') {
    187189                if (isatty *STDIN) {
    188190                    print STDERR "Reading XML from STDIN. Press ^D to end\n";
    189191                }
    190                 $hash = read_xml *STDIN;
     192                $new = read_xml *STDIN;
    191193            } else {
    192194                open FH, '<', $file;
    193                 $hash = read_xml *FH;
     195                $new = read_xml *FH;
    194196                close FH;
     197            }
     198            # Append the new data to the current data
     199            for my $key (keys %$new) {
     200                if ($key eq '.attr' and defined $hash->{'.attr'}) {
     201                    for my $attr ($new->{'.attr'}) {
     202                        $hash->{'.attr'}->{$attr} = $new->{'.attr'}->{$attr};
     203                    }
     204                } elsif (defined $hash->{$key}) {
     205                    if (ref $hash->{$key} ne 'ARRAY') {
     206                        $hash->{$key} = [ $hash->{$key} ];
     207                    }
     208                    if (ref $new->{$key} eq 'ARRAY') {
     209                        for my $elem (@{$new->{$key}}) {
     210                            push @{$hash->{$key}}, $elem;
     211                        }
     212                    } else {
     213                        push @{$hash->{$key}}, $new->{$key};
     214                    }
     215                } else {
     216                    $hash->{$key} = $new->{$key};
     217                }
    195218            }
    196219        },
Note: See TracChangeset for help on using the changeset viewer.