File Coverage

blib/lib/Iterator/Breathe.pm
Criterion Covered Total %
statement 26 29 89.6
branch 7 12 58.3
condition n/a
subroutine 6 6 100.0
pod 1 1 100.0
total 40 48 83.3


line stmt bran cond sub pod time code
1             package Iterator::Breathe;
2             our $AUTHORITY = 'cpan:GENE';
3              
4             # ABSTRACT: Iterate a counter up and back
5              
6             our $VERSION = '0.0100';
7              
8 1     1   577 use Carp qw( croak );
  1         2  
  1         47  
9 1     1   478 use Moo;
  1         9710  
  1         4  
10 1     1   1236 use Scalar::Util qw( looks_like_number );
  1         2  
  1         45  
11              
12 1     1   413 use strictures 2;
  1         1399  
  1         33  
13 1     1   581 use namespace::clean;
  1         10228  
  1         5  
14              
15              
16             has direction => (
17             is => 'rw',
18             isa => sub { croak "$_[0] is not a boolean" unless $_[0] =~ /^[01]$/ },
19             default => sub { 1 },
20             );
21              
22              
23             has i => (
24             is => 'rw',
25             isa => sub { croak "$_[0] is not a number" unless looks_like_number( $_[0] ) },
26             default => sub { 0 },
27             );
28              
29              
30             has bottom => (
31             is => 'rw',
32             isa => sub { croak "$_[0] is not a number" unless looks_like_number( $_[0] ) },
33             default => sub { 0 },
34             );
35              
36              
37             has top => (
38             is => 'rw',
39             isa => sub { croak "$_[0] is not an integer" unless $_[0] =~ /^\d+$/ },
40             default => sub { 100 },
41             );
42              
43              
44             has verbose => (
45             is => 'ro',
46             isa => sub { croak "$_[0] is not a boolean" unless $_[0] =~ /^[01]$/ },
47             default => sub { 0 },
48             );
49              
50              
51             sub iterate {
52 200     200 1 86676 my ($self) = @_;
53              
54 200 50       555 print $self->i, "\n" if $self->verbose;
55              
56 200 100       3880 if ( $self->direction ) {
57 101 100       1721 if ( $self->i >= $self->top ) {
58 1         32 $self->i( $self->i - 1 );
59 1         20 $self->direction( 0 );
60 1 50       12 print "Change direction to down.\n" if $self->verbose;
61             }
62             else {
63 100         2998 $self->i( $self->i + 1 );
64             }
65             }
66             else {
67 99 50       1670 if ( $self->i <= $self->bottom ) {
68 0         0 $self->i( $self->i + 1 );
69 0         0 $self->direction( 1 );
70 0 0       0 print "Change direction to up.\n" if $self->verbose;
71             }
72             else {
73 99         2831 $self->i( $self->i - 1 );
74             }
75             }
76              
77 200         3605 return $self->i;
78             }
79              
80             1;
81              
82             __END__