Catalyst::Authentication::Store::Tangram::User - A thin adaptor


Catalyst-Authentication-Store-Tangram documentation Contained in the Catalyst-Authentication-Store-Tangram distribution.

Index


Code Index:

NAME

Top

Catalyst::Authentication::Store::Tangram::User - A thin adaptor to adapt any Tangram class to behave as needed by Catalyst::Authentication::User

SYNOPSIS

Top

    $c->user->id; # Returns unique user ID
    $c->user->get('email_address'); # Retrieve value from the underlying Tangram object.
    $c->user->get_object; # Get the underlying Tangram object yourself.

DESCRIPTION

Top

The Catalyst::Authentication::Store::Tangram::User class encapsulates any Tangram class in the Catalyst::Authentication::User interface. An instance of it will be returned by $c->user when using Catalyst::Authentication::Store::Tangram. Methods not defined in this module are passed through to the Tangram object. The object stringifies to the Tangram ID.

METHODS

Top

new ($class, $storage, $tangram_object)

Simple constructor

id

Unique Tangram ID for this object

get_object

Returns the underlying Tangram user object.

roles

Returns the list of roles which this user is authorised to do.

supported_features

Returns hashref of features that this Authentication::User subclass supports.

AUTHOR

Top

Tomas Doran, <bobtfish at bobtfish dot net>

With thanks to state51, my employer, for giving me the time to work on this.

BUGS

Top

All complex software has bugs, and I'm sure that this module is no exception.

Please report bugs through the rt.cpan.org bug tracker.

COPYRIGHT

Top


Catalyst-Authentication-Store-Tangram documentation Contained in the Catalyst-Authentication-Store-Tangram distribution.

package Catalyst::Authentication::Store::Tangram::User;
use strict;
use warnings;
use base qw/Catalyst::Authentication::User/;
use Carp qw/confess/;
use Scalar::Util qw/blessed/;

use overload '""' => sub { shift->id }, fallback => 1;

BEGIN {
    __PACKAGE__->mk_accessors(qw/_tangram _storage _store _roles/);
}

sub new {
    my ($class, $storage, $tangram_ob, $store) = @_;
    bless { _storage => $storage, _tangram => $tangram_ob, _store => $store }, $class;
}

*get_object = \&_tangram;

sub id {
    my ($self) = @_;
    return $self->_storage->id($self->_tangram);
}

sub roles {
    my ($self) = @_;
    $self->_roles([$self->_store->lookup_roles($self)])
        unless $self->_roles;
    return @{ $self->_roles };
}

sub supported_features {
        return {
        password => { self_check => 0, },
        session  => 1,
        roles    => { self_check => 0, },
    };
}

sub AUTOLOAD {
    my $self = shift;

    ( my $method ) = ( our $AUTOLOAD =~ /([^:]+)$/ );

    return if $method eq "DESTROY";

    confess("Could not call method $method on tangram class " . 
        blessed($self->_tangram)) unless $self->_tangram->can($method);
    $self->_tangram->$method;
}

1;