Changeset 29672 for main/trunk/package-kits/linux/files/servlet.pl
- Timestamp:
- 2015-01-07T14:49:26+13:00 (9 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
main/trunk/package-kits/linux/files/servlet.pl
r29671 r29672 165 165 # [1]: Function that is run for the command 166 166 # [2]: Number of arguments of the command (if any) 167 # [3]: True if the command has a variable number of args 167 168 %commands = ( 168 169 help => [ … … 182 183 ], 183 184 read => [ 184 'Parses XML from a file into the internal state',185 "Parses XML from a file into the internal state\n input_file (- for STDIN)", 185 186 sub { 186 187 my $file = shift @ARGV; … … 206 207 $hash->{$key} = [ $hash->{$key} ]; 207 208 } 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 } 209 push @{$hash->{$key}}, 210 (ref $new->{$key} eq 'ARRAY' ? @{$new->{$key}} : $new->{$key}); 215 211 } else { 216 212 $hash->{$key} = $new->{$key}; … … 221 217 ], 222 218 write => [ 223 'Writes the current internal state as XML to a file',219 "Writes the current internal state as XML to a file\n output_file (- for STDOUT)", 224 220 sub { 225 221 my $file = shift @ARGV; … … 287 283 1, 288 284 ], 285 add => [ 286 "Adds a new servlet to the current internal state\n name description class [param=value param2=value...] ;", 287 sub { 288 my %servlet = ( 289 'servlet-name' => shift @ARGV, 290 'description' => shift @ARGV, 291 'servlet-class'=> shift @ARGV, 292 'init-param' => [], 293 ); 294 while (@ARGV) { 295 my $param = shift @ARGV; 296 $param eq ';' and last; 297 my ($key, $value) = split '=', $param, 2; 298 (defined $key and defined $value) or die "Expected params in form 'param=value'\n"; 299 push @{$servlet{'init-param'}}, { 300 'param-name' => $key, 301 'param-value' => $value, 302 }; 303 } 304 if (defined $hash->{servlet}) { 305 unless (ref $hash->{servlet} eq 'ARRAY') { 306 $hash->{servlet} = [ $hash->{servlet} ]; 307 } 308 push @{$hash->{servlet}}, \%servlet; 309 } else { 310 $hash->{servlet} = \%servlet; 311 } 312 }, 313 3, 314 1, 315 ], 289 316 ); 290 317 291 318 # Check that all given commands are valid 292 319 my $argc = 0; 320 my $varargs = 0; 293 321 for my $cmd (@ARGV) { 294 if ($argc > 0) { 322 if ($varargs and $cmd eq ';') { 323 $varargs = 0; 324 } elsif ($argc > 0) { 295 325 # skip arguments to a previous command 296 326 $argc --; 327 } elsif ($varargs) { 297 328 } elsif (defined $commands{$cmd}) { 298 329 # get the argument count of a valid command 299 330 $argc = @{$commands{$cmd}}[2]; 300 331 defined $argc or ($argc = 0); 332 $varargs = @{$commands{$cmd}}[3]; 301 333 } else { 302 334 # invalid command … … 306 338 } 307 339 } 308 $argc > 0 and die "Expected $argc more argument" . ($argc > 1 ? "s" : "") . "\n"; 340 $argc != 0 and die "Expected $argc more argument" . ($argc != 1 ? "s" : "") . "\n"; 341 $varargs and die "Unclosed vararg command. Add an argument ';' to close the varargs\n"; 309 342 310 343 # Run the commands
Note:
See TracChangeset
for help on using the changeset viewer.