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

Jifty commits jifty-commit at lists.jifty.org
Mon Mar 2 19:57:56 EST 2009


Author: alexmv
Date: Mon Mar  2 19:57:56 2009
New Revision: 6533

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

Log:
 r42838 at kohr-ah:  chmrr | 2009-03-02 19:55:26 -0500
 File::ShareDir fixups; explode if jifty share can't be found


Modified: jifty/trunk/lib/Jifty/Plugin.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Plugin.pm	(original)
+++ jifty/trunk/lib/Jifty/Plugin.pm	Mon Mar  2 19:57:56 2009
@@ -111,26 +111,21 @@
     my $self = shift;
     my $class = ref($self);
 
-    Jifty::Util->require('File::ShareDir');
     unless ( $self->{share} ) {
-        local $@
-            ; # We're just avoiding File::ShareDir's failure behaviour of dying
-        eval { $self->{share} = File::ShareDir::dist_dir($class) };
+        # Try File::ShareDir, in case it's a non-core plugin
+        Jifty::Util->require('File::ShareDir');
+        my $dist = $class;
+        $dist =~ s/::/-/g;
+        local $@;
+        eval { $self->{share} = File::ShareDir::dist_dir($dist) };
     }
     unless ( $self->{share} ) {
+        # Core plugins live in jifty's share/plugins/Jifty/Plugin/Whatever/
+        my $class_to_path = $class;
+        $class_to_path =~ s|::|/|g;
+        # for the in dist plugin share resides in share/plugins/...
         $self->{share} = Jifty::Util->share_root;
-        if ( $self->{'share'} ) {
-            my $class_to_path = $class;
-            $class_to_path =~ s|::|/|g;
-            # for the in dist plugin share resides in share/plugins/...
-            $self->{share} .= "/plugins/" . $class_to_path;
-            if (!-d $self->{share}) {
-                # for the plugin share resides in plugins/NAME/share
-                $self->{share} = $INC{$class_to_path.'.pm'};
-                $self->{share} =~ s{lib/\Q$class_to_path.pm}{share};
-                $self->{share} = File::Spec->rel2abs($self->{share});
-            }
-        }
+        $self->{share} .= "/plugins/" . $class_to_path;
     }
     return $self->{share};
 }

Modified: jifty/trunk/lib/Jifty/Util.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Util.pm	(original)
+++ jifty/trunk/lib/Jifty/Util.pm	Mon Mar  2 19:57:56 2009
@@ -101,18 +101,20 @@
 
 sub share_root {
     my $self = shift;
-
-    
-    Jifty::Util->require('File::ShareDir');
-    $SHARE_ROOT ||=  eval { File::Spec->rel2abs( File::ShareDir::module_dir('Jifty') )};
-    if (not $SHARE_ROOT or not -d $SHARE_ROOT) {
-        # XXX TODO: This is a bloody hack
-        # Module::Install::ShareDir and File::ShareDir don't play nicely
-        # together
+    unless (defined $SHARE_ROOT) {
+        # Try for the local version, first
         my @root = File::Spec->splitdir($self->jifty_root); # lib
         pop @root; # Jifty-version
         $SHARE_ROOT = File::Spec->catdir(@root,"share");
+        undef $SHARE_ROOT unless defined $SHARE_ROOT and -d $SHARE_ROOT and -d File::Spec->catdir($SHARE_ROOT,"web");
+
+        # If that doesn't pass inspection, try File::ShareDir::dist_dir
+        Jifty::Util->require('File::ShareDir');
+        $SHARE_ROOT ||= eval { File::Spec->rel2abs( File::ShareDir::dist_dir('Jifty') )};
+        undef $SHARE_ROOT unless defined $SHARE_ROOT and -d $SHARE_ROOT and -d File::Spec->catdir($SHARE_ROOT,"web");
     }
+
+    die "Can't locate Jifty share root!" unless defined $SHARE_ROOT;
     return ($SHARE_ROOT);
 }
 


More information about the Jifty-commit mailing list