[Jifty-commit] r1408 - in jifty/trunk/lib: . Jifty/Plugin

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Thu Jun 29 20:14:27 EDT 2006


Author: jpeacock
Date: Thu Jun 29 20:14:18 2006
New Revision: 1408

Removed:
   jifty/trunk/lib/Jifty/Plugin/
Modified:
   jifty/trunk/lib/Jifty.pm
   jifty/trunk/lib/Jifty/ClassLoader.pm
   jifty/trunk/lib/Jifty/Plugin.pm
   jifty/trunk/lib/Jifty/Util.pm

Log:
Revert new ClassLoader code, which was giving Wifty fits (tested).
Sorry!

Modified: jifty/trunk/lib/Jifty.pm
==============================================================================
--- jifty/trunk/lib/Jifty.pm	(original)
+++ jifty/trunk/lib/Jifty.pm	Thu Jun 29 20:14:18 2006
@@ -119,8 +119,8 @@
     push @Jifty::Record::ISA, Jifty->config->framework('Database')->{'RecordBaseClass'};
 
     __PACKAGE__->logger( Jifty::Logger->new( $args{'logger_component'} ) );
-
-    my $base = Jifty->config->framework('ApplicationClass');
+    # Get a classloader set up
+    Jifty::ClassLoader->new(base => Jifty->config->framework('ApplicationClass'))->require;
 
     # Set up plugins
     my @plugins;
@@ -128,13 +128,8 @@
         my $class = "Jifty::Plugin::".(keys %{$plugin})[0];
         my %options = %{ $plugin->{(keys %{$plugin})[0]} };
         Jifty::Util->require($class);
-        Jifty::ClassLoader->new(base => $class);
-        push @plugins, $class->new(base => $base, %options);
+        push @plugins, $class->new(%options);
     }
-
-    # Get a classloader set up
-    Jifty::ClassLoader->new(base => $base)->require;
-
     __PACKAGE__->plugins(@plugins);
     __PACKAGE__->handler(Jifty::Handler->new());
     __PACKAGE__->api(Jifty::API->new());

Modified: jifty/trunk/lib/Jifty/ClassLoader.pm
==============================================================================
--- jifty/trunk/lib/Jifty/ClassLoader.pm	(original)
+++ jifty/trunk/lib/Jifty/ClassLoader.pm	Thu Jun 29 20:14:18 2006
@@ -27,113 +27,15 @@
 automatically loaded.
 
 =cut
-our @_CLASSES;
-our $_already_pushed;
 
 sub new {
     my $class = shift;
     my $self = bless {@_}, $class;
 
-    $self->load_defaults() if $self->{base};
-
-    # finally, put this object into @INC for later
-    unless ( $_already_pushed ) {
-        push(@INC, $self);
-        $_already_pushed = 1;
-    }
+    push @INC, $self;
     return $self;
 }
 
-
-sub register ($&) {
-    my ($self, $regex, $code) = @_;
-    push @_CLASSES, [$regex, $code];
-}
-
-sub preregister ($&) {
-    my ($self, $regex, $code) = @_;
-    unshift @_CLASSES, [$regex, $code];
-}
-
-sub load_defaults {
-    my ($self) = @_;
-    my $base = $self->{base};
-
-    $self->register(
-        qr/^(?:$base)$/,
-        sub {
-            my ($module) = @_;
-            return $self->return_class(
-                  "use warnings; use strict;\n"
-                . " package " . $self->{base} . ";\n" 
-                . "sub _autogenerated { 1 };\n"
-                . " 1;"
-            );
-        }
-    );
-
-    $self->register(
-        qr/^(?:$base)::(Record|Collection|Notification|Dispatcher|Bootstrap|Upgrade)$/,
-        sub {
-            my ($module) = @_;
-            return $self->return_class(
-                  "use warnings; use strict; package $module;\n"
-                . "use base qw/Jifty::$1/;\n"
-                . "sub _autogenerated { 1 };\n"
-                . "1;"
-            );
-        }
-    );
-    
-    $self->register(
-        qr/^(?:$base)::CurrentUser$/,
-        sub {
-            my ($module) = @_;
-            return $self->return_class(
-                  "use warnings; use strict; package $module;\n"
-                . "use base qw/Jifty::CurrentUser/;\n"
-                . "sub _autogenerated { 1 };\n"
-                . "1;"
-            );
-        }
-    );
-
-    $self->register(
-        qr/^(?:$base)::Model::(\w+)Collection$/,
-        sub {
-            my ($module) = @_;
-            my $base = $self->{base}; # for clarity purposes
-            return $self->return_class(
-                  "use warnings; use strict; package $module;\n"
-                . "use base qw/${base}::Collection/;\n"
-                . "sub record_class { '${base}::Model::$1' }\n"
-                . "sub _autogenerated { 1 };\n"
-                . "1;"
-            );
-        }
-    );
-
-    $self->register(
-        qr/^(?:$base)::Action::(Create|Update|Delete)([^\.]+)$/,
-        sub {
-            my ($module) = @_;
-            my $modelclass = $self->{base} . "::Model::" . $2;
-            Jifty::Util->require($modelclass);
-
-            return undef unless eval { $modelclass->table };
-
-            return $self->return_class(
-                  "use warnings; use strict; package $module;\n"
-                . "use base qw/Jifty::Action::Record::$1/;\n"
-                . "sub record_class { '$modelclass' };\n"
-                . "sub autogenerated { 1 };\n"
-                . "1;"
-            );
-        }
-    );
-
-}
-    
 =head2 INC
 
 The hook that is called when a module has been C<require>'d that
