diff options
| -rw-r--r-- | fml/lib/FML/Utils.pm | 19 | ||||
| -rw-r--r-- | regress/base/copy.pl | 18 |
2 files changed, 30 insertions, 7 deletions
diff --git a/fml/lib/FML/Utils.pm b/fml/lib/FML/Utils.pm index bb356b70..892942e7 100644 --- a/fml/lib/FML/Utils.pm +++ b/fml/lib/FML/Utils.pm @@ -16,7 +16,7 @@ use Carp; require Exporter; @ISA = qw(Exporter); -@EXPORT_OK = qw(mkdirhier touch search_program); +@EXPORT_OK = qw(mkdirhier touch search_program copy); =head1 NAME @@ -142,4 +142,21 @@ sub search_program } + +# wrappers for delegation :-) +sub copy +{ + my ($src, $dst) = @_; + my $pkg = 'IO::File::Atomic'; + + eval qq{ require $pkg; $pkg->import();}; + unless ($@) { + $pkg->new->copy($src, $dst); + } + else { + undef; + } +} + + 1; diff --git a/regress/base/copy.pl b/regress/base/copy.pl index 049ff5ba..9708e2a5 100644 --- a/regress/base/copy.pl +++ b/regress/base/copy.pl @@ -9,12 +9,18 @@ # $FML$ # -use IO::File::Atomic; +unless (@ARGV) { + use FML::Utils qw(copy); + copy("main.cf", "/tmp/main.cf"); +} +else { + my ($src, $dst) = @ARGV; -($src, $dst) = @ARGV; -print "IO::File::Atomic->copy($src, $dst);\n"; -print "sleep 3;\n"; -sleep 3; -my $status = IO::File::Atomic->copy($src, $dst) || die("fail to copy"); + use IO::File::Atomic; + print "IO::File::Atomic->copy($src, $dst);\n"; + print "sleep 3;\n"; + sleep 3; + my $status = IO::File::Atomic->copy($src, $dst) || die("fail to copy"); +} exit 0; |
