fix the delegation code in User.pm
Matt S Trout [Wed, 1 Sep 2010 19:17:04 +0000 (19:17 +0000)]
Changes
lib/Catalyst/Authentication/Store/DBIx/Class/User.pm

diff --git a/Changes b/Changes
index 990eef8..2cdbbb2 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,7 @@
 Revision history for Catalyst-Plugin-Authentication-Store-DBIx-Class
 
+        * Make can() work as well as AUTOLOADing.
+
 0.1300  2010-06-16
         * Support columns with accessors that aren't the column name.
         * Fix some documentation typos.
index 3b05c19..231d1cd 100644 (file)
@@ -238,6 +238,21 @@ sub auto_update {
     $self->_user->auto_update( @_ );
 }
 
+sub can {
+    my $self = shift;
+    return $self->SUPER::can(@_) || do {
+        my ($method) = @_; warn $method;
+        if (my $code = $self->_user->can($method)) {
+            sub { shift->_user->$code(@_) }
+        } elsif (my $accessor =
+            try { $self->_user->result_source->column_info($method)->{accessor} }) {
+            sub { shift->_user->$accessor }
+        } else {
+            undef;
+        }
+    };
+}
+
 sub AUTOLOAD {
     my $self = shift;
     (my $method) = (our $AUTOLOAD =~ /([^:]+)$/);
@@ -354,9 +369,13 @@ None known currently, please email the author if you find any.
 
 Jason Kuri (jayk@cpan.org)
 
+=head1 CONTRIBUTORS
+
+Matt S Trout (mst) <mst@shadowcat.co.uk>
+
 =head1 LICENSE
 
-Copyright (c) 2007 the aforementioned authors. All rights
+Copyright (c) 2007-2010 the aforementioned authors. All rights
 reserved. This program is free software; you can redistribute
 it and/or modify it under the same terms as Perl itself.