ControlBreak

 view release on metacpan or  search on metacpan

README  view on Meta::CPAN


    To simplify this situation, method test_and_do() can be used in place of
    test() and continue().

FIELDS
  iteration
    A readonly field that provides the current iteration number.

    This can be useful if you are doing an final processing after an
    iteration loop has ended. In the event that the data stream is empty and
    there were no iterations, then you can condition your final processing
    on iteration > 0.

    Note that the interation field is incremented by test() (or
    test_and_do()). Therefore, when called within a loop it is effectively
    zero-based if referenced within the iteration block before test() is
    invoked, and then one-based after test().

  level_names
    A readonly field that provides a list of the level names that were
    provided as arguments to new().

README  view on Meta::CPAN

            $cb->test_and_do(
                $control1,
                $control2,
                $cb->iteration == $list_of_lists - 1,
                $sub_totals
            );
        }

  reset
    Resets the state of the object so it can be used again for another set
    of iterations using the same number and type of controls establish when
    the object was instantiated with new(). Any comparisons that were
    subsequently modified are retained.

  test ( $var1 [, $var2 ]... )
    Submits the control variables for testing against the values from the
    previous iteration.

    Testing is done in reverse order, from highest to lowest (major to
    minor) and stops once a change is detected. Where it stops determines
    the control break level. For example, if $var2 changed, method levelnum

lib/ControlBreak.pm  view on Meta::CPAN

class   ControlBreak;

# althouth Object::Pad allows a version argument on the class statement
# we can't use it because we want Dist::Zilla to set it from the dist.ini
# version -- and that requires it to be an 'our' statement.
our $VERSION = 'v0.22.244';

use Carp            qw(croak);

# public attributes
field $iteration    :reader     { 0 };  # [0] counts iterations
field @level_names  :reader;            # [1] list of level names

# private attributes
field $_num_levels;                     # [2] the number of control levels
field %_levname                 {   };  # [3] map of levidx to levname
field %_levidx                  {   };  # [4] map of lenname to levidx
field %_comp_op;                        # [5] comparison operators
field %_fcomp;                          # [6] comparison functions
field $_test_levelnum           { 0 };  # [7] last level returned by test()
field $_test_levelname          { '' }; # [8] last level returned by test()

lib/ControlBreak.pm  view on Meta::CPAN

field $_continue_count          { 0 };  # [11] the number of types continue was called

=head1 FIELDS

=head2 iteration

A readonly field that provides the current iteration number.

This can be useful if you are doing an final processing after an
iteration loop has ended.  In the event that the data stream is empty
and there were no iterations, then you can condition your final
processing on iteration > 0.

Note that the B<interation> field is incremented by B<test()> (or
B<test_and_do()>). Therefore, when called within a loop it is
effectively zero-based if referenced within the iteration block
before B<test()> is invoked, and then one-based after B<test()>.

=head2 level_names

A readonly field that provides a list of the level names that were

lib/ControlBreak.pm  view on Meta::CPAN


=cut

method level_numbers () {
    return 1 .. $_num_levels;
}

=head2 reset

Resets the state of the object so it can be used again for another
set of iterations using the same number and type of controls
establish when the object was instantiated with B<new()>.  Any
comparisons that were subsequently modified are retained.

=cut

method reset () {   ## no critic [ProhibitParensWithBuiltins]
    $iteration          = 0;
    $_continue_count    = 0;
    $_test_levelnum     = 0;
    $_test_levelname    = 0;

t/10_end_of_list.t  view on Meta::CPAN

    my $cb = ControlBreak->new( qw( District Country EOL ) );


    my @totals;

    # set up some level number variables for convenient indexing into @totals
    my ($L1, $L2, $L3) = $cb->level_numbers;

    my @data = <DATA>;

    # iterations begin at zero and are incremented during the call
    # to test() -- which is called within test_and_do().  So, the
    # iteration number of the last value in the list -- for the
    # purpose of comparison to the iteration number before a test
    # method is called -- is the list length minus one.
    my $last_iter = @data - 1;

    foreach my $line (@data) {
        chomp $line;

        my ($country, $district, $city, $population) = split ',', $line;



( run in 0.563 second using v1.01-cache-2.11-cpan-96521ef73a4 )