line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package StateML::Arc ; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
1050
|
use strict ; |
|
3
|
|
|
|
|
7
|
|
|
3
|
|
|
|
|
115
|
|
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
14
|
use base qw(StateML::Object ) ; |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
197
|
|
6
|
|
|
|
|
|
|
|
7
|
3
|
|
|
3
|
|
1577
|
use StateML::Utils qw( empty ); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
156
|
|
8
|
3
|
|
|
3
|
|
15
|
use Carp qw( confess ); |
|
3
|
|
|
|
|
5
|
|
|
3
|
|
|
|
|
3239
|
|
9
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
=head1 NAME |
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
StateML::Arc - A transition between states |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
=head1 DESCRIPTION |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
An arc is a transition between states; they occur by default or |
17
|
|
|
|
|
|
|
on certain events. |
18
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
A loopback arc is an arc that transits from a state back to itself. |
20
|
|
|
|
|
|
|
|
21
|
|
|
|
|
|
|
Arcs can have handlers, either explicitly using one or more s or |
22
|
|
|
|
|
|
|
by reference to an using an action-id attribute (we need to |
23
|
|
|
|
|
|
|
allow arcs to have multiple actions at some point). |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Arcs can contain an , in which case the 's event-id= is |
26
|
|
|
|
|
|
|
automatically read from the (which in turn may omit it and let |
27
|
|
|
|
|
|
|
StateML::Machine assign one). |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head2 Default from/to state ids. |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
On parsing, elements may appear in elements. When they |
32
|
|
|
|
|
|
|
do, the from= and/or to= attributes may be omitted; they will default to |
33
|
|
|
|
|
|
|
the parent state's id. |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
=head1 METHODS (incomplete, see the source, luke) |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=over |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
=cut |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=item event |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Returns the event for this arc, if set. |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=cut |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
sub event { |
48
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
49
|
|
|
|
|
|
|
|
50
|
0
|
0
|
|
|
|
0
|
$self->event_id( $_[0]->id ) if @_; |
51
|
|
|
|
|
|
|
|
52
|
0
|
0
|
|
|
|
0
|
return unless defined wantarray; |
53
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
0
|
my $event_id = $self->event_id; |
55
|
0
|
0
|
|
|
|
0
|
return undef unless defined $event_id; |
56
|
|
|
|
|
|
|
|
57
|
0
|
0
|
|
|
|
0
|
confess "arc is not in a machine, can't fetch the event" |
58
|
|
|
|
|
|
|
unless $self->machine; |
59
|
|
|
|
|
|
|
|
60
|
0
|
|
|
|
|
0
|
my $event = $self->machine->event_by_id( $event_id ); |
61
|
|
|
|
|
|
|
|
62
|
0
|
0
|
|
|
|
0
|
confess "event ", as_str( $event_id ), " is not in machine" |
63
|
|
|
|
|
|
|
unless $event; |
64
|
|
|
|
|
|
|
|
65
|
0
|
|
|
|
|
0
|
return $event; |
66
|
|
|
|
|
|
|
} |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
=item event_id |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
Returns the event_id if set. If not set (undef), returns the default event's |
71
|
|
|
|
|
|
|
ID if it is present in the machine. Note that "" is a I valid id. |
72
|
|
|
|
|
|
|
|
73
|
|
|
|
|
|
|
=cut |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
sub event_id { |
76
|
2
|
|
|
2
|
1
|
335
|
my $self = shift ; |
77
|
|
|
|
|
|
|
|
78
|
2
|
50
|
|
|
|
6
|
$self->{EVENT_ID} = shift if @_ ; |
79
|
2
|
50
|
|
|
|
6
|
return $self->{EVENT_ID} if defined $self->{EVENT_ID}; |
80
|
|
|
|
|
|
|
|
81
|
2
|
|
66
|
|
|
6
|
my $default_event = |
82
|
|
|
|
|
|
|
$self->machine && $self->machine->event_by_id( "#DEFAULT" ); |
83
|
|
|
|
|
|
|
|
84
|
2
|
100
|
|
|
|
10
|
return $default_event ? $default_event->id : undef; |
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=item name |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Returns the name if set. If not set, returns the name of the event_id |
90
|
|
|
|
|
|
|
event (if that's set). Note that "" I a valid name. |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=cut |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub name { |
95
|
0
|
|
|
0
|
1
|
0
|
my $self = shift; |
96
|
|
|
|
|
|
|
|
97
|
0
|
0
|
|
|
|
0
|
$self->SUPER::name( @_ ) if @_; |
98
|
0
|
0
|
|
|
|
0
|
return $self->{NAME} if defined $self->{NAME}; |
99
|
|
|
|
|
|
|
|
100
|
0
|
0
|
|
|
|
0
|
my $event = $self->event if $self->machine; |
101
|
|
|
|
|
|
|
|
102
|
0
|
|
|
|
|
0
|
return $event->name; |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
sub from { |
106
|
2
|
|
|
2
|
1
|
3
|
my $self = shift ; |
107
|
2
|
50
|
|
|
|
4
|
$self->{FROM} = shift if @_ ; |
108
|
2
|
|
|
|
|
8
|
return $self->{FROM} ; |
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
|
111
|
|
|
|
|
|
|
sub to { |
112
|
2
|
|
|
2
|
1
|
3
|
my $self = shift ; |
113
|
2
|
50
|
|
|
|
15
|
$self->{TO} = shift if @_ ; |
114
|
2
|
|
|
|
|
10
|
return $self->{TO} ; |
115
|
|
|
|
|
|
|
} |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub guard { |
118
|
0
|
|
|
0
|
0
|
|
my $self = shift ; |
119
|
0
|
0
|
|
|
|
|
$self->{GUARD} = shift if @_ ; |
120
|
0
|
|
|
|
|
|
return $self->{GUARD} ; |
121
|
|
|
|
|
|
|
} |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
sub from_state { |
124
|
0
|
|
|
0
|
0
|
|
my $self = shift ; |
125
|
0
|
0
|
|
|
|
|
$self->{FROM} = shift()->id if @_ ; |
126
|
0
|
|
|
|
|
|
return $self->machine->state_by_id( $self->{FROM} ) ; |
127
|
|
|
|
|
|
|
} |
128
|
|
|
|
|
|
|
|
129
|
|
|
|
|
|
|
sub to_state { |
130
|
0
|
|
|
0
|
0
|
|
my $self = shift ; |
131
|
0
|
0
|
|
|
|
|
$self->{TO} = shift()->id if @_ ; |
132
|
0
|
|
|
|
|
|
return $self->machine->state_by_id( $self->{TO} ) ; |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
sub description { |
136
|
0
|
|
|
0
|
0
|
|
my $self = shift ; |
137
|
0
|
0
|
|
|
|
|
$self->{DESCRIPTION} = shift if @_ ; |
138
|
0
|
|
|
|
|
|
return $self->{DESCRIPTION}; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
sub handlers { |
142
|
0
|
|
|
0
|
0
|
|
my $self = shift ; |
143
|
0
|
0
|
|
|
|
|
$self->{HANDLERS} = @_ if @_ ; |
144
|
|
|
|
|
|
|
return map ref $_ |
145
|
0
|
|
|
|
|
|
? do { |
146
|
0
|
|
|
|
|
|
my $action = $self->machine->action_by_id( $$_ ); |
147
|
0
|
0
|
|
|
|
|
die "Action $$_ for arc ", |
148
|
|
|
|
|
|
|
$self->name, |
149
|
|
|
|
|
|
|
" (id ", |
150
|
|
|
|
|
|
|
$self->id, |
151
|
|
|
|
|
|
|
") not defined\n" |
152
|
|
|
|
|
|
|
unless $action; |
153
|
0
|
|
|
|
|
|
$action->handlers; |
154
|
|
|
|
|
|
|
} |
155
|
|
|
|
|
|
|
: $_, |
156
|
0
|
0
|
|
|
|
|
@{$self->{HANDLERS}} ; |
157
|
|
|
|
|
|
|
} |
158
|
|
|
|
|
|
|
|
159
|
|
|
|
|
|
|
|
160
|
|
|
|
|
|
|
sub handler_descriptions { |
161
|
0
|
|
|
0
|
0
|
|
my $self = shift ; |
162
|
|
|
|
|
|
|
return map ref $_ |
163
|
0
|
|
|
|
|
|
? do { |
164
|
0
|
|
|
|
|
|
my $action = $self->machine->action_by_id( $$_ ); |
165
|
0
|
0
|
|
|
|
|
die "Action $$_ for arc ", |
166
|
|
|
|
|
|
|
$self->name, |
167
|
|
|
|
|
|
|
" (id ", |
168
|
|
|
|
|
|
|
$self->id, |
169
|
|
|
|
|
|
|
") not defined\n" |
170
|
|
|
|
|
|
|
unless $action; |
171
|
0
|
|
|
|
|
|
my $desc = $action->description; |
172
|
0
|
0
|
|
|
|
|
defined $desc ? $desc : $action->handlers; |
173
|
|
|
|
|
|
|
} |
174
|
|
|
|
|
|
|
: $_, |
175
|
0
|
0
|
|
|
|
|
@{$self->{HANDLERS}} ; |
176
|
|
|
|
|
|
|
} |
177
|
|
|
|
|
|
|
|
178
|
|
|
|
|
|
|
|
179
|
|
|
|
|
|
|
sub add_handler { |
180
|
0
|
|
|
0
|
0
|
|
my $self = shift ; |
181
|
0
|
|
|
|
|
|
push @{$self->{HANDLERS}}, @_ ; |
|
0
|
|
|
|
|
|
|
182
|
|
|
|
|
|
|
} |
183
|
|
|
|
|
|
|
|
184
|
|
|
|
|
|
|
|
185
|
|
|
|
|
|
|
sub handler_attributes { |
186
|
0
|
|
|
0
|
0
|
|
my $self = shift ; |
187
|
|
|
|
|
|
|
return map ref $_ |
188
|
0
|
|
|
|
|
|
? do { |
189
|
0
|
|
|
|
|
|
my $action = $self->machine->action_by_id( $$_ ); |
190
|
0
|
0
|
|
|
|
|
die "Action $$_ for arc ", |
191
|
|
|
|
|
|
|
$self->name, |
192
|
|
|
|
|
|
|
" (id ", |
193
|
|
|
|
|
|
|
$self->id, |
194
|
|
|
|
|
|
|
") not defined\n" |
195
|
|
|
|
|
|
|
unless $action; |
196
|
0
|
|
|
|
|
|
$action->attributes( @_ ); |
197
|
|
|
|
|
|
|
} |
198
|
|
|
|
|
|
|
: (), |
199
|
0
|
0
|
|
|
|
|
@{$self->{HANDLERS}} ; |
200
|
|
|
|
|
|
|
} |
201
|
|
|
|
|
|
|
|
202
|
|
|
|
|
|
|
|
203
|
|
|
|
|
|
|
=item attribute |
204
|
|
|
|
|
|
|
|
205
|
|
|
|
|
|
|
Like StateML::Object::attribute, but inherits from the event. |
206
|
|
|
|
|
|
|
|
207
|
|
|
|
|
|
|
=cut |
208
|
|
|
|
|
|
|
|
209
|
|
|
|
|
|
|
sub attribute { |
210
|
0
|
|
|
0
|
1
|
|
my $self = shift ; |
211
|
|
|
|
|
|
|
|
212
|
0
|
|
|
|
|
|
my $a = $self->SUPER::attribute( @_ ) ; |
213
|
0
|
0
|
0
|
|
|
|
if ( @_ < 3 && ! defined $a ) { |
214
|
0
|
|
|
|
|
|
my $e = $self->machine->object_by_id( $self->event_id ) ; |
215
|
0
|
0
|
|
|
|
|
$a = $e->attribute( @_ ) if defined $e ; |
216
|
|
|
|
|
|
|
} |
217
|
0
|
|
|
|
|
|
return $a ; |
218
|
|
|
|
|
|
|
} |
219
|
|
|
|
|
|
|
|
220
|
|
|
|
|
|
|
|
221
|
|
|
|
|
|
|
=item attributes |
222
|
|
|
|
|
|
|
|
223
|
|
|
|
|
|
|
Like StateML::Object::attributes, but inherits from all handlers and then |
224
|
|
|
|
|
|
|
the event. |
225
|
|
|
|
|
|
|
|
226
|
|
|
|
|
|
|
=cut |
227
|
|
|
|
|
|
|
|
228
|
|
|
|
|
|
|
sub attributes { |
229
|
0
|
|
|
0
|
1
|
|
my $self = shift ; |
230
|
|
|
|
|
|
|
|
231
|
0
|
|
|
|
|
|
my $e = $self->machine->object_by_id( $self->event_id ) ; |
232
|
0
|
|
|
|
|
|
my @ea ; |
233
|
0
|
0
|
|
|
|
|
@ea = $e->attributes( @_ ) if defined $e ; |
234
|
0
|
|
|
|
|
|
my @ha = $self->handler_attributes( @_ ); |
235
|
|
|
|
|
|
|
|
236
|
0
|
|
|
|
|
|
my %a = ( @ha, @ea, $self->SUPER::attributes( @_ ) ) ; |
237
|
0
|
|
|
|
|
|
return %a ; |
238
|
|
|
|
|
|
|
} |
239
|
|
|
|
|
|
|
|
240
|
|
|
|
|
|
|
=back |
241
|
|
|
|
|
|
|
|
242
|
|
|
|
|
|
|
=head1 LIMITATIONS |
243
|
|
|
|
|
|
|
|
244
|
|
|
|
|
|
|
=head1 COPYRIGHT |
245
|
|
|
|
|
|
|
|
246
|
|
|
|
|
|
|
Copyright 2003, R. Barrie Slaymaker, Jr., All Rights Reserved |
247
|
|
|
|
|
|
|
|
248
|
|
|
|
|
|
|
=head1 LICENSE |
249
|
|
|
|
|
|
|
|
250
|
|
|
|
|
|
|
You may use this module under the terms of the BSD, Artistic, or GPL licenses, |
251
|
|
|
|
|
|
|
any version. |
252
|
|
|
|
|
|
|
|
253
|
|
|
|
|
|
|
=head1 AUTHOR |
254
|
|
|
|
|
|
|
|
255
|
|
|
|
|
|
|
Barrie Slaymaker |
256
|
|
|
|
|
|
|
|
257
|
|
|
|
|
|
|
=cut |
258
|
|
|
|
|
|
|
|
259
|
|
|
|
|
|
|
|
260
|
|
|
|
|
|
|
1 ; |