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
--- /dev/null
+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;
--- /dev/null
+#!/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' );