summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorfukachan <fukachan>2001-02-01 12:47:42 +0000
committerfukachan <fukachan>2001-02-01 12:47:42 +0000
commitc0b934e1e408f84362ec41cdea5899fa2b0a0ebe (patch)
treef4eaa494d4e2083287a4b81a63109576bfa36692
parent5c2ac1982cba4bee94de17d63c9399e99143a2bc (diff)
downloadfml8-c0b934e1e408f84362ec41cdea5899fa2b0a0ebe.tar.gz
fml8-c0b934e1e408f84362ec41cdea5899fa2b0a0ebe.tar.bz2
fml8-c0b934e1e408f84362ec41cdea5899fa2b0a0ebe.zip
FML::Utils::copy() is a wrapper, which uses IO::File::Atomic.
-rw-r--r--fml/lib/FML/Utils.pm19
-rw-r--r--regress/base/copy.pl18
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;