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.0201';
7              
8 1     1   701 use Carp qw( croak );
  1         2  
  1         54  
9 1     1   479 use Moo;
  1         9957  
  1         6  
10 1     1   1273 use Scalar::Util qw( looks_like_number );
  1         2  
  1         55  
11              
12 1     1   411 use strictures 2;
  1         1445  
  1         43  
13 1     1   627 use namespace::clean;
  1         10774  
  1         7  
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 a number" unless looks_like_number( $_[0] ) },
40             default => sub { 100 },
41             );
42              
43              
44             has step => (
45             is => 'rw',
46             isa => sub { croak "$_[0] is not a number" unless looks_like_number( $_[0] ) },
47             default => sub { 1 },
48             );
49              
50              
51             has verbose => (
52             is => 'ro',
53             isa => sub { croak "$_[0] is not a boolean" unless $_[0] =~ /^[01]$/ },
54             default => sub { 0 },
55             );
56              
57              
58             sub iterate {
59 200     200 1 90610 my ($self) = @_;
60              
61 200 50       650 print $self->i, "\n" if $self->verbose;
62              
63 200 100       3766 if ( $self->direction ) {
64 101 100       1749 if ( $self->i >= $self->top ) {
65 1         32 $self->i( $self->i - $self->step );
66 1         19 $self->direction( 0 );
67 1 50       9 print "Change direction to down.\n" if $self->verbose;
68             }
69             else {
70 100         2934 $self->i( $self->i + $self->step );
71             }
72             }
73             else {
74 99 50       1719 if ( $self->i <= $self->bottom ) {
75 0         0 $self->i( $self->i + $self->step );
76 0         0 $self->direction( 1 );
77 0 0       0 print "Change direction to up.\n" if $self->verbose;
78             }
79             else {
80 99         2927 $self->i( $self->i - $self->step );
81             }
82             }
83              
84 200         3282 return $self->i;
85             }
86              
87             1;
88              
89             __END__