From 814599b13f90ab9771f5e22f0eac35e2d987deee Mon Sep 17 00:00:00 2001 From: Mike Taylor Date: Mon, 8 Dec 2014 16:56:34 +0000 Subject: [PATCH] Some code, not complete. --- lib/IndexData/Utils/PersistentCounter.pm | 34 ++++++++++++++++++++++++++++++ 1 file changed, 34 insertions(+) diff --git a/lib/IndexData/Utils/PersistentCounter.pm b/lib/IndexData/Utils/PersistentCounter.pm index 5779261..95e18bc 100644 --- a/lib/IndexData/Utils/PersistentCounter.pm +++ b/lib/IndexData/Utils/PersistentCounter.pm @@ -4,4 +4,38 @@ use 5.018002; use strict; use warnings; +use IO::File; + + +sub new { + my $class = shift(); + my($file, $create) = @_; + + if (! -f $file) { + return undef if !$create; + # ### There is a bit of a race condition here, but it's not + # something that's going to crop up in real life. + my $fh = new IO::File(">$file") || return undef; + $fh->print("1\n"); + $fh->close() or return undef; + } + + my $this = bless { + file => $file, + }, $class; + + return $this; +} + + +sub next { + my $this = shift(); +} + + +sub delete { + my $this = shift(); +} + + 1; -- 1.7.10.4