[SCM] libpath-tiny-perl Debian packaging branch, master, updated. debian/0.020-1-13-g8895609

Keedi Kim keedi.k at gmail.com
Tue May 28 16:27:19 UTC 2013


The following commit has been merged in the master branch:
commit 7743eac52b33b8bbfd801809dbad7eb553f58d39
Author: Keedi Kim <keedi at cpan.org>
Date:   Mon May 27 13:03:57 2013 +0900

    Support touch to take a single epoch seconds

diff --git a/lib/Path/Tiny.pm b/lib/Path/Tiny.pm
index acc4b99..6982a7f 100644
--- a/lib/Path/Tiny.pm
+++ b/lib/Path/Tiny.pm
@@ -978,9 +978,11 @@ sub stringify { $_[0]->[PATH] }
 =method touch
 
     path("foo.txt")->touch;
+    path("foo.txt")->touch($epoch_secs);
 
 Like the Unix C<touch> utility.  Creates the file if it doesn't exist, or else
-changes the modification and access times to the current time.
+changes the modification and access times to the current time.  If the first
+argument is the epoch seconds then it will be used.
 
 Returns the path object so it can be easily chained with spew:
 
@@ -989,15 +991,14 @@ Returns the path object so it can be easily chained with spew:
 =cut
 
 sub touch {
-    my ($self) = @_;
-    if ( -e $self->[PATH] ) {
-        my $now = time();
-        utime $now, $now, $self->[PATH] or _throw( 'utime', [ $now, $now, $self->[PATH] ] );
-    }
-    else {
+    my ( $self, $epoch ) = @_;
+    if ( ! -e $self->[PATH] ) {
         my $fh = $self->openw;
         close $fh or _throw( 'close', [$fh] );
     }
+    $epoch = defined($epoch) ? $epoch : time();
+    utime $epoch, $epoch, $self->[PATH]
+        or _throw( 'utime', [ $epoch, $epoch, $self->[PATH] ] );
     return $self;
 }
 
diff --git a/t/filesystem.t b/t/filesystem.t
index d597b9c..863e741 100644
--- a/t/filesystem.t
+++ b/t/filesystem.t
@@ -61,9 +61,12 @@ ok $dir->is_dir, "It's a directory!";
 $file = $dir->child('foo.x');
 $file->touch;
 ok -e $file;
-utime time - 10, time - 10, $file;
+my $epoch = time - 10;
+utime $epoch, $epoch, $file;
 $file->touch;
-ok( $file->stat->mtime > ( time - 10 ), "touch sets utime" );
+ok( $file->stat->mtime > $epoch, "touch sets utime as current time" );
+$file->touch($epoch);
+ok( $file->stat->mtime == $epoch, "touch sets utime as 10 secs before" );
 
 {
     my @files = $dir->children;

-- 
libpath-tiny-perl Debian packaging



More information about the Pkg-perl-cvs-commits mailing list