# HG changeset patch # User Heiko Schlittermann (JUMPER) # Date 1312237260 -7200 # Node ID 21a87c5f86e46b9f3538be1ad08980e964baae2f initial diff -r 000000000000 -r 21a87c5f86e4 Build.PL --- /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(); diff -r 000000000000 -r 21a87c5f86e4 lib/Fops.pm --- /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 + +=cut diff -r 000000000000 -r 21a87c5f86e4 lib/Fops/native.pm --- /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; diff -r 000000000000 -r 21a87c5f86e4 t/000-module.t --- /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;