| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Git::Demo::Story; |
|
2
|
1
|
|
|
1
|
|
4
|
use strict; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
31
|
|
|
3
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
29
|
|
|
4
|
1
|
|
|
1
|
|
545
|
use Git::Demo::Story::Event; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
24
|
|
|
5
|
1
|
|
|
1
|
|
546
|
use Git::Demo::Story::Character; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
29
|
|
|
6
|
1
|
|
|
1
|
|
395
|
use Git::Demo::Story::EventHandler; |
|
|
1
|
|
|
|
|
5
|
|
|
|
1
|
|
|
|
|
61
|
|
|
7
|
1
|
|
|
1
|
|
1368
|
use YAML::Any qw/LoadFile DumpFile/; |
|
|
1
|
|
|
|
|
1610
|
|
|
|
1
|
|
|
|
|
11
|
|
|
8
|
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
=head1 NAME |
|
10
|
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
Git::Demo::Story - The story with which to run a demo |
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
=head1 VERSION |
|
14
|
|
|
|
|
|
|
|
|
15
|
|
|
|
|
|
|
Version 0.01 |
|
16
|
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
=cut |
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
|
20
|
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
##FIXME |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
=head1 SUBROUTINES/METHODS |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
=head2 new |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
=cut |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub new{ |
|
34
|
0
|
|
|
0
|
1
|
|
my $class = shift; |
|
35
|
0
|
|
|
|
|
|
my $args = shift; |
|
36
|
|
|
|
|
|
|
|
|
37
|
0
|
|
|
|
|
|
my $self = {}; |
|
38
|
|
|
|
|
|
|
|
|
39
|
0
|
|
|
|
|
|
foreach( qw/dir/ ){ |
|
40
|
0
|
0
|
|
|
|
|
if( ! $args->{$_} ){ |
|
41
|
0
|
|
|
|
|
|
die( __PACKAGE__ . " requires argument $_" ); |
|
42
|
|
|
|
|
|
|
} |
|
43
|
0
|
|
|
|
|
|
$self->{$_} = $args->{$_}; |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
foreach( qw/verbose/ ){ |
|
47
|
0
|
|
|
|
|
|
$self->{$_} = $args->{$_}; |
|
48
|
|
|
|
|
|
|
} |
|
49
|
|
|
|
|
|
|
|
|
50
|
0
|
|
|
|
|
|
my $logger = Log::Log4perl->get_logger( __PACKAGE__ ); |
|
51
|
0
|
|
|
|
|
|
$self->{logger} = $logger; |
|
52
|
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
bless $self, $class; |
|
54
|
|
|
|
|
|
|
|
|
55
|
0
|
0
|
|
|
|
|
if( $args->{story_file} ){ |
|
56
|
0
|
|
|
|
|
|
$self->load_story( $args->{story_file} ); |
|
57
|
|
|
|
|
|
|
} |
|
58
|
|
|
|
|
|
|
|
|
59
|
0
|
|
|
|
|
|
$self->{event_handler} = Git::Demo::Story::EventHandler->new( { story => $self, |
|
60
|
|
|
|
|
|
|
verbose => $self->{verbose}, |
|
61
|
|
|
|
|
|
|
} ); |
|
62
|
|
|
|
|
|
|
|
|
63
|
0
|
|
0
|
|
|
|
$self->{characters} ||= []; |
|
64
|
0
|
|
0
|
|
|
|
$self->{events} ||= []; |
|
65
|
0
|
|
|
|
|
|
$self->{event_cursor} = 0; |
|
66
|
|
|
|
|
|
|
|
|
67
|
0
|
|
|
|
|
|
return $self; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub load_story{ |
|
72
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
73
|
0
|
|
|
|
|
|
my $story_file = shift; |
|
74
|
0
|
|
|
|
|
|
my $logger = $self->{logger}; |
|
75
|
|
|
|
|
|
|
|
|
76
|
0
|
0
|
|
|
|
|
if( ! $story_file ){ |
|
77
|
0
|
|
|
|
|
|
die( "No story file passed to load_story\n" ); |
|
78
|
|
|
|
|
|
|
} |
|
79
|
0
|
0
|
|
|
|
|
if( ! -f $story_file ){ |
|
80
|
0
|
|
|
|
|
|
die( "Story file ($story_file) does not exist\n" ); |
|
81
|
|
|
|
|
|
|
} |
|
82
|
|
|
|
|
|
|
|
|
83
|
0
|
|
|
|
|
|
my $details = LoadFile( $story_file ); |
|
84
|
0
|
0
|
|
|
|
|
if( ! $details ){ |
|
85
|
0
|
|
|
|
|
|
die( "Could not load story from $story_file\n" ); |
|
86
|
|
|
|
|
|
|
} |
|
87
|
|
|
|
|
|
|
|
|
88
|
0
|
|
|
|
|
|
$self->{characters} = {}; |
|
89
|
0
|
0
|
0
|
|
|
|
if( $details->{characters} and ref( $details->{characters} ) eq 'ARRAY' ){ |
|
90
|
0
|
|
|
|
|
|
foreach my $character_hash( @{ $details->{characters} } ){ |
|
|
0
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
my $character = Git::Demo::Story::Character->new( { story => $self, |
|
92
|
|
|
|
|
|
|
name => $character_hash->{name}, |
|
93
|
|
|
|
|
|
|
git_args => $character_hash->{git_args}, |
|
94
|
|
|
|
|
|
|
} ); |
|
95
|
0
|
|
|
|
|
|
$self->{characters}->{$character_hash->{name}} = $character; |
|
96
|
|
|
|
|
|
|
} |
|
97
|
|
|
|
|
|
|
} |
|
98
|
|
|
|
|
|
|
|
|
99
|
0
|
|
|
|
|
|
$self->{events} = []; |
|
100
|
0
|
0
|
0
|
|
|
|
if( $details->{events} and ref( $details->{events} ) eq 'ARRAY' ){ |
|
101
|
0
|
|
|
|
|
|
foreach( @{ $details->{events} } ){ |
|
|
0
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
|
my $event = Git::Demo::Story::Event->new( $_ ); |
|
103
|
0
|
|
|
|
|
|
$logger->debug( "Adding event: " . $event->stringify() ); |
|
104
|
0
|
|
|
|
|
|
push( @{ $self->{events} }, $event ); |
|
|
0
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
} |
|
107
|
0
|
|
|
|
|
|
$self->{event_cursor} = 0; |
|
108
|
|
|
|
|
|
|
|
|
109
|
0
|
|
|
|
|
|
$self->{story_file} = $story_file; |
|
110
|
|
|
|
|
|
|
} |
|
111
|
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
sub save_story{ |
|
114
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
115
|
0
|
|
|
|
|
|
my $story_file = shift; |
|
116
|
|
|
|
|
|
|
|
|
117
|
0
|
|
0
|
|
|
|
$story_file ||= $self->{story_file}; |
|
118
|
0
|
0
|
|
|
|
|
if( ! $story_file ){ |
|
119
|
0
|
|
|
|
|
|
die( "No story_file defined to write to" ); |
|
120
|
|
|
|
|
|
|
} |
|
121
|
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
my $details = { characters => $self->{characters} }; |
|
123
|
0
|
|
|
|
|
|
my @events; |
|
124
|
0
|
|
|
|
|
|
foreach( @{ $self->{events} } ){ |
|
|
0
|
|
|
|
|
|
|
|
125
|
0
|
|
|
|
|
|
push( @events, $_->to_hash() ); |
|
126
|
|
|
|
|
|
|
} |
|
127
|
0
|
|
|
|
|
|
$details->{events} = \@events; |
|
128
|
|
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
|
DumpFile( $story_file, $details ); |
|
130
|
|
|
|
|
|
|
} |
|
131
|
|
|
|
|
|
|
|
|
132
|
|
|
|
|
|
|
# Returns the number of events played |
|
133
|
|
|
|
|
|
|
sub play{ |
|
134
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
135
|
0
|
|
|
|
|
|
my $count = 0; |
|
136
|
0
|
|
|
|
|
|
while( my $event = $self->next_event() ){ |
|
137
|
0
|
|
|
|
|
|
$count++; |
|
138
|
0
|
|
|
|
|
|
$self->{event_handler}->exec( $event ); |
|
139
|
|
|
|
|
|
|
} |
|
140
|
0
|
|
|
|
|
|
return $count; |
|
141
|
|
|
|
|
|
|
} |
|
142
|
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
# Plays the next event, and returns this event |
|
144
|
|
|
|
|
|
|
sub play_next{ |
|
145
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
146
|
0
|
0
|
|
|
|
|
if( my $event = $self->next_event() ){ |
|
147
|
0
|
|
|
|
|
|
$self->{event_handler}->exec( $event ); |
|
148
|
0
|
|
|
|
|
|
return $event; |
|
149
|
|
|
|
|
|
|
} |
|
150
|
0
|
|
|
|
|
|
return undef; |
|
151
|
|
|
|
|
|
|
} |
|
152
|
|
|
|
|
|
|
|
|
153
|
|
|
|
|
|
|
# Returns the next event and increments the event cursor |
|
154
|
|
|
|
|
|
|
sub next_event{ |
|
155
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
156
|
0
|
0
|
|
|
|
|
if( defined( $self->{events}->[ $self->{event_cursor} ] ) ){ |
|
157
|
0
|
|
|
|
|
|
return $self->{events}->[ $self->{event_cursor}++ ]; |
|
158
|
|
|
|
|
|
|
} |
|
159
|
0
|
|
|
|
|
|
return undef; |
|
160
|
|
|
|
|
|
|
} |
|
161
|
|
|
|
|
|
|
|
|
162
|
|
|
|
|
|
|
# Return all characters |
|
163
|
|
|
|
|
|
|
sub characters{ |
|
164
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
165
|
0
|
|
|
|
|
|
return $self->{characters}; |
|
166
|
|
|
|
|
|
|
} |
|
167
|
|
|
|
|
|
|
|
|
168
|
|
|
|
|
|
|
# Return a character by name |
|
169
|
|
|
|
|
|
|
sub get_character{ |
|
170
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
171
|
0
|
|
|
|
|
|
my $name = shift; |
|
172
|
0
|
0
|
|
|
|
|
if( defined( $self->{characters}->{$name} ) ){ |
|
173
|
0
|
|
|
|
|
|
return $self->{characters}->{$name}; |
|
174
|
|
|
|
|
|
|
} |
|
175
|
0
|
|
|
|
|
|
return undef; |
|
176
|
|
|
|
|
|
|
} |
|
177
|
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
sub dir{ |
|
179
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
180
|
0
|
|
|
|
|
|
return $self->{dir}; |
|
181
|
|
|
|
|
|
|
} |
|
182
|
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
sub pause{ |
|
184
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
|
185
|
0
|
0
|
|
|
|
|
if( $self->{no_pause} ){ |
|
186
|
0
|
|
|
|
|
|
return; |
|
187
|
|
|
|
|
|
|
} |
|
188
|
0
|
|
|
|
|
|
print "Continue?"; |
|
189
|
0
|
|
|
|
|
|
my $in = |
|
190
|
|
|
|
|
|
|
} |
|
191
|
|
|
|
|
|
|
=head1 AUTHOR |
|
192
|
|
|
|
|
|
|
|
|
193
|
|
|
|
|
|
|
Robin Clarke, C<< >> |
|
194
|
|
|
|
|
|
|
|
|
195
|
|
|
|
|
|
|
|
|
196
|
|
|
|
|
|
|
=head1 LICENSE AND COPYRIGHT |
|
197
|
|
|
|
|
|
|
|
|
198
|
|
|
|
|
|
|
Copyright 2010 Robin Clarke. |
|
199
|
|
|
|
|
|
|
|
|
200
|
|
|
|
|
|
|
This program is free software; you can redistribute it and/or modify it |
|
201
|
|
|
|
|
|
|
under the terms of either: the GNU General Public License as published |
|
202
|
|
|
|
|
|
|
by the Free Software Foundation; or the Artistic License. |
|
203
|
|
|
|
|
|
|
|
|
204
|
|
|
|
|
|
|
See http://dev.perl.org/licenses/ for more information. |
|
205
|
|
|
|
|
|
|
|
|
206
|
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=cut |
|
208
|
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
1; |