# Copyright 2000-2004 The Apache Software Foundation # # Licensed under the Apache License, Version 2.0 (the "License"); # you may not use this file except in compliance with the License. # You may obtain a copy of the License at # # http://www.apache.org/licenses/LICENSE-2.0 # # Unless required by applicable law or agreed to in writing, software # distributed under the License is distributed on an "AS IS" BASIS, # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. # See the License for the specific language governing permissions and # limitations under the License. use strict; use Apache::Cookie (); use Apache::Request (); use vars qw(@ANIMALS); unless (@ANIMALS) { @ANIMALS = sort qw{ lion tiger bear pig porcupine ferret zebra gnu ostrich emu moa goat weasel yak chicken sheep hyena dodo lounge-lizard squirrel rat mouse hedgehog racoon baboon kangaroo hippopotamus }; } my $r = shift; my $apr = Apache::Request->new($r); my $cookies = Apache::Cookie->new($r)->parse; my $c = $cookies->{'animals'}; my %zoo = (); %zoo = $c->value if $c; # Recover the new animal(s) from the parameter 'new_animal' my @new = $apr->param('new_animals'); # If the action is 'add', then add new animals to the zoo. Otherwise # delete them. foreach (@new) { if ($apr->param('action') eq 'Add') { $zoo{$_}++; } elsif ($apr->param('action') eq 'Delete') { $zoo{$_}-- if $zoo{$_}; delete $zoo{$_} unless $zoo{$_}; } } # Add new animals to old, and put them in a cookie my $cookie = Apache::Cookie->new($r, -name => 'animals', -value => \%zoo, -expires => '+1h'); $cookie->bake; $apr->send_http_header('text/html'); my $title = 'Animal crackers'; print < $title

$title

Choose the animals you want to add to the zoo, and click "add".

Add/DeleteCurrent Contents
EOF if (%zoo) { print "
    \n"; foreach (sort keys %zoo) { print "
  • $zoo{$_} $_\n"; } print "
\n"; } else { print "The zoo is empty.\n"; } print < EOF