[Jifty-commit] r6713 - jifty/trunk/lib/Jifty/Action

Jifty commits jifty-commit at lists.jifty.org
Mon Mar 30 17:37:40 EDT 2009


Author: alexmv
Date: Mon Mar 30 17:37:40 2009
New Revision: 6713

Modified:
   jifty/trunk/lib/Jifty/Action/Record.pm

Log:
Obviate the need for the really short sub record_class {...} in most cases

Modified: jifty/trunk/lib/Jifty/Action/Record.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Action/Record.pm	(original)
+++ jifty/trunk/lib/Jifty/Action/Record.pm	Mon Mar 30 17:37:40 2009
@@ -15,8 +15,9 @@
 
 To actually use this class, you probably want to inherit from one of
 L<Jifty::Action::Record::Create>, L<Jifty::Action::Record::Update>, or
-L<Jifty::Action::Record::Delete> and override the C<record_class>
-method.
+L<Jifty::Action::Record::Delete>.  You may need to override the
+L</record_class> method, if Jifty cannot determine the record class of
+this action.
 
 =cut
 
@@ -55,9 +56,20 @@
 
 sub record_class {
     my $self = shift;
-    my $class = ref $self;
-    my $hint = $class eq __PACKAGE__ ? "" : " (did you forget to override record_class in $class?)";
-    $self->log->fatal("Jifty::Action::Record must be subclassed to be used" .  $hint);
+    return $self->{record_class} ||= do {
+        my $class = ref($self);
+        if ($class =~ /::(Create|Search|Execute|Update|Delete)([^:]+)$/) {
+            my($type, $model) = ($1, $2);
+            $model = Jifty->app_class( Model => $model );
+            return $model if grep {$_ eq $model} Jifty->class_loader->models;
+        }
+
+        if ($class eq "Jifty::Action::Record") {
+            $self->log->fatal("Jifty::Action::Record must be subclassed to be used");
+        } else {
+            $self->log->fatal("Cannot determine model for Jifty::Action::Record subclass $class");
+        }
+    };
 }
 
 =head2 new PARAMHASH


More information about the Jifty-commit mailing list