Catalyst-Authentication-Store-DBIx-Class

 view release on metacpan or  search on metacpan

lib/Catalyst/Authentication/Store/DBIx/Class/User.pm  view on Meta::CPAN

package Catalyst::Authentication::Store::DBIx::Class::User;

use Moose;
use namespace::autoclean;
extends 'Catalyst::Authentication::User';

use List::MoreUtils 'all';
use Try::Tiny;

has 'config'    => (is => 'rw');
has 'resultset' => (is => 'rw');
has '_user'     => (is => 'rw');
has '_roles'    => (is => 'rw');

sub new {
    my ( $class, $config, $c) = @_;

	$config->{user_model} = $config->{user_class}
        unless defined $config->{user_model};

    my $self = {
        resultset => $c->model($config->{'user_model'}),
        config => $config,
        _roles => undef,
        _user => undef
    };

    bless $self, $class;

    Catalyst::Exception->throw(
        "\$c->model('${ \$self->config->{user_model} }') did not return a resultset."
          . " Did you set user_model correctly?"
    ) unless $self->{resultset};

    $self->config->{'id_field'} = [$self->{'resultset'}->result_source->primary_columns]
        unless exists $self->config->{'id_field'};

    $self->config->{'id_field'} = [$self->config->{'id_field'}]
        unless ref $self->config->{'id_field'} eq 'ARRAY';

    Catalyst::Exception->throw(
        "id_field set to "
          . join(q{,} => @{ $self->config->{'id_field'} })
          . " but user table has no column by that name!"
    ) unless all { $self->{'resultset'}->result_source->has_column($_) } @{ $self->config->{'id_field'} };

    ## if we have lazyloading turned on - we should not query the DB unless something gets read.
    ## that's the idea anyway - still have to work out how to manage that - so for now we always force
    ## lazyload to off.
    $self->config->{lazyload} = 0;

#    if (!$self->config->{lazyload}) {
#        return $self->load_user($authinfo, $c);
#    } else {
#        ## what do we do with a lazyload?
#        ## presumably this is coming out of session storage.
#        ## use $authinfo to fill in the user in that case?
#    }

    return $self;
}


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

    my $dbix_class_config = 0;



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