-
Notifications
You must be signed in to change notification settings - Fork 11
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Extract a common module/library/header.
This is Refactoring / code cleanup. See: * https://refactoring.com/catalog/extractMethod.html * https://en.wikipedia.org/wiki/Code_refactoring * https://www.refactoring.com/ * https://www.joelonsoftware.com/2002/01/23/rub-a-dub-dub/ Some small optimisations may have slipped in as well.
- Loading branch information
Showing
2 changed files
with
81 additions
and
63 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
79 changes: 79 additions & 0 deletions
79
cpan/Games-Solitaire-Verify/Games-Solitaire-Verify/lib/Games/Solitaire/Verify/LinesIter.pm
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,79 @@ | ||
package Games::Solitaire::Verify::LinesIter; | ||
|
||
use strict; | ||
use warnings; | ||
|
||
sub new | ||
{ | ||
my $class = shift; | ||
|
||
my $self = bless {}, $class; | ||
|
||
$self->_init(@_); | ||
|
||
return $self; | ||
} | ||
|
||
sub _init | ||
{ | ||
my ( $self, $args ) = @_; | ||
|
||
$self->{_get} = $args->{_get}; | ||
$self->{_line_num} = 0; | ||
|
||
return; | ||
} | ||
|
||
sub _get_line | ||
{ | ||
my ( $self, ) = @_; | ||
|
||
my $ret = $self->{_get}->(); | ||
return ( $ret, ++$self->{_line_num} ); | ||
} | ||
|
||
sub _assert_empty_line | ||
{ | ||
my ( $self, ) = @_; | ||
|
||
my ( $s, $line_idx ) = $self->_get_line; | ||
|
||
if ( $s ne '' ) | ||
{ | ||
Carp::confess("Line '$line_idx' is not empty, but '$s'"); | ||
} | ||
|
||
return; | ||
} | ||
|
||
sub _compare_line | ||
{ | ||
my ( $self, $wanted_line, $title, ) = @_; | ||
|
||
my ( $line, $line_idx ) = $self->_get_line; | ||
if ( $line ne $wanted_line ) | ||
{ | ||
Carp::confess( | ||
"$title string is '$line' vs. '$wanted_line' at line no. $line_idx" | ||
); | ||
} | ||
|
||
return; | ||
} | ||
|
||
1; | ||
|
||
__END__ | ||
=head1 NAME | ||
Games::Solitaire::Verify::LinesIter - a lines' iterator | ||
to keep track of line numbers. | ||
=head1 METHODS | ||
=head2 Games::Solitaire::Verify::LinesIter->new() | ||
Construct a new lines iterator ( B<FOR INTERNAL USE!!> ) | ||
=cut |