[Jifty-commit] r4606 - in jifty/trunk: lib/Jifty lib/Jifty/Plugin lib/Jifty/Script share/plugins/Jifty/Plugin/AdminUI/web/templates/__jifty/admin

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Mon Dec 3 15:34:36 EST 2007


Author: alexmv
Date: Mon Dec  3 15:34:32 2007
New Revision: 4606

Modified:
   jifty/trunk/   (props changed)
   jifty/trunk/lib/Jifty/Action.pm
   jifty/trunk/lib/Jifty/ClassLoader.pm
   jifty/trunk/lib/Jifty/Plugin/ClassLoader.pm
   jifty/trunk/lib/Jifty/Script/Schema.pm
   jifty/trunk/share/plugins/Jifty/Plugin/AdminUI/web/templates/__jifty/admin/index.html

Log:
 r25352 at zoq-fot-pik:  chmrr | 2007-12-03 15:33:18 -0500
  * Fix for autogenerated modules.  Since sticking a method into them
    can cause things to "inherit" being autogenerated(!), we instead
    keep a global hash of them.
 
  * Also, fix schema code, which checked the wrong class for plugins
    overriding the app.


Modified: jifty/trunk/lib/Jifty/Action.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Action.pm	(original)
+++ jifty/trunk/lib/Jifty/Action.pm	Mon Dec  3 15:34:32 2007
@@ -1248,11 +1248,6 @@
     return;
 }
 
-=head2 autogenerated
-
-Autogenerated Actions will always return true when this method is called. 
-"Regular" actions will return false.
-
 =head1 CUSTOMIZATION
 
 =head2 Canonicalization
@@ -1375,8 +1370,6 @@
 
 =cut
 
-sub autogenerated {0}
-
 =head1 SEE ALSO
 
 L<Jifty>, L<Jifty::API>, L<Jifty::Action::Record>, L<Jifty::Result>,

Modified: jifty/trunk/lib/Jifty/ClassLoader.pm
==============================================================================
--- jifty/trunk/lib/Jifty/ClassLoader.pm	(original)
+++ jifty/trunk/lib/Jifty/ClassLoader.pm	Mon Dec  3 15:34:32 2007
@@ -3,6 +3,8 @@
 
 package Jifty::ClassLoader;
 
+our %AUTOGENERATED;
+
 =head1 NAME
 
 Jifty::ClassLoader - Loads the application classes
@@ -170,27 +172,29 @@
                                       Dispatcher|Bootstrap|Upgrade|CurrentUser|
                                       Handle|Event|Event::Model|Action|
                                       Action::Record::\w+)$/x ) {
+        $AUTOGENERATED{$module} = 1;
         return $self->return_class(
                   "package $module;\n"
-                . "use base qw/Jifty::$1/; sub _autogenerated { 1 };\n"
+                . "use base qw/Jifty::$1/; \n"
             );
     } 
     
     # Autogenerate an empty View if none is defined
     elsif ( $module =~ /^(?:$base)::View$/ ) {
+        $AUTOGENERATED{$module} = 1;
         return $self->return_class(
                   "package $module;\n"
-                . "use Jifty::View::Declare -base; sub _autogenerated { 1 };\n"
+                . "use Jifty::View::Declare -base;\n"
             );
     } 
 
     # Autogenerate the Collection class for a Model
     elsif ( $module =~ /^(?:$base)::Model::([^\.]+)Collection$/ ) {
+        $AUTOGENERATED{$module} = 1;
         return $self->return_class(
                   "package $module;\n"
                 . "use base qw/@{[$base]}::Collection/;\n"
                 . "sub record_class { '@{[$base]}::Model::$1' }\n"
-                . "sub _autogenerated { 1 };\n"
             );
     } 
     
@@ -204,11 +208,11 @@
         # Don't generate an event unless it really is a model
         return undef unless eval { $modelclass->isa('Jifty::Record') };
 
+        $AUTOGENERATED{$module} = 1;
         return $self->return_class(
                   "package $module;\n"
                 . "use base qw/${base}::Event::Model/;\n"
                 . "sub record_class { '$modelclass' };\n"
-                . "sub _autogenerated { 1 };\n"
             );
     } 
     
@@ -223,11 +227,11 @@
         # Don't generate the action unless it really is a model
         if ( eval { $modelclass->isa('Jifty::Record') } ) {
 
+            $AUTOGENERATED{$module} = 1;
             return $self->return_class(
                   "package $module;\n"
                 . "use base qw/$base\::Action::Record::$1/;\n"
                 . "sub record_class { '$modelclass' };\n"
-                . "sub _autogenerated { 1 };\n"
             );
         }
 
