X-Git-Url: http://git.indexdata.com/cgi-bin?a=blobdiff_plain;ds=sidebyside;f=lib%2FIndexData%2FUtils%2FPersistentCounter.pm;h=95e18bc01ebb0972d58f19d43f5217bdaf4fc654;hb=814599b13f90ab9771f5e22f0eac35e2d987deee;hp=57792619f9f882d77a6dd92eb869f3f636615284;hpb=22a00ad235c759af2087b7912e613fff09ae9f54;p=perl-indexdata-utils.git 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;