@@ -203,12 +105,47 @@
     $module =~ s/.pm$//;
     $module =~ s{/}{::}g;
 
-    foreach my $class ( @_CLASSES ) {
-        my ($regex, $code) = @{$class};
-        if ( $module =~ /$regex/ ) {
-            my $return = &$code($module);
-            return $return if defined $return;
-        }
+    # The quick check
+    return undef unless $module =~ m!^$base!;
+
+    if ( $module =~ m!^(?:$base)$! ) {
+        return $self->return_class(
+            "use warnings; use strict; package " . $base . ";\n" . " 1;" );
+    }
+#    elsif ( $module =~ m!^(?:$base)::Action$! ) {
+#        return $self->return_class(
+#                  "use warnings; use strict; package $module;\n"
+#                . "use base qw/Jifty::Action/; sub _autogenerated { 1 };\n"
+#                . "1;" );
+#    }
+    elsif ( $module =~ m!^(?:$base)::(Record|Collection|Notification|Dispatcher|Bootstrap|Upgrade)$! ) {
+        return $self->return_class(
+                  "use warnings; use strict; package $module;\n"
+                . "use base qw/Jifty::$1/; sub _autogenerated { 1 };\n"
+                . "1;" );
+    } elsif ( $module =~ m!^(?:$base)::CurrentUser$! ) {
+        return $self->return_class(
+                  "use warnings; use strict; package $module;\n"
+                . "use base qw/Jifty::CurrentUser/; sub _autogenerated { 1 };\n"
+                . "1;" );
+    } elsif ( $module =~ m!^(?:$base)::Model::(\w+)Collection$! ) {
+        return $self->return_class(
+                  "use warnings; use strict; package $module;\n"
+                . "use base qw/@{[$base]}::Collection/;\n"
+                . "sub record_class { '@{[$base]}::Model::$1' }\n"
+                . "1;" );
+    } elsif ( $module =~ m!^(?:$base)::Action::(Create|Update|Delete)([^\.]+)$! ) {
+        my $modelclass = $base . "::Model::" . $2;
+        Jifty::Util->require($modelclass);
+
+        return undef unless eval { $modelclass->table };
+
+        return $self->return_class(
+                  "use warnings; use strict; package $module;\n"
+                . "use base qw/Jifty::Action::Record::$1/;\n"
+                . "sub record_class { '$modelclass' };\n"
+                . "sub autogenerated { 1 };\n"
+                . "1;" );
     }
     return undef;
 }
@@ -239,8 +176,8 @@
 
 sub require {
     my $self = shift;
+    
     my $base = $self->{base};
-
     # if we don't even have an application class, this trick will not work
     return unless ($base); 
     Jifty::Util->require($base);

Modified: jifty/trunk/lib/Jifty/Plugin.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Plugin.pm	(original)
+++ jifty/trunk/lib/Jifty/Plugin.pm	Thu Jun 29 20:14:18 2006
@@ -49,17 +49,15 @@
 
 sub new {
     my $class = shift;
-    push @_, plugin => $class;
     
-    # Need to initialize a dispatcher
+    # Get a classloader set up
+    Jifty::ClassLoader->new(base => $class)->require;
     Jifty::Util->require($class->dispatcher);
 
     # XXX TODO: Add .po path
 
-    my $self = bless {@_} => $class;
+    my $self = bless {} => $class;
     $self->init(@_);
-    $self->plugin_defaults();
-    
     return $self;
 }
 
@@ -76,46 +74,6 @@
     1;
 }
 
-sub plugin_defaults {
-    my $self = shift;
-    my $base = $self->{base};
-    my $plugin = $self->{plugin};
-
-    # Create the plugin classloader elements on behalf of the application
-    require Jifty::ClassLoader;
-    my $classloader = Jifty::ClassLoader->new();
-    
-    $classloader->preregister(
-        qr/^(?:$base)::(Notification|CurrentUser)$/o,
-        sub {
-            my $module = shift;
-            my $plugin = $self->{plugin};
-            my $toplevel = "${plugin}::$1";
-            return $self->return_class(
-                      "use warnings; use strict; package $module;\n"
-                    . "use base qw/$toplevel/;\n"
-                    . "sub _autogenerated { 1 };\n"
-                    . "1;"
-            );
-        },
-    );
-
-    $classloader->preregister(
-        qr/^(?:$base)::Action::([^\.]+)$/o,
-        sub {
-            my $module = shift;
-            my $plugin = $self->{plugin};
-            my $action = "${plugin}::Action::$1";
-            return $self->return_class(
-                  "use warnings; use strict; package $module;\n"
-                . "use base qw/$action/;\n"
-                . "sub autogenerated { 1 };\n"
-                . "1;"
-            );
-        }
-    );
-}
-
 =head2 new_request
 
 Called right before every request.  By default, this adds the plugin's
@@ -175,11 +133,4 @@
     return $class."::Dispatcher";
 }
 
-sub return_class {
-    my $self = shift;
-    my $content = shift;
-    open my $fh, '<', \$content;
-    return $fh;
-}
-
 1;

Modified: jifty/trunk/lib/Jifty/Util.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Util.pm	(original)
+++ jifty/trunk/lib/Jifty/Util.pm	Thu Jun 29 20:14:18 2006
@@ -197,7 +197,7 @@
     if ($UNIVERSAL::require::ERROR) {
         my $error = $UNIVERSAL::require::ERROR;
         $error =~ s/ at .*?\n$//;
-        Jifty->log->warn(sprintf("$error at %s line %d\n", (caller)[1,2]));
+        Jifty->log->error(sprintf("$error at %s line %d\n", (caller)[1,2]));
         return 0;
     }
 


More information about the Jifty-commit mailing list