@@ -265,7 +269,6 @@
         foreach my $plugin (map {ref} Jifty->plugins) {
             next if ($plugin eq $base);
             my $class = $plugin."::".$type."::".$item;
-
             # Found it!
             if (Jifty::Util->try_to_require($class) ) {
 
@@ -278,10 +281,10 @@
                     if $type eq 'Model';
 
                 # Generate the empty stub
+                $AUTOGENERATED{$module} = 1;
                 return $self->return_class(
                         "package $module;\n"
                         . "use base qw/$class/;\n"
-                        . "sub _autogenerated { 1 };\n"
                         . $module_suffix
                     );
             }
@@ -467,6 +470,18 @@
     @INC = grep {defined $_ and $_ ne $self} @INC;
 }
 
+=head2 autogenerated PACKAGE
+
+Returns true if the package was autogenerated by a classloader.
+
+=cut
+
+sub autogenerated {
+    my $class = shift;
+    my $classname = shift;
+    return $AUTOGENERATED{$classname};
+}
+
 =head1 WRITING YOUR OWN CLASSES
 
 If you require more functionality than is provided by the classes created by

Modified: jifty/trunk/lib/Jifty/Plugin/ClassLoader.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Plugin/ClassLoader.pm	(original)
+++ jifty/trunk/lib/Jifty/Plugin/ClassLoader.pm	Mon Dec  3 15:34:32 2007
@@ -125,10 +125,10 @@
         my $method = "${plugin}::CurrentUser";
 	if ( Jifty::Util->already_required($method) ) {
 	    Jifty->log->debug("Implementing $module using $method");
+            $Jifty::ClassLoader::AUTOGENERATED{$module} = 1;
             return Jifty::ClassLoader->return_class(
                   "use warnings; use strict; package $module;\n"
                 . "use base qw/$method/;\n"
-                . "sub _autogenerated { 1 };\n"
                 . "1;" ) 
 	}
 	else {
@@ -144,11 +144,11 @@
 
 	if ( Jifty::Util->already_required($method) ) {
 	    Jifty->log->debug("Implementing $module using $method");
+            $Jifty::ClassLoader::AUTOGENERATED{$module} = 1;
 	    return Jifty::ClassLoader->return_class(
                   "use warnings; use strict; package $module;\n"
                 . "use base qw/$method/;\n"
                 . "sub record_class { '$base$model' };\n"
-                . "sub autogenerated { 1 };\n"
                 . "1;" )
 	}
 	else {
@@ -158,10 +158,10 @@
 	my $method = $plugin . "::" . $1 . $2;
 	if ( Jifty::Util->already_required($method) ) {
 	    Jifty->log->debug("Implementing $module using $method");
+            $Jifty::ClassLoader::AUTOGENERATED{$module} = 1;
 	    return Jifty::ClassLoader->return_class(
                   "use warnings; use strict; package $module;\n"
                 . "use base qw/$method/;\n"
-                . "sub autogenerated { 1 };\n"
                 . "1;" )
 	}
 	else {

Modified: jifty/trunk/lib/Jifty/Script/Schema.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Script/Schema.pm	(original)
+++ jifty/trunk/lib/Jifty/Script/Schema.pm	Mon Dec  3 15:34:32 2007
@@ -251,6 +251,8 @@
 
     MODEL:
     for my $model ( @models) {
+        # Skip autogenerated models; that is, those that are overridden by plugins.
+        next MODEL if Jifty::ClassLoader->autogenerated($model);
         my $plugin_root = Jifty->app_class('Plugin').'::';
 
         # TODO XXX FIXME:
@@ -293,9 +295,9 @@
             # Check to make sure this model is not overridden in the app,
             # in such cases we don't want to try to create the same table
             # twice, so let the app model do it rather than the plugin
-            my $app_model = Jifty->app_class($model_name);
+            my $app_model = Jifty->app_class("Model",$model_name);
             $app_model->require;
-            next MODEL unless $app_model->can('_autogenerated');
+            next MODEL unless Jifty::ClassLoader->autogenerated($app_model);
         }
 
         $log->info("Using $model, as it appears to be new.");

Modified: jifty/trunk/share/plugins/Jifty/Plugin/AdminUI/web/templates/__jifty/admin/index.html
==============================================================================
--- jifty/trunk/share/plugins/Jifty/Plugin/AdminUI/web/templates/__jifty/admin/index.html	(original)
+++ jifty/trunk/share/plugins/Jifty/Plugin/AdminUI/web/templates/__jifty/admin/index.html	Mon Dec  3 15:34:32 2007
@@ -20,7 +20,7 @@
 <ul>
 % foreach my $action (Jifty->api->actions) {
 % next unless (Jifty::Util->try_to_require($action));
-% next if ( $action->can('autogenerated') and $action->autogenerated);
+% next if ( Jifty::ClassLoader->autogenerated($action) );
 <li><% Jifty->web->link( url => '/__jifty/admin/action/'.$action, label => $action) %></li>
 % }
 </ul>


More information about the Jifty-commit mailing list