[Jifty-commit] r2684 - in jifty/trunk: lib/Jifty

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Sun Jan 28 08:57:35 EST 2007


Author: jesse
Date: Sun Jan 28 08:57:35 2007
New Revision: 2684

Modified:
   jifty/trunk/   (props changed)
   jifty/trunk/lib/Jifty/ClassLoader.pm

Log:
 r21616 at hualien:  jesse | 2007-01-28 21:56:23 +0800
 * Extract the "load model related classes" logic in the class loader to its own function
 * A new method provides a tantalizing glimpse of jifty's forthcoming "load models from the database" support


Modified: jifty/trunk/lib/Jifty/ClassLoader.pm
==============================================================================
--- jifty/trunk/lib/Jifty/ClassLoader.pm	(original)
+++ jifty/trunk/lib/Jifty/ClassLoader.pm	Sun Jan 28 08:57:35 2007
@@ -204,6 +204,10 @@
     return unless ($base); 
     Jifty::Util->require($base);
     Jifty::Util->require($base."::CurrentUser");
+
+    my %models;
+    
+
     Jifty::Module::Pluggable->import(
         search_path =>
           [ map { $base . "::" . $_ } 'Model', 'Action', 'Notification', 'Event' ],
@@ -211,14 +215,52 @@
         except  => qr/\.#/,
         inner   => 0
     );
-    my %models;
     $models{$_} = 1 for grep {/^($base)::Model::(.*)$/ and not /Collection$/} $self->plugins;
     $self->models(sort keys %models);
     for my $full ($self->models) {
+        $self->_require_model_related_classes($full);
+    }
+        
+}
+
+sub _require_model_related_classes {
+    my $self = shift;
+    my $full = shift;
+    my $base = $self->{base};
         my($short) = $full =~ /::Model::(.*)/;
         Jifty::Util->require($full . "Collection");
         Jifty::Util->require($base . "::Action::" . $_ . $short)
             for qw/Create Update Delete Search/;
+
+}
+
+
+=head2 require_classes_from_database
+
+Jifty supports model classes that aren't files on disk but instead records
+in your database. It's a little bit mind bending, but basically, you can
+build an application entirely out of the database without ever writing a 
+line of code(*). 
+
+* As of early 2007, this forward looking statement is mostly a lie. But we're 
+working on it.
+
+This method finds all database-backed models and instantiates jifty classes for 
+them it returns a list of classnames of the models it created.
+
+=cut
+
+sub require_classes_from_database {
+    my $self = shift;
+    my @instantiated;
+
+    require Jifty::Model::ModelClassCollection;
+    require Jifty::Model::ModelClass;
+    my $models = Jifty::Model::ModelClassCollection->new(current_user => Jifty::CurrentUser->superuser);
+    $models->unlimit();
+    while (my $model = $models->next) {
+        $model->instantiate();
+        $self->_require_model_related_classes($model->qualified_class);
     }
 }
 


More information about the Jifty-commit mailing list