initial
authorHeiko Schlittermann (JUMPER) <hs@schlittermann.de>
Tue, 02 Aug 2011 00:21:00 +0200
changeset 0 21a87c5f86e4
child 1 9416fc33d2a0
initial
Build.PL
lib/Fops.pm
lib/Fops/native.pm
t/000-module.t
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/Build.PL	Tue Aug 02 00:21:00 2011 +0200
@@ -0,0 +1,8 @@
+use strict;
+use warnings;
+use Module::Build;
+
+Module::Build->new(
+    dist_name => "Fops",
+    dist_version => "0.0",
+)->create_build_script();
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/Fops.pm	Tue Aug 02 00:21:00 2011 +0200
@@ -0,0 +1,51 @@
+package Fops;
+use strict;
+use warnings;
+use Carp;
+
+sub new {
+    my $class = ref $_[0] ? ref shift : shift;
+    my $implementation = shift;
+    eval "require Fops::$implementation";
+    return "Fops::$implementation"->new(@_);
+}
+
+sub type { shift->{type} }
+
+sub cd {
+    my $self = shift;
+    croak "method `cd' needs implementation in ".ref $self;
+}
+
+
+1
+__END__
+
+=head1 NAME
+    
+    Fops - file operations
+
+=head1 SYNOPSIS
+
+    use Fops;
+
+    $fops = Fops->new(native => $root);
+
+    $fops->cd("dir");
+    $fops->put($src => $dst);
+    $fops->rename($from => $to);
+    $fops->stat($src);
+    $fops->get($src => $dst);
+
+    $src = $fops->get($src);
+
+=head1 DESCRIPTION
+
+A simple abstraction for some file operations.
+To be of real use, this module needs helpers.
+
+=head1 SEE ALSO
+
+L<Fops::native(3)>
+
+=cut
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/Fops/native.pm	Tue Aug 02 00:21:00 2011 +0200
@@ -0,0 +1,37 @@
+package Fops::native;
+use strict;
+use warnings;
+use Carp;
+use Cwd ();
+use base qw(Fops);
+
+sub new {
+    my $class = ref $_[0] ? ref shift : shift;
+    my $self = bless {} => $class;
+    $self->{root} = shift;
+    $self->{type} = "native";
+
+    return $self;
+}
+
+sub cd {
+    my $self = shift;
+    my $dst = shift;
+
+    if ($dst =~ /\//) {
+	$dst = Cwd::abs_path "$self->{root}/$dst";
+    }
+    else {
+	$dst = Cwd::abs_path(cwd . "/$dst");
+    }
+
+    croak "invalid destination $dst" 
+	if not $dst =~ /^$self->{root\/}/;
+
+    chdir $dst or croak "Can't chdir to $dst: $!";
+}
+
+sub pwd { cwd }
+
+
+1;
--- /dev/null	Thu Jan 01 00:00:00 1970 +0000
+++ b/t/000-module.t	Tue Aug 02 00:21:00 2011 +0200
@@ -0,0 +1,17 @@
+use strict;
+use warnings;
+use Test::More;
+
+use_ok "Fops";
+
+my $fops = Fops->new(native => "/tmp");
+isa_ok($fops => "Fops");
+isa_ok($fops => "Fops::native");
+is($fops->type => "native", "type is native");
+
+foreach (qw(type pwd cd)) {
+    can_ok $fops => $_;
+}
+
+
+done_testing;