line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Git::Demo::Story::EventHandler; |
2
|
1
|
|
|
1
|
|
5
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
3
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
25
|
|
4
|
1
|
|
|
1
|
|
366
|
use Git::Demo::Action::Git; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
21
|
|
5
|
1
|
|
|
1
|
|
410
|
use Git::Demo::Action::Print; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
6
|
1
|
|
|
1
|
|
453
|
use Git::Demo::Action::File; |
|
1
|
|
|
|
|
4
|
|
|
1
|
|
|
|
|
897
|
|
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
sub new{ |
9
|
0
|
|
|
0
|
0
|
|
my $class = shift; |
10
|
0
|
|
|
|
|
|
my $args = shift; |
11
|
|
|
|
|
|
|
|
12
|
0
|
|
|
|
|
|
my $self = {}; |
13
|
0
|
|
|
|
|
|
foreach( qw/story/ ){ |
14
|
0
|
0
|
|
|
|
|
if( ! $args->{$_} ){ |
15
|
0
|
|
|
|
|
|
die( __PACKAGE__ . " requires $_" ); |
16
|
|
|
|
|
|
|
} |
17
|
0
|
|
|
|
|
|
$self->{$_} = $args->{$_}; |
18
|
|
|
|
|
|
|
} |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
# And the optionals |
21
|
0
|
|
|
|
|
|
foreach( qw/verbose/ ){ |
22
|
0
|
|
|
|
|
|
$self->{$_} = $args->{$_}; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
0
|
|
|
|
|
|
my %action_handlers = ( 'git' => Git::Demo::Action::Git->new(), |
26
|
|
|
|
|
|
|
'print' => Git::Demo::Action::Print->new(), |
27
|
|
|
|
|
|
|
'file' => Git::Demo::Action::File->new(), |
28
|
|
|
|
|
|
|
); |
29
|
0
|
|
|
|
|
|
$self->{action_handlers} = \%action_handlers; |
30
|
|
|
|
|
|
|
|
31
|
0
|
|
|
|
|
|
my $logger = Log::Log4perl->get_logger( __PACKAGE__ ); |
32
|
0
|
|
|
|
|
|
$self->{logger} = $logger; |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
|
|
|
bless $self, $class; |
35
|
0
|
|
|
|
|
|
return $self; |
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
sub characters{ |
39
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
40
|
0
|
|
|
|
|
|
my $event = shift; |
41
|
|
|
|
|
|
|
|
42
|
0
|
|
|
|
|
|
my @characters = (); |
43
|
0
|
|
|
|
|
|
my @names = split( / /, $event->characters() ); |
44
|
|
|
|
|
|
|
|
45
|
0
|
0
|
|
|
|
|
if( scalar( @names ) == 0 ){ |
46
|
0
|
|
|
|
|
|
return @characters; |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
# If the magic word ALL is used, get all characters |
50
|
0
|
0
|
|
|
|
|
if( $names[0] =~ m/^ALL/ ){ |
51
|
0
|
|
|
|
|
|
my $magic = shift( @names ); |
52
|
0
|
0
|
|
|
|
|
if( $magic eq 'ALL' ){ |
53
|
0
|
|
|
|
|
|
@characters = values( %{ $self->{story}->characters() } ); |
|
0
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
}else{ |
55
|
|
|
|
|
|
|
# But if the magic word ALL_NOT, then use all as a basis, but remove those which come |
56
|
|
|
|
|
|
|
# after ALL_NOT |
57
|
0
|
|
|
|
|
|
my @temp_characters = values( %{ $self->{story}->characters() } ); |
|
0
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
CHARACTER: |
59
|
0
|
|
|
|
|
|
foreach my $character( @temp_characters ){ |
60
|
0
|
|
|
|
|
|
foreach( @names ){ |
61
|
0
|
0
|
|
|
|
|
if( $_ eq $character->name() ){ |
62
|
0
|
|
|
|
|
|
next CHARACTER; |
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
} |
65
|
0
|
|
|
|
|
|
push( @characters, $character ); |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
} |
68
|
|
|
|
|
|
|
}else{ |
69
|
|
|
|
|
|
|
# We just have a list of names - see if we know the characters |
70
|
0
|
|
|
|
|
|
foreach( @names ){ |
71
|
0
|
|
|
|
|
|
my $character = $self->{story}->get_character( $_ ); |
72
|
0
|
0
|
|
|
|
|
if( ! $character ){ |
73
|
0
|
|
|
|
|
|
die( "Unknown character (" . $event->character() . ")" ); |
74
|
|
|
|
|
|
|
} |
75
|
0
|
|
|
|
|
|
push( @characters, $character ); |
76
|
|
|
|
|
|
|
} |
77
|
|
|
|
|
|
|
} |
78
|
0
|
|
|
|
|
|
return @characters; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub exec{ |
82
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
83
|
0
|
|
|
|
|
|
my $event = shift; |
84
|
0
|
|
|
|
|
|
my $logger = $self->{logger}; |
85
|
|
|
|
|
|
|
|
86
|
0
|
|
|
|
|
|
my $action_handler = undef; |
87
|
0
|
0
|
|
|
|
|
if( ! defined( $self->{action_handlers}->{ $event->type() } ) ){ |
88
|
0
|
|
|
|
|
|
die( "Unknown event type: " . $event->type() ); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
0
|
|
|
|
|
|
my @characters = $self->characters( $event ); |
92
|
0
|
|
|
|
|
|
foreach my $character( @characters ){ |
93
|
0
|
|
|
|
|
|
$logger->debug( sprintf( "running a %s action for %s", $event->type(), $character->name() ) ); |
94
|
0
|
|
|
|
|
|
my( $rtn, $warnings ) = $self->{action_handlers}->{ $event->type() }->run( $character, $event ); |
95
|
0
|
0
|
0
|
|
|
|
if( $self->{verbose} && $rtn ){ |
96
|
0
|
|
|
|
|
|
print $rtn; |
97
|
|
|
|
|
|
|
} |
98
|
0
|
0
|
|
|
|
|
if( $warnings ){ |
99
|
0
|
|
|
|
|
|
print "Git warnings:\n$warnings"; |
100
|
|
|
|
|
|
|
} |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
1; |