--- a/lib/Fops.pm Tue Aug 02 16:02:54 2011 +0200
+++ b/lib/Fops.pm Tue Aug 02 17:12:48 2011 +0200
@@ -1,7 +1,10 @@
package Fops;
+use 5.010;
use strict;
use warnings;
use Carp;
+use base qw(Exporter);
+our @EXPORT_OK = qw(_path);
our $VERSION = "0.1";
@@ -17,12 +20,38 @@
sub type { shift->{type} }
sub pwd { shift->{cwd} }
+sub root { shift->{root} }
sub cd {
my $self = shift;
croak "method `cd' needs implementation in " . ref $self;
}
+sub stat {
+ my $self = shift;
+ croak "method `stat` needs implementation in " . ref $self;
+}
+
+sub _path {
+ my @parts = grep {length} split /\// => join "/", @_;
+ my @path;
+
+ while (@parts) {
+ my $_;
+ given ($_ = pop @parts) {
+ when (".") { }
+ when ("..") { pop @parts }
+ default { unshift @path => $_ }
+ }
+ }
+
+ #$self->{cwd} =~ s{/\.(?=/|$)}{}g; # dots
+ #$self->{cwd} =~ s{/[^/]+/\.\.(?=/|$)}{}g;
+ #$self->{cwd} =~ s{/+}{/}g;
+
+ return "/" . join "/" => @path;
+}
+
1
__END__