Linux and UNIX Man Pages

Linux & Unix Commands - Search Man Pages

file::counterfile(3pm) [debian man page]

CounterFile(3pm)					User Contributed Perl Documentation					  CounterFile(3pm)

NAME
File::CounterFile - Persistent counter class SYNOPSIS
use File::CounterFile; $c = File::CounterFile->new("COUNTER", "aa00"); $id = $c->inc; open(F, ">F$id"); DESCRIPTION
This module implements a persistent counter class. Each counter is represented by a separate file in the file system. File locking is applied, so multiple processes can attempt to access a counter simultaneously without risk of counter destruction. You give the file name as the first parameter to the object constructor ("new"). The file is created if it does not exist. If the file name does not start with "/" or ".", then it is interpreted as a file relative to $File::CounterFile::DEFAULT_DIR. The default value for this variable is initialized from the environment variable "TMPDIR", or /usr/tmp if no environment variable is defined. You may want to assign a different value to this variable before creating counters. If you pass a second parameter to the constructor, it sets the initial value for a new counter. This parameter only takes effect when the file is created (i.e. it does not exist before the call). When you call the "inc()" method, you increment the counter value by one. When you call "dec()", the counter value is decremented. In both cases the new value is returned. The "dec()" method only works for numerical counters (digits only). You can peek at the value of the counter (without incrementing it) by using the "value()" method. The counter can be locked and unlocked with the "lock()" and "unlock()" methods. Incrementing and value retrieval are faster when the counter is locked, because we do not have to update the counter file all the time. You can query whether the counter is locked with the "locked()" method. There is also an operator overloading interface to the File::CounterFile object. This means that you can use the "++" operator for incrementing and the "--" operator for decrementing the counter, and you can interpolate counters directly into strings. COPYRIGHT
Copyright (c) 1995-1998,2002,2003 Gisle Aas. All rights reserved. This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself. AUTHOR
Gisle Aas <gisle@aas.no> perl v5.10.0 2004-01-23 CounterFile(3pm)

Check Out this Related Man Page

Moose::Meta::Attribute::Native::Trait::Counter(3)	User Contributed Perl Documentation	 Moose::Meta::Attribute::Native::Trait::Counter(3)

NAME
Moose::Meta::Attribute::Native::Trait::Counter - Helper trait for Int attributes which represent counters VERSION
version 2.0604 SYNOPSIS
package MyHomePage; use Moose; has 'counter' => ( traits => ['Counter'], is => 'ro', isa => 'Num', default => 0, handles => { inc_counter => 'inc', dec_counter => 'dec', reset_counter => 'reset', }, ); my $page = MyHomePage->new(); $page->inc_counter; # same as $page->counter( $page->counter + 1 ); $page->dec_counter; # same as $page->counter( $page->counter - 1 ); my $count_by_twos = 2; $page->inc_counter($count_by_twos); DESCRIPTION
This trait provides native delegation methods for counters. A counter can be any sort of number (integer or not). The delegation methods allow you to increment, decrement, or reset the value. DEFAULT TYPE
If you don't provide an "isa" value for your attribute, it will default to "Num". PROVIDED METHODS
o set($value) Sets the counter to the specified value and returns the new value. This method requires a single argument. o inc o inc($arg) Increases the attribute value by the amount of the argument, or by 1 if no argument is given. This method returns the new value. This method accepts a single argument. o dec o dec($arg) Decreases the attribute value by the amount of the argument, or by 1 if no argument is given. This method returns the new value. This method accepts a single argument. o reset Resets the value stored in this slot to its default value, and returns the new value. BUGS
See "BUGS" in Moose for details on reporting bugs. AUTHOR
Moose is maintained by the Moose Cabal, along with the help of many contributors. See "CABAL" in Moose and "CONTRIBUTORS" in Moose for details. COPYRIGHT AND LICENSE
This software is copyright (c) 2012 by Infinity Interactive, Inc.. This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself. perl v5.16.2 2012-09-19 Moose::Meta::Attribute::Native::Trait::Counter(3)
Man Page