Tie::CountLoop - Have a counter looping in a scalar with min max and increment value.


Tie-CountLoop documentation  | view source Contained in the Tie-CountLoop distribution.

Index


NAME

Top

Tie::CountLoop - Have a counter looping in a scalar with min max and increment value.

SYNOPSIS

Top

	use Tie::CountLoop;

	tie my $counter , 'Tie::CountLoop',15 ,-1 ,15 ,7 ,0;

	my $t = tied $counter;
	$t->increment( 1 );

	for ( 1 .. 20 )
	{
		print "  <<$counter>> <$_>  \n";
	}
        ## stop temporary the auto increment behaviour
	$t->auto( 0 );
	for ( 1 .. 20 )
	{
		print "  <<$counter>> <$_>  \n";
	}

	or

	## the default value allow this 
        ## it is the same as my $counter , 'Tie::CountLoop', 0 , 1 , ( 2**32 ) - 1 , 0 , 0;
	use Tie::CountLoop;
	tie my $counter , 'Tie::CountLoop';

	for ( 1 .. 20 )
	{
		print "  <<$counter>> <$_>  \n";
	}

        ## How to toggle a binary flag after 5 access to the valriable
	my $t1 = tie my $counter1 , 'Tie::CountLoop',0,1,1,0,5;

	for ( 1 .. 20 )
	{
		print "  <<$counter1>> <$_>  \n";
	}




DESCRIPTION

Top

Tie::CountLoop allows you to tie a scalar in such a way that it increments each time it is used. The tie takes 4 optionals extra arguments.

Argument 1: is the start value of the counter. (default =0).

Argument 2: is the increment value. (default = 1).

Argument 3: is the maximal value. When this value is reached, the counter is set to the minimal value (default = (2**32) -1)

Argument 4: is the minimal value. When this value is reached if we used an negative increment value, the counter is set to the maximal value (default = 0)

Argument 5: is a skipping value. If set to 3, means that you could access the counter 3 time without incrementing (default=1)

METHODS

Top

The Tie::CountLoop provide 7 extra methods.

auto

which change the autoincrement behaviour. With 1, the counter is incremented when accessed. With 0, the counter is NOT incremented when accessed.

toggle

which toggle the autoincrement behaviour (on and off and again).

value

get/set the value of the counter without incrementing the counter.

max

get/set the maximal value for the counter.

min

get/set the minimal value for the counter.

increment

get/set the increment value for the counter.

skip

get/set the skipping value for the counter.

REVISION HISTORY

Top



    Revision 1.7  2008/09/25 15:52:27  fabrice
    add extra methods to access all parameter of the counter
    clean the code for auto and toggle to allow instantiation by object 




    Revision 1.6  2006/11/14 13:31:56  fabrice
    fix default value for skip parameter

    Revision 1.5  2006/02/03 10:42:55  fabrice
    add README file

    Revision 1.4  2006/02/03 10:21:37  fabrice
    correct code for maximal and minimal value after increment

    Revision 1.3  2006/01/26 19:31:20  fabrice
    add method 'retrieve'

    Revision 1.2  2006/01/26 15:53:56  fabrice
    pod created

    Revision: 1.1 start project




AUTHOR

Top

This package was written by Dulaunoy Fabrice <fabrice@dulaunoy.com>.

COPYRIGHT and LICENSE

Top


Tie-CountLoop documentation  | view source Contained in the Tie-CountLoop distribution.