[Bps-public-commit] r11089 - Shipwright/trunk/lib/Shipwright

sunnavy at bestpractical.com sunnavy at bestpractical.com
Tue Mar 18 04:45:45 EDT 2008


Author: sunnavy
Date: Tue Mar 18 04:45:44 2008
New Revision: 11089

Modified:
   Shipwright/trunk/lib/Shipwright/Util.pm

Log:
added share_root sub

Modified: Shipwright/trunk/lib/Shipwright/Util.pm
==============================================================================
--- Shipwright/trunk/lib/Shipwright/Util.pm	(original)
+++ Shipwright/trunk/lib/Shipwright/Util.pm	Tue Mar 18 04:45:44 2008
@@ -4,6 +4,9 @@
 use strict;
 use Carp;
 use IPC::Run3;
+use UNIVERSAL::require;
+use File::Spec;
+our ( $SHIPWRIGHT_ROOT, $SHARE_ROOT );
 
 BEGIN {
     local $@;
@@ -65,6 +68,50 @@
 
 }
 
+=head2 shipwright_root
+
+Returns the root directory that Shipwright has been installed into.
+Uses %INC to figure out where Shipwright.pm is.
+
+=cut
+
+sub shipwright_root {
+    my $self = shift;
+
+    unless ($SHIPWRIGHT_ROOT) {
+        my $dir = (File::Spec->splitpath($INC{"Shipwright.pm"}))[1];
+        $SHIPWRIGHT_ROOT = File::Spec->rel2abs($dir);
+    }
+
+    return ($SHIPWRIGHT_ROOT);
+}
+
+=head2 share_root
+
+Returns the 'share' directory of the installed Shipwright module. This is
+currently only used to store the initial files in vessel.
+
+=cut
+
+sub share_root {
+    my $self = shift;
+    
+    File::ShareDir->require;
+    $SHARE_ROOT ||=  eval { File::Spec->rel2abs(
+            File::ShareDir::module_dir('Shipwright') )};
+
+    unless ( $SHARE_ROOT && -d $SHARE_ROOT) {
+        # XXX TODO: This is a bloody hack
+        # Module::Install::Share and File::ShareDir don't play nicely
+        # together
+        my @root = File::Spec->splitdir($self->shipwright_root); 
+        $root[-1] = 'share'; # replace 'lib' to 'share'
+        $SHARE_ROOT = File::Spec->catdir(@root);
+    }
+    return ($SHARE_ROOT);
+
+}
+
 1;
 
 __END__



More information about the Bps-public-commit mailing list