Bit-FlipFlop

 view release on metacpan or  search on metacpan

FlipFlop.pm  view on Meta::CPAN


Maintaining one bit of state in a program can be a very useful thing. A
Bit::FlipFlop does just that. The flip flop can be false (represented
by the integer 0) or true (1).

=head2 Overview

The initial state of a flip flop is false.  It has an opportunity
to change state during each call to the C<test> method.  

Two callbacks are provided at flip flop construction time, C<set> and
C<reset>. One or both of these callbacks may be evaluated when the
C<test> method is called. The callbacks are evaluated in scalar context,
and their return value is interpreted as a boolean.

While false, the flip flop evaluates the C<set> callback at each call to
the C<test> method. If the C<set> callback returns a true value, the
flip flop flips state to true. While true, the flip flop evaluates the
C<reset> callback when C<test> is called. If C<reset> returns a true
value, then the flip flop flops back into the false state. 

=head2 Edge Conditions and More

FlipFlop.pm  view on Meta::CPAN

=item C<new>

  $f = Bit::FlipFlop->new(set   => sub {$. == 15},
                          reset => sub {$. == 20},
                          simultaneous_edges => 0);

The C<new> method creates a new Bit::FlipFlop object.  A newly created 
flip flop's state is always false.  

The C<set> and C<reset> arguments are required. They are sub refs that
are used for callbacks to test for setting or resetting the flip flop.

C<simultaneous_edges> is an optional argument that defaults to 1
(true) if unspecified. This argument governs whether the flip flop
may look for a leading edge and trailing edge within a single call to
the C<test> method.  

Normally when a flip flop is in the false state, it tests for the
C<set> condition. Should that condition be true, then the flip flop
will change states to true. There are two possible behaviors at this
point. The flip flop could either evaluate the C<reset> condition to



( run in 1.064 second using v1.01-cache-2.11-cpan-9b1e4054eb1 )