<%INIT>
my ($cookie,$new_cookie_header,$new_cookie);
# getting current cookie value
my $cookie_header = $r->header_in('Cookie');
foreach (split("; ",$cookie_header)) {
    my ($key,$value) = split("=");
    $cookie = $value if ($key eq 'CD-ME');
}
my %saved;
if ($add) {
   foreach my $id (split ":",$cookie) {$saved{$id}++;}
   $saved{$add}++;
   $new_cookie = join ":", keys %saved;
} elsif ($remove) {
   foreach my $id (split ":",$cookie) {$saved{$id}++ unless $id eq $remove;}
   $new_cookie = join ":", keys %saved;
} elsif ($retrieve) {
   return $cookie;
} elsif ($purge) {
   $new_cookie = "";
}

$new_cookie_header = "CD-ME=$new_cookie;path=/;expires=Tue, 21-Jan-2020 14:49:28 GMT";
$r->header_out('Set-cookie'=>$new_cookie_header);

</%INIT>
<%ARGS>
$add=>undef
$remove=>undef
$retrieve=>undef
$purge=>undef
</%ARGS>
