| 1 | use strict; | ||
| 2 | use warnings; | ||
| 3 | #use feature qw( say ); | ||
| 4 | |||
| 5 | package | ||
| 6 | Games::Sudoku::Trainer::Found_info; | ||
| 7 | |||
| 8 | use version; our $VERSION = qv('0.03'); # PBP | ||
| 9 | |||
| 10 | # This package manages a FIFO buffer for scalars. Incoming scalars | ||
| 11 | # are added to the buffer, the oldest scalar is returned on request. | ||
| 12 | # If the buffer is empty, "undef" is returned. So "undef" shouldn't | ||
| 13 | # be presented for addition (this is currently not checked). | ||
| 14 | # In spite of its name, Found_info doesn't know anything about the | ||
| 15 | # managed scalars. | ||
| 16 | |||
| 17 | my @pending; # all Found_info objects waiting for processing | ||
| 18 | |||
| 19 | # constructor for Found_info objects | ||
| 20 | # the new object is added to @pending | ||
| 21 | # | ||
| 22 | sub new { | ||
| 23 | my $class = shift; | ||
| 24 | my $found_ref = shift; | ||
| 25 | |||
| 26 | #TODO: future enhancement: replace array by named properties | ||
| 27 | # my @props_values = @_; # property values | ||
| 28 | |||
| 29 | # my %props; | ||
| 30 | # @props{qw/stratname action clues results/} = (@props_values); | ||
| 31 | #say "props ", %props; | ||
| 32 | # my $self = \%props; | ||
| 33 | my $self = $found_ref; | ||
| 34 | bless $self, $class; | ||
| 35 | |||
| 36 | push @pending, $self; | ||
| 37 | return; | ||
| 38 | } | ||
| 39 | |||
| 40 | # getter for Found_info objects | ||
| 41 | # return the oldest pending Found_info object for processing | ||
| 42 | # | ||
| 43 | sub oldest { | ||
| 44 | |||
| 45 | return shift @pending; | ||
| 46 | } | ||
| 47 | |||
| 48 | 1; |