<<

NAME

Koha::CookieManager - Object for unified handling of cookies in Koha

SYNOPSIS

    use Koha::CookieManager;
    my $mgr = Koha::CookieManager->new;

    # Replace cookies
    $cookie_list = $mgr->replace_in_list( [ $cookie1, $cookie2_old ], $cookie2_new );

    # Clear cookies (governed by deny list entries in koha-conf)
    $cookie_list = $mgr->clear_unless( $cookie1, $cookie2, $cookie3_name );

DESCRIPTION

The current object allows you to clear cookies in a list based on the deny list in koha-conf.xml. It also offers a method to replace the old version of a cookie by a new one.

It could be extended by (gradually) routing cookie creation through it in order to consistently fill cookie parameters like httponly, secure and samesite flag, etc. And could serve to register all our cookies in a central location.

METHODS

new

    my $mgr = Koha::CookieManager->new({}); # parameters for extensions

clear_unless

    $cookies = $self->clear_unless( $query->cookie, @$cookies );

    Arguments: either cookie names or cookie objects (CGI::Cookie).
    Note: in the example above $query->cookie is a list of cookie names as returned
    by the CGI object.

    Returns an arrayref of cookie objects: empty, expired cookies for those passed
    by name or objects that are not on the deny list, together with the remaining
    (untouched) cookie objects that are on the deny list.

replace_in_list

    $list2 = $mgr->replace_in_list( $list1, $cookie );

    Add $cookie to $list1, removing older occurrences in list1.
    $list1 is a list of CGI::Cookie objects.
    $cookie must be a CGI::Cookie object; if it is not, only
    cookie objects in list1 are returned (filtering list1).

    Returns an arrayref of CGI::Cookie objects.

INTERNAL ROUTINES

<<