| 1 | package StateML::Arc ; | ||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||
| 3 | 3 | ▶ | use strict ; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||
| 5 | 3 | ▶ | use base qw(StateML::Object ) ; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 3 | ▶ | use StateML::Utils qw( empty ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 3 | ▶ | use Carp qw( confess ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 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 <handler>s or | ||||||||||||||||||||||||||||
| 22 | by reference to an <action> using an action-id attribute (we need to | ||||||||||||||||||||||||||||
| 23 | allow arcs to have multiple actions at some point). | ||||||||||||||||||||||||||||
| 24 | |||||||||||||||||||||||||||||
| 25 | Arcs can contain an <event>, in which case the <arc>'s event-id= is | ||||||||||||||||||||||||||||
| 26 | automatically read from the <event> (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, <arc> elements may appear in <state> 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 | 0 | ▶ | sub event { | ||||||||||||||||||||||||||
|
Subroutine
event: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||
| 48 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||
| 50 | 0 | ▶ | $self->event_id( $_[0]->id ) if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 0 | ▶ | return unless defined wantarray; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | my $event_id = $self->event_id; | |||||||||||||||||||||||||||
| 55 | 0 | ▶ | return undef unless defined $event_id; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 56 | |||||||||||||||||||||||||||||
| 57 | 0 | ▶ | confess "arc is not in a machine, can't fetch the event" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 58 | unless $self->machine; | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 0 | my $event = $self->machine->event_by_id( $event_id ); | |||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||
| 62 | 0 | ▶ | confess "event ", as_str( $event_id ), " is not in machine" | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 63 | unless $event; | ||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||
| 65 | 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<not> valid id. | ||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||
| 73 | =cut | ||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||
| 75 | 2 | ▶ | sub event_id { | ||||||||||||||||||||||||||
|
Subroutine
event_id: called CC=5 SCAR=16.6
Pod
documented
| |||||||||||||||||||||||||||||
| 76 | 2 | my $self = shift ; | |||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 2 | ▶ | $self->{EVENT_ID} = shift if @_ ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 79 | 2 | ▶ | return $self->{EVENT_ID} if defined $self->{EVENT_ID}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | 2 | ▶ | my $default_event = | ||||||||||||||||||||||||||
|
Condition66%2/3
$self->machine && $self->machine->event_by_id('#DEFAULT')
MC/DC50%1/2
$self->machine && $self->machine->event_by_id('#DEFAULT')
$self->machine
$self->machine->event_by_id('#DEFAULT')
Truth table66%2/3
A && B
A= $self->machineB= $self->machine->event_by_id('#DEFAULT')
| |||||||||||||||||||||||||||||
| 82 | $self->machine && $self->machine->event_by_id( "#DEFAULT" ); | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 2 | ▶ | return $default_event ? $default_event->id : undef; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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<is> a valid name. | ||||||||||||||||||||||||||||
| 91 | |||||||||||||||||||||||||||||
| 92 | =cut | ||||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 0 | ▶ | sub name { | ||||||||||||||||||||||||||
|
Subroutine
name: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 95 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 0 | ▶ | $self->SUPER::name( @_ ) if @_; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | 0 | ▶ | return $self->{NAME} if defined $self->{NAME}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 0 | ▶ | my $event = $self->event if $self->machine; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||
| 102 | 0 | return $event->name; | |||||||||||||||||||||||||||
| 103 | } | ||||||||||||||||||||||||||||
| 104 | |||||||||||||||||||||||||||||
| 105 | 2 | ▶ | sub from { | ||||||||||||||||||||||||||
|
Subroutine
from: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 106 | 2 | my $self = shift ; | |||||||||||||||||||||||||||
| 107 | 2 | ▶ | $self->{FROM} = shift if @_ ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 108 | 2 | return $self->{FROM} ; | |||||||||||||||||||||||||||
| 109 | } | ||||||||||||||||||||||||||||
| 110 | |||||||||||||||||||||||||||||
| 111 | 2 | ▶ | sub to { | ||||||||||||||||||||||||||
|
Subroutine
to: called CC=2 SCAR=7.1
Pod
documented
| |||||||||||||||||||||||||||||
| 112 | 2 | my $self = shift ; | |||||||||||||||||||||||||||
| 113 | 2 | ▶ | $self->{TO} = shift if @_ ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 114 | 2 | return $self->{TO} ; | |||||||||||||||||||||||||||
| 115 | } | ||||||||||||||||||||||||||||
| 116 | |||||||||||||||||||||||||||||
| 117 | 0 | ▶ | sub guard { | ||||||||||||||||||||||||||
|
Subroutine
guard: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 118 | 0 | my $self = shift ; | |||||||||||||||||||||||||||
| 119 | 0 | ▶ | $self->{GUARD} = shift if @_ ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 120 | 0 | return $self->{GUARD} ; | |||||||||||||||||||||||||||
| 121 | } | ||||||||||||||||||||||||||||
| 122 | |||||||||||||||||||||||||||||
| 123 | 0 | ▶ | sub from_state { | ||||||||||||||||||||||||||
|
Subroutine
from_state: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 124 | 0 | my $self = shift ; | |||||||||||||||||||||||||||
| 125 | 0 | ▶ | $self->{FROM} = shift()->id if @_ ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | 0 | return $self->machine->state_by_id( $self->{FROM} ) ; | |||||||||||||||||||||||||||
| 127 | } | ||||||||||||||||||||||||||||
| 128 | |||||||||||||||||||||||||||||
| 129 | 0 | ▶ | sub to_state { | ||||||||||||||||||||||||||
|
Subroutine
to_state: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 130 | 0 | my $self = shift ; | |||||||||||||||||||||||||||
| 131 | 0 | ▶ | $self->{TO} = shift()->id if @_ ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 132 | 0 | return $self->machine->state_by_id( $self->{TO} ) ; | |||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 0 | ▶ | sub description { | ||||||||||||||||||||||||||
|
Subroutine
description: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 136 | 0 | my $self = shift ; | |||||||||||||||||||||||||||
| 137 | 0 | ▶ | $self->{DESCRIPTION} = shift if @_ ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 138 | 0 | return $self->{DESCRIPTION}; | |||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||
| 141 | 0 | ▶ | sub handlers { | ||||||||||||||||||||||||||
|
Subroutine
handlers: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 142 | 0 | my $self = shift ; | |||||||||||||||||||||||||||
| 143 | 0 | ▶ | $self->{HANDLERS} = @_ if @_ ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 144 | return map ref $_ | ||||||||||||||||||||||||||||
| 145 | ? do { | ||||||||||||||||||||||||||||
| 146 | 0 | my $action = $self->machine->action_by_id( $$_ ); | |||||||||||||||||||||||||||
| 147 | 0 | ▶ | die "Action $$_ for arc ", | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 148 | $self->name, | ||||||||||||||||||||||||||||
| 149 | " (id ", | ||||||||||||||||||||||||||||
| 150 | $self->id, | ||||||||||||||||||||||||||||
| 151 | ") not defined\n" | ||||||||||||||||||||||||||||
| 152 | unless $action; | ||||||||||||||||||||||||||||
| 153 | 0 | $action->handlers; | |||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | : $_, | ||||||||||||||||||||||||||||
| 156 | 0 | ▶ | @{$self->{HANDLERS}} ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 0 | ▶ | sub handler_descriptions { | ||||||||||||||||||||||||||
|
Subroutine
handler_descriptions: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 161 | 0 | my $self = shift ; | |||||||||||||||||||||||||||
| 162 | return map ref $_ | ||||||||||||||||||||||||||||
| 163 | ? do { | ||||||||||||||||||||||||||||
| 164 | 0 | my $action = $self->machine->action_by_id( $$_ ); | |||||||||||||||||||||||||||
| 165 | 0 | ▶ | die "Action $$_ for arc ", | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 166 | $self->name, | ||||||||||||||||||||||||||||
| 167 | " (id ", | ||||||||||||||||||||||||||||
| 168 | $self->id, | ||||||||||||||||||||||||||||
| 169 | ") not defined\n" | ||||||||||||||||||||||||||||
| 170 | unless $action; | ||||||||||||||||||||||||||||
| 171 | 0 | my $desc = $action->description; | |||||||||||||||||||||||||||
| 172 | 0 | ▶ | defined $desc ? $desc : $action->handlers; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 173 | } | ||||||||||||||||||||||||||||
| 174 | : $_, | ||||||||||||||||||||||||||||
| 175 | 0 | ▶ | @{$self->{HANDLERS}} ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 176 | } | ||||||||||||||||||||||||||||
| 177 | |||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 0 | ▶ | sub add_handler { | ||||||||||||||||||||||||||
|
Subroutine
add_handler: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 180 | 0 | my $self = shift ; | |||||||||||||||||||||||||||
| 181 | 0 | push @{$self->{HANDLERS}}, @_ ; | |||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||
| 185 | 0 | ▶ | sub handler_attributes { | ||||||||||||||||||||||||||
|
Subroutine
handler_attributes: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 186 | 0 | my $self = shift ; | |||||||||||||||||||||||||||
| 187 | return map ref $_ | ||||||||||||||||||||||||||||
| 188 | ? do { | ||||||||||||||||||||||||||||
| 189 | 0 | my $action = $self->machine->action_by_id( $$_ ); | |||||||||||||||||||||||||||
| 190 | 0 | ▶ | die "Action $$_ for arc ", | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 191 | $self->name, | ||||||||||||||||||||||||||||
| 192 | " (id ", | ||||||||||||||||||||||||||||
| 193 | $self->id, | ||||||||||||||||||||||||||||
| 194 | ") not defined\n" | ||||||||||||||||||||||||||||
| 195 | unless $action; | ||||||||||||||||||||||||||||
| 196 | 0 | $action->attributes( @_ ); | |||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||
| 198 | : (), | ||||||||||||||||||||||||||||
| 199 | 0 | ▶ | @{$self->{HANDLERS}} ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 200 | } | ||||||||||||||||||||||||||||
| 201 | |||||||||||||||||||||||||||||
| 202 | |||||||||||||||||||||||||||||
| 203 | =item attribute | ||||||||||||||||||||||||||||
| 204 | |||||||||||||||||||||||||||||
| 205 | Like StateML::Object::attribute, but inherits from the event. | ||||||||||||||||||||||||||||
| 206 | |||||||||||||||||||||||||||||
| 207 | =cut | ||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||
| 209 | 0 | ▶ | sub attribute { | ||||||||||||||||||||||||||
|
Subroutine
attribute: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 210 | 0 | my $self = shift ; | |||||||||||||||||||||||||||
| 211 | |||||||||||||||||||||||||||||
| 212 | 0 | my $a = $self->SUPER::attribute( @_ ) ; | |||||||||||||||||||||||||||
| 213 | 0 | ▶ | if ( @_ < 3 && ! defined $a ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@_ < 3 and not defined $a
MC/DC0%0/2
@_ < 3 and not defined $a
@_ < 3
not defined $a
Truth table0%0/3
A and not(B)
A= @_ < 3B= not defined $a
| |||||||||||||||||||||||||||||
| 214 | 0 | my $e = $self->machine->object_by_id( $self->event_id ) ; | |||||||||||||||||||||||||||
| 215 | 0 | ▶ | $a = $e->attribute( @_ ) if defined $e ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 | 0 | ▶ | sub attributes { | ||||||||||||||||||||||||||
|
Subroutine
attributes: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||
| 229 | 0 | my $self = shift ; | |||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||
| 231 | 0 | my $e = $self->machine->object_by_id( $self->event_id ) ; | |||||||||||||||||||||||||||
| 232 | 0 | my @ea ; | |||||||||||||||||||||||||||
| 233 | 0 | ▶ | @ea = $e->attributes( @_ ) if defined $e ; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 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 <barries@slaysys.com> | ||||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | =cut | ||||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | |||||||||||||||||||||||||||||
| 260 | 3 | 1 ; | |||||||||||||||||||||||||||