line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
5
|
|
|
5
|
|
86
|
use 5.010001; |
|
5
|
|
|
|
|
23
|
|
2
|
5
|
|
|
5
|
|
34
|
use strict; |
|
5
|
|
|
|
|
9
|
|
|
5
|
|
|
|
|
127
|
|
3
|
5
|
|
|
5
|
|
31
|
use warnings; |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
324
|
|
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
package Story::Interact::State; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:TOBYINK'; |
8
|
|
|
|
|
|
|
our $VERSION = '0.001012'; |
9
|
|
|
|
|
|
|
|
10
|
5
|
|
|
5
|
|
2076
|
use Story::Interact::Character (); |
|
5
|
|
|
|
|
25
|
|
|
5
|
|
|
|
|
223
|
|
11
|
|
|
|
|
|
|
|
12
|
5
|
|
|
5
|
|
45
|
use Moo; |
|
5
|
|
|
|
|
117
|
|
|
5
|
|
|
|
|
47
|
|
13
|
5
|
|
|
5
|
|
1737
|
use Module::Runtime qw( use_package_optimistically ); |
|
5
|
|
|
|
|
18
|
|
|
5
|
|
|
|
|
50
|
|
14
|
5
|
|
|
5
|
|
442
|
use Types::Common -types; |
|
5
|
|
|
|
|
29
|
|
|
5
|
|
|
|
|
52
|
|
15
|
5
|
|
|
5
|
|
69645
|
use namespace::clean; |
|
5
|
|
|
|
|
11
|
|
|
5
|
|
|
|
|
57
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
has 'world' => ( |
18
|
|
|
|
|
|
|
is => 'ro', |
19
|
|
|
|
|
|
|
isa => HashRef, |
20
|
9
|
|
|
9
|
|
338
|
builder => sub { {} }, |
21
|
|
|
|
|
|
|
); |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
has 'character' => ( |
24
|
|
|
|
|
|
|
is => 'ro', |
25
|
|
|
|
|
|
|
isa => HashRef->of( Object ), |
26
|
9
|
|
|
9
|
|
16832
|
builder => sub { {} }, |
27
|
|
|
|
|
|
|
); |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
has 'location' => ( |
30
|
|
|
|
|
|
|
is => 'ro', |
31
|
|
|
|
|
|
|
isa => HashRef->of( HashRef ), |
32
|
9
|
|
|
9
|
|
363
|
builder => sub { {} }, |
33
|
|
|
|
|
|
|
); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
has 'visited' => ( |
36
|
|
|
|
|
|
|
is => 'ro', |
37
|
|
|
|
|
|
|
isa => HashRef->of( PositiveOrZeroInt ), |
38
|
9
|
|
|
9
|
|
371
|
builder => sub { {} }, |
39
|
|
|
|
|
|
|
); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
has 'character_class' => ( |
42
|
|
|
|
|
|
|
is => 'ro', |
43
|
|
|
|
|
|
|
isa => Str, |
44
|
9
|
|
|
9
|
|
411
|
builder => sub { 'Story::Interact::Character' }, |
45
|
|
|
|
|
|
|
); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
has 'params' => ( |
48
|
|
|
|
|
|
|
is => 'rw', |
49
|
|
|
|
|
|
|
isa => HashRef, |
50
|
9
|
|
|
9
|
|
350
|
builder => sub { {} }, |
51
|
|
|
|
|
|
|
); |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
sub BUILD { |
54
|
9
|
|
|
9
|
0
|
229
|
my ( $self, $arg ) = @_; |
55
|
9
|
|
|
|
|
56
|
$self->define_npc( player => ( name => 'Anon' ) ); |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub player { |
59
|
55
|
|
|
55
|
0
|
118
|
my ( $self ) = @_; |
60
|
55
|
|
|
|
|
1202
|
return $self->character->{player}; |
61
|
|
|
|
|
|
|
} |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
sub define_npc { |
64
|
10
|
|
|
10
|
0
|
141
|
my ( $self, $code, %attrs ) = @_; |
65
|
10
|
50
|
|
|
|
89
|
return if defined $self->character->{$code}; |
66
|
|
|
|
|
|
|
|
67
|
10
|
|
66
|
|
|
96
|
my $character_class = delete( $attrs{class} ) // $self->character_class; |
68
|
10
|
|
|
|
|
66
|
$self->character->{$code} = use_package_optimistically( $character_class )->new( %attrs ); |
69
|
|
|
|
|
|
|
} |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub update_from_page { |
72
|
45
|
|
|
45
|
0
|
95
|
my ( $self, $page ) = @_; |
73
|
45
|
|
|
|
|
212
|
++$self->visited->{ $page->id }; |
74
|
45
|
|
|
|
|
119
|
$self->player->_set_location( $page->location ); |
75
|
45
|
|
|
|
|
1248
|
return $self; |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
sub dump { |
79
|
0
|
|
|
0
|
0
|
|
my ( $self ) = @_; |
80
|
0
|
|
|
|
|
|
require Storable; |
81
|
0
|
|
|
|
|
|
require MIME::Base64; |
82
|
0
|
|
|
|
|
|
require Compress::Bzip2; |
83
|
0
|
|
|
|
|
|
my $frozen = Compress::Bzip2::memBzip( Storable::nfreeze( $self ) ); |
84
|
0
|
|
|
|
|
|
return MIME::Base64::encode_base64( $frozen ); |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
sub load { |
88
|
0
|
|
|
0
|
0
|
|
my ( $class, $data ) = @_; |
89
|
0
|
|
|
|
|
|
require Storable; |
90
|
0
|
|
|
|
|
|
require MIME::Base64; |
91
|
0
|
|
|
|
|
|
require Compress::Bzip2; |
92
|
0
|
|
|
|
|
|
my $frozen = MIME::Base64::decode_base64( $data ); |
93
|
0
|
0
|
|
|
|
|
if ( my $unzipped = Compress::Bzip2::memBunzip($frozen) ) { |
94
|
0
|
|
|
|
|
|
return Storable::thaw( $unzipped ); |
95
|
|
|
|
|
|
|
} |
96
|
0
|
|
|
|
|
|
return Storable::thaw( $frozen ); |
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
1; |