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

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Sun Mar 11 20:35:17 EDT 2007


Author: jesse
Date: Sun Mar 11 20:35:16 2007
New Revision: 2945

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

Log:
 r53343 at pinglin:  jesse | 2007-03-11 20:34:29 -0400
 * a way to try to load a module from disk that may or may not exist
 


Modified: jifty/trunk/lib/Jifty/Util.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Util.pm	(original)
+++ jifty/trunk/lib/Jifty/Util.pm	Sun Mar 11 20:35:16 2007
@@ -222,7 +222,14 @@
 
 sub require {
     my $self = shift;
-    my $class = shift;
+    my $module = shift;
+    $self->_require( module => $module,  quiet => 0);
+}
+
+sub _require {
+    my $self = shift;
+    my %args = ( module => undef, quiet => undef, @_);
+    my $class = $args{'module'};
 
     # Quick hack to silence warnings.
     # Maybe some dependencies were lost.
@@ -233,11 +240,15 @@
 
     return 1 if $self->already_required($class);
 
+    local $UNIVERSAL::require::ERROR = '';
     my $retval = $class->require;
     if ($UNIVERSAL::require::ERROR) {
         my $error = $UNIVERSAL::require::ERROR;
         $error =~ s/ at .*?\n$//;
-        Jifty->log->error(sprintf("$error at %s line %d\n", (caller)[1,2]));
+        
+        unless ($args{'quiet'} and $error =~ /^Can't locate/) {
+            Jifty->log->error(sprintf("$error at %s line %d\n", (caller(1))[1,2]));
+        }
         return 0;
     }
 
@@ -250,6 +261,20 @@
     return 1;
 }
 
+=head2 try_to_require Module
+
+This method works just like L</require>, except that it surpresses the error message
+in cases where the module isn't found.
+
+=cut
+
+sub  try_to_require {
+    my $self = shift;
+    my $module = shift;
+    $self->_require( module => $module,  quiet => 1);
+}
+
+
 =head2 already_required class
 
 Helper function to test whether a given class has already been require'd.


More information about the Jifty-commit mailing list