line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Games::2048::Serializable; |
2
|
4
|
|
|
4
|
|
84
|
use 5.012; |
|
4
|
|
|
|
|
12
|
|
|
4
|
|
|
|
|
166
|
|
3
|
4
|
|
|
4
|
|
2561
|
use Moo::Role; |
|
4
|
|
|
|
|
33695
|
|
|
4
|
|
|
|
|
21
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
# increment this whenever we break compat with older game objects |
6
|
|
|
|
|
|
|
our $VERSION = '0.04'; |
7
|
|
|
|
|
|
|
|
8
|
4
|
|
|
4
|
|
4878
|
use Storable; |
|
4
|
|
|
|
|
12728
|
|
|
4
|
|
|
|
|
278
|
|
9
|
4
|
|
|
4
|
|
2478
|
use File::Spec::Functions; |
|
4
|
|
|
|
|
2899
|
|
|
4
|
|
|
|
|
322
|
|
10
|
4
|
|
|
4
|
|
2190
|
use File::HomeDir; |
|
4
|
|
|
|
|
18084
|
|
|
4
|
|
|
|
|
1071
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
has version => is => 'rw', default => __PACKAGE__->VERSION; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub _game_file { |
15
|
0
|
|
|
0
|
|
0
|
my ($file) = @_; |
16
|
0
|
|
|
|
|
0
|
state $dir = eval { |
17
|
0
|
0
|
|
|
|
0
|
my $my_dist_method = "my_dist_" . ($^O eq "MSWin32" ? "data" : "config"); |
18
|
0
|
|
|
|
|
0
|
File::HomeDir->$my_dist_method("Games-2048", {create => 1}); |
19
|
|
|
|
|
|
|
}; |
20
|
0
|
0
|
|
|
|
0
|
return if !defined $dir; |
21
|
0
|
|
|
|
|
0
|
return catfile $dir, $file; |
22
|
|
|
|
|
|
|
} |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub save { |
25
|
0
|
|
|
0
|
0
|
0
|
my ($self, $file) = @_; |
26
|
0
|
|
|
|
|
0
|
$self->version(__PACKAGE__->VERSION); |
27
|
0
|
|
|
|
|
0
|
eval { store $self, _game_file($file); 1 }; |
|
0
|
|
|
|
|
0
|
|
|
0
|
|
|
|
|
0
|
|
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
sub restore { |
31
|
0
|
|
|
0
|
0
|
0
|
my ($self, $file) = @_; |
32
|
0
|
|
|
|
|
0
|
$self = eval { retrieve _game_file($file) }; |
|
0
|
|
|
|
|
0
|
|
33
|
0
|
|
|
|
|
0
|
$self; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
sub is_valid { |
37
|
1
|
|
|
1
|
0
|
2010
|
my $self = shift; |
38
|
1
|
50
|
|
|
|
31
|
defined $self->version and $self->version >= __PACKAGE__->VERSION; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
1; |