r1890@llin: dpavlin | 2009-05-29 20:09:47 +0200
authorDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 29 May 2009 18:15:57 +0000 (18:15 +0000)
committerDobrica Pavlinusic <dpavlin@rot13.org>
Fri, 29 May 2009 18:15:57 +0000 (18:15 +0000)
 WebPAC::Path provides mk_base_path helper function

git-svn-id: svn+ssh://mjesec/home/dpavlin/svn/webpac2/trunk@1202 07558da8-63fa-0310-ba24-9fe276d99e06

lib/WebPAC/Path.pm [new file with mode: 0644]
t/1-path.t [new file with mode: 0755]

diff --git a/lib/WebPAC/Path.pm b/lib/WebPAC/Path.pm
new file mode 100644 (file)
index 0000000..541b4da
--- /dev/null
@@ -0,0 +1,27 @@
+package WebPAC::Path;
+
+use strict;
+use warnings;
+
+use Exporter 'import';
+our @EXPORT = qw/
+       mk_base_path
+/;
+
+use File::Path;
+
+sub mk_base_path {
+       my ($path) = @_;
+
+       my $base_path = $path;
+       $base_path =~ s{/[^/]+$}{};
+
+       if ( ! -e $base_path ) {
+               mkpath $base_path;
+               warn "# created $base_path\n";
+       }
+
+       return -e $base_path;
+}
+
+1;
diff --git a/t/1-path.t b/t/1-path.t
new file mode 100755 (executable)
index 0000000..01e3784
--- /dev/null
@@ -0,0 +1,19 @@
+#!/usr/bin/perl
+
+use warnings;
+use strict;
+
+use Test::More tests => 5;
+
+use lib 'lib';
+
+BEGIN {
+       use_ok( 'WebPAC::Path' );
+}
+
+my $path = '/tmp/webpac-test-$$/file';
+
+ok( mk_base_path( $path ), 'mk_base_path' );
+ok( open(my $fh, '>', $path), "create $path" );
+ok( -e $path, "exists $path" );
+ok( unlink($path), 'unlink' );