Search code examples
perlmojolicious

How to replace Mojolicious sessions with a custom implementation?


By default Mojolicious sessions create a signed cookie for the session. I would like to override this behavior. I can extend Mojolicious::Sessions and override the load and store methods, but how do I use my class instead of the default Mojolicious::Sessions.


Solution

  • As documented, the Mojolicious::Sessions object is held in the app's sessions property. Therefore you can either override it on creation

    my $app = MyApp->new( sessions => MySessions->new );
    

    or afterward

    $app->sessions( MySessions->new );