[Jifty-commit] r572 - jifty/trunk/lib/Jifty

jifty-commit at lists.jifty.org jifty-commit at lists.jifty.org
Sun Feb 12 15:33:53 EST 2006


Author: jesse
Date: Sun Feb 12 15:33:49 2006
New Revision: 572

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

Log:
 r23607 at truegrounds:  jesse | 2006-02-12 14:36:28 -0500
 * extracted make_path from Jifty::Action::Devel::FileEditor, so we can use it to create var directories
 


Modified: jifty/trunk/lib/Jifty/Action/Devel/FileEditor.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Action/Devel/FileEditor.pm	(original)
+++ jifty/trunk/lib/Jifty/Action/Devel/FileEditor.pm	Sun Feb 12 15:33:49 2006
@@ -74,7 +74,9 @@
 sub take_action {
     my $self = shift;
     my $dest  = $self->{'write_to'};
-    $self->_make_path($dest);
+    my @dirs = File::Spec->splitdir( $dest );
+    pop @dirs; # discard filename. we only want to make the directory ;)
+    Jifty::Util->make_path( File::Spec->catdir(@dirs));
     my $writehandle = IO::File->new();
     $writehandle->open(">$dest") || die "Couldn't open $dest for writing: ".$!;
     $writehandle->print( $self->argument_value('content')) || die " Couldn't write to $dest: ".$!;
@@ -83,21 +85,5 @@
 }
 
 
-sub _make_path {
-    my $self = shift;
-    my $whole_path = shift;
-    my @dirs = File::Spec->splitdir( $whole_path );
-    pop @dirs; # get the filename ripped off the directory
-    my $path ='';
-    foreach my $dir ( @dirs) {
-        $path = File::Spec->catdir($path, $dir);
-        if (-d $path) { next }
-        if (-w $path) { die "$path not writable"; }
-        
-        
-        mkdir($path) || die "Couldn't create directory $path: $!";
-    }
-
-}
 
 1;

Modified: jifty/trunk/lib/Jifty/Util.pm
==============================================================================
--- jifty/trunk/lib/Jifty/Util.pm	(original)
+++ jifty/trunk/lib/Jifty/Util.pm	Sun Feb 12 15:33:49 2006
@@ -45,6 +45,7 @@
     return (File::Spec->rel2abs($dir));   
 }
 
+
 =head2 share_root
 
 Returns the 'share' directory of the installed Jifty module.  This is
@@ -116,9 +117,32 @@
     return pop @root;
 }
 
+=head2 make_path PATH
+
+When handed a directory, creates that directory, starting as far up the 
+chain as necessary. (This is what 'mkdir -p' does in your shell)
+
+=cut
+
+sub make_path {
+    my $self = shift;
+    my $whole_path = shift;
+    my @dirs = File::Spec->splitdir( $whole_path );
+    my $path ='';
+    foreach my $dir ( @dirs) {
+        $path = File::Spec->catdir($path, $dir);
+        if (-d $path) { next }
+        if (-w $path) { die "$path not writable"; }
+        
+        
+        mkdir($path) || die "Couldn't create directory $path: $!";
+    }
+
+}
+
 =head1 AUTHOR
 
-Various folks at BestPractical Solutions, LLC.
+Various folks at Best Practical Solutions, LLC.
 
 =cut
 


More information about the Jifty-commit mailing list