Catalyst-Authentication-Store-CouchDB

 view release on metacpan or  search on metacpan

lib/Catalyst/Authentication/Store/CouchDB.pm  view on Meta::CPAN

## no critic
# no critic line turns off Perl::Critic, to get rid of the warning that
# Dist::Zilla::Plugin::PkgVersion puts the package version straight
# after the package line, and thus before use strict
package Catalyst::Authentication::Store::CouchDB;
BEGIN {
  $Catalyst::Authentication::Store::CouchDB::VERSION = '0.001';
}
# ABSTRACT: A storage class for Catalyst Authentication using CouchDB
## use critic
use strict;
use warnings;

use Moose 2.00;
use Catalyst::Exception;

has 'store_user_class'  => (is => 'ro', isa => 'Str', default => 'Catalyst::Authentication::Store::CouchDB::User', );
has 'config'            => (is => 'ro', isa => 'HashRef', required => 1,  );

# Convert the parameters passed to ->new into the correct
# format for passing to our Moose generated constructor.
# Also, ensure that the user class is loaded.

around BUILDARGS => sub {
    my ( $orig, $class, $config, $c ) = @_;

    # Validate the configuration
    if (!$config->{couchdb_uri}) {
        Catalyst::Exception->throw("couchdb_uri required in configuration");
    }

    if (!$config->{dbname}) {
        Catalyst::Exception->throw("dbname required in configuration");
    }
    if (!$config->{designdoc}) {
        Catalyst::Exception->throw("designdoc required in configuration");
    }
    if ($config->{designdoc} !~ /^\_design\//) {
        Catalyst::Exception->throw("designdoc must start with _design/ required in configuration");
    }
    if (!$config->{view}) {
        Catalyst::Exception->throw("view required in configuration");
    }

    ## figure out if we are overriding the default store user class
    $config->{'store_user_class'} = (exists($config->{'store_user_class'})) ? $config->{'store_user_class'} :
                                        "Catalyst::Authentication::Store::CouchDB::User";

    ## make sure the store class is loaded.
    Catalyst::Utils::ensure_class_loaded( $config->{'store_user_class'} );

    # $orig will call the superclass BUILDARGS, which
    # will format the args hash appropriately.
    return $class->$orig(
        store_user_class => $config->{store_user_class},
        config => $config,
    );
};

sub from_session {
    my ($self, $c, $frozenuser) = @_;

    my $user = $self->store_user_class->new($self->{'config'}, $c);
    return $user->from_session($frozenuser);
}

sub for_session {
    my ($self, $c, $user) = @_;

    return $user->for_session();
}

sub find_user {
    my ($self, $authinfo, $c) = @_;

    my $user = $self->store_user_class->new($self->{'config'}, $c);

    return $user->load($authinfo, $c);



( run in 0.755 second using v1.01-cache-2.11-cpan-39bf76dae61 )