Catalyst::Plugin::Session::AsObject - Make your session data an object


version 0.05


    package MyApp;

    use MyApp::Session;

    use Catalyst qw(

        'Plugin::Session' => {
            object_class => 'MyApp::Session',

    sub foo : Global {
        my $self = shift;
        my $c    = shift;

        my $session = $c->session_object();

        if ( $session->has_error_messages() ) {...}


This class makes it easier to treat the session as an object rather than a plain hash reference. This is useful if you want to ensure that the session only contains specific pieces of data.

However, because of implementation details, we cannot override the existing $c->session() method, so you need to use the new $c->session_object() method provided by this plugin.


This class provides the following methods:


Returns the object stored in the session. If needed, a new object is created.


Returns true if there is an object already in the session.


This plugin has only configuration key, "object_class". This key should appear under the existing top-level "session" configuration key.

The "object_class" must already be loaded, and must have a new() method as its constructor. This constructor must not require any parameters, as it will be called without any arguments.


Please report any bugs or feature requests to, or through the web interface at I will be notified, and then you'll automatically be notified of progress on your bug as I make changes.


If you'd like to thank me for the work I've done on this module, please consider making a "donation" to me via PayPal. I spend a lot of free time creating free software, and would appreciate any support you'd care to offer.

Please note that I am not suggesting that you must do this in order for me to continue working on this particular software. I will continue to do so, inasmuch as I have in the past, for as long as it interests me.

Similarly, a donation made in this way will probably not make me work on this software much more, unless I get so many donations that I can consider working on free software full time, which seems unlikely at best.

To donate, log into PayPal and send money to or use the button on this page:


Dave Rolsky, ><


This software is Copyright (c) 2012 by Dave Rolsky.

This is free software, licensed under:

  The Artistic License 2.0 (GPL Compatible)