07 December 2007
This post may be outdated due to it was written on 2007. The links may be broken. The code may be not working anymore. Leave comments if needed.
I just release a new CPAN module for Catalyst - Catalyst::Authentication::Store::FromSub::Hash.

Generally I always hate one situation that http://search.cpan.org/perldoc?Catalyst::Authentication::Store::DBIx::Class hits database every request. to ease database, I create one cache layout between Authentication and database.

In my Foorum,
Foorum.pm
use Catalyst qw/Authentication ../;

foorum.yml
authentication:
default_realm: 'members'
realms:
members:
credential:
class: 'Password'
password_field: 'password'
password_type: "hashed"
password_hash_type: "SHA-1"
store:
class: 'FromSub::Hash'
model_class: "UserAuth"

In this config, we use store "FromSub::Hash" and model_class "UserAuth". so we need create a Foorum::Model::UserAuth:
package Foorum::Model::UserAuth;
use base 'Catalyst::Model';

sub auth {
my ($self, $c, $userinfo) = @_;

my $where;
if (exists $userinfo->{user_id}) {
$where = { user_id => $userinfo->{user_id} };
} elsif (exists $userinfo->{username}) {
$where = { username => $userinfo->{username} };
} else { return; }

my $user = $c->model('User')->get( $c, $where );
return $user;
}

$c->model('User')->get($c, $where); has built-in cache layout. and it return hash from/to cache.

I guess I would create another module - Catalyst::Authentication::Store::FromSub::Object later.
but since I don't use it, I'm not sure when will it kick out.

@Enjoy!


blog comments powered by Disqus