File Coverage

blib/lib/Freecell/Deal/MS.pm
Criterion Covered Total %
statement 30 30 100.0
branch n/a
condition n/a
subroutine 7 7 100.0
pod 2 2 100.0
total 39 39 100.0


line stmt bran cond sub pod time code
1             package Freecell::Deal::MS;
2             $Freecell::Deal::MS::VERSION = '0.6.0';
3 2     2   455914 use strict;
  2         5  
  2         84  
4 2     2   10 use warnings;
  2         4  
  2         143  
5              
6 2     2   1360 use Math::RNG::Microsoft::FCPro ();
  2         143101  
  2         80  
7              
8             use Class::XSAccessor {
9 2         13 constructor => 'new',
10             accessors => [qw(deal)],
11 2     2   1622 };
  2         4077  
12              
13             my @INITIAL_CARDS = (
14             map {
15             my $s = $_;
16             map { $s . $_ } qw/C D H S/;
17             } ( 'A', ( 2 .. 9 ), 'T', 'J', 'Q', 'K' )
18             );
19              
20             sub _string_arrays
21             {
22 3     3   6 my ($self) = @_;
23              
24 3         49 my @cards = @INITIAL_CARDS;
25 3         23 Math::RNG::Microsoft::FCPro->new( seed => scalar( $self->deal ) )
26             ->shuffle( \@cards );
27 3         244302 my @lines = ( map { [] } 0 .. 7 );
  24         40  
28 3         6 my $i = -1;
29 3         12 while (@cards)
30             {
31 156         164 push @{ $lines[ ( ( ++$i ) & 7 ) ] }, pop(@cards);
  156         314  
32             }
33 3         13 return \@lines;
34             }
35              
36             sub as_columns_array
37             {
38 1     1 1 3 my ($self) = @_;
39              
40 1         13 my $rec =
41             { array_of_arrays_of_strings => scalar( $self->_string_arrays() ), };
42              
43 1         25 return $rec;
44             }
45              
46             sub as_str
47             {
48 2     2 1 356557 my ($self) = @_;
49              
50 2         8 my $lines = scalar( $self->_string_arrays() );
51 2         6 my $str = join "", map { ": @$_\n" } @$lines;
  16         42  
52 2         24 return $str;
53             }
54              
55             1;
56              
57             __END__