lib/Fops.pm
changeset 2 1bd03bcf26b4
parent 1 9416fc33d2a0
equal deleted inserted replaced
1:9416fc33d2a0 2:1bd03bcf26b4
     1 package Fops;
     1 package Fops;
       
     2 use 5.010;
     2 use strict;
     3 use strict;
     3 use warnings;
     4 use warnings;
     4 use Carp;
     5 use Carp;
       
     6 use base qw(Exporter);
       
     7 our @EXPORT_OK = qw(_path);
     5 
     8 
     6 our $VERSION = "0.1";
     9 our $VERSION = "0.1";
     7 
    10 
     8 sub new {
    11 sub new {
     9     my $class = ref $_[0] ? ref shift : shift;
    12     my $class = ref $_[0] ? ref shift : shift;
    15     return "Fops::$implementation"->new(@_);
    18     return "Fops::$implementation"->new(@_);
    16 }
    19 }
    17 
    20 
    18 sub type { shift->{type} }
    21 sub type { shift->{type} }
    19 sub pwd  { shift->{cwd} }
    22 sub pwd  { shift->{cwd} }
       
    23 sub root { shift->{root} }
    20 
    24 
    21 sub cd {
    25 sub cd {
    22     my $self = shift;
    26     my $self = shift;
    23     croak "method `cd' needs implementation in " . ref $self;
    27     croak "method `cd' needs implementation in " . ref $self;
       
    28 }
       
    29 
       
    30 sub stat {
       
    31     my $self = shift;
       
    32     croak "method `stat` needs implementation in " . ref $self;
       
    33 }
       
    34 
       
    35 sub _path {
       
    36     my @parts = grep {length} split /\// => join "/", @_;
       
    37     my @path;
       
    38 
       
    39     while (@parts) {
       
    40         my $_;
       
    41         given ($_ = pop @parts) {
       
    42             when (".")  { }
       
    43             when ("..") { pop @parts }
       
    44             default { unshift @path => $_ }
       
    45         }
       
    46     }
       
    47 
       
    48     #$self->{cwd} =~ s{/\.(?=/|$)}{}g;	# dots
       
    49     #$self->{cwd} =~ s{/[^/]+/\.\.(?=/|$)}{}g;
       
    50     #$self->{cwd} =~ s{/+}{/}g;
       
    51 
       
    52     return "/" . join "/" => @path;
    24 }
    53 }
    25 
    54 
    26 1
    55 1
    27 __END__
    56 __END__
    28 
    57