From: Rafael Kitover Date: Mon, 7 Jun 2010 12:38:01 +0000 (+0000) Subject: cleanup and handle unknown column/method X-Git-Tag: v0.1201~2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Authentication-Store-DBIx-Class.git;a=commitdiff_plain;h=51f4005671be7e098c544bb03a8e960bb251800c cleanup and handle unknown column/method --- diff --git a/Makefile.PL b/Makefile.PL index 66edb22..50fde2a 100644 --- a/Makefile.PL +++ b/Makefile.PL @@ -40,6 +40,7 @@ requires ( 'Moose' => 0, 'namespace::autoclean' => 0, 'List::MoreUtils' => 0, + 'Try::Tiny' => 0, ); test_requires 'Test::More'; diff --git a/lib/Catalyst/Authentication/Store/DBIx/Class/User.pm b/lib/Catalyst/Authentication/Store/DBIx/Class/User.pm index 4ae3d12..87a8c0e 100644 --- a/lib/Catalyst/Authentication/Store/DBIx/Class/User.pm +++ b/lib/Catalyst/Authentication/Store/DBIx/Class/User.pm @@ -5,6 +5,7 @@ use namespace::autoclean; extends 'Catalyst::Authentication::User'; use List::MoreUtils 'all'; +use Try::Tiny; has 'config' => (is => 'rw'); has 'resultset' => (is => 'rw'); @@ -201,9 +202,11 @@ sub get { if (my $code = $self->_user->can($field)) { return $self->_user->$code; } - elsif (my $accessor = $self->_user->result_source->column_info($field)->{accessor}) { + elsif (my $accessor = + try { $self->_user->result_source->column_info($field)->{accessor} }) { return $self->_user->$accessor; } else { + # XXX this should probably throw return undef; } } @@ -240,12 +243,7 @@ sub AUTOLOAD { (my $method) = (our $AUTOLOAD =~ /([^:]+)$/); return if $method eq "DESTROY"; - if (my $code = $self->_user->can($method)) { - $self->_user->$code(@_); - } - elsif (my $accessor = $self->_user->result_source->column_info($method)->{accessor}) { - $self->_user->$accessor(@_); - } + return $self->get($method); } __PACKAGE__->meta->make_immutable(inline_constructor => 0);