lib/Fops/native.pm
changeset 2 1bd03bcf26b4
parent 1 9416fc33d2a0
--- a/lib/Fops/native.pm	Tue Aug 02 16:02:54 2011 +0200
+++ b/lib/Fops/native.pm	Tue Aug 02 17:12:48 2011 +0200
@@ -5,6 +5,8 @@
 use Carp;
 use Cwd qw(abs_path cwd);
 use base qw(Fops);
+use File::Path ();
+use Fops qw(_path);
 
 our $VERSION = "0.0";
 
@@ -25,24 +27,27 @@
     $dst = $self->{cwd} .= "/$dst"
       if $dst !~ /^\//;
 
-    my @path;
-    my @parts = grep {length} split /\// => $dst;
-    while (@parts) {
-        my $_;
-        given ($_ = pop @parts) {
-            when (".")  { }
-            when ("..") { pop @parts }
-            default { unshift @path => $_ }
-        }
-    }
+    $self->{cwd} = _path($dst);
+}
+
+sub stat {
+    my $self = shift;
+    stat(_path($self->{root}, shift));
+}
 
-    #$self->{cwd} =~ s{/\.(?=/|$)}{}g;	# dots
-    #$self->{cwd} =~ s{/[^/]+/\.\.(?=/|$)}{}g;
-    #$self->{cwd} =~ s{/+}{/}g;
+sub is_dir {
+    my $self = shift;
+    -d _path($self->{root}, shift);
+}
 
-    $self->{cwd} = "/" . join "/" => @path;
+sub is_file {
+    my $self = shift;
+    -f _path($self->{root}, shift);
+}
 
-    $self;
+sub mkpath {
+    my $self = shift;
+    File::Path::mkpath([ map { _path($self->{root}, $_) } @_ ]);
 }
 
 1;