You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Copy file name to clipboardexpand all lines: Documentation.md
+33-32
Original file line number
Diff line number
Diff line change
@@ -36,7 +36,7 @@ SYNOPSIS
36
36
37
37
my $open = Tinky::Transition.new(name => 'open', from => $state-new, to => $state-open);
38
38
39
-
# Where more than one transition has the same name, the transition which matches the object's
39
+
# Where more than one transition has the same name, the transition which matches the object's
40
40
# current state will be use.
41
41
my $reject-new = Tinky::Transition.new(name => 'reject', from => $state-new, to => $state-rejected);
42
42
my $reject-open = Tinky::Transition.new(name => 'reject', from => $state-open, to => $state-rejected);
@@ -64,7 +64,7 @@ SYNOPSIS
64
64
my $workflow = Tinky::Workflow.new(:@transitions, name => 'ticket-workflow', initial-state => $state-new );
65
65
66
66
# The workflow aggregates the Supplies of the transitions and the states.
67
-
# This could be to a logging subsystem for instance.
67
+
# This could be to a logging subsystem for instance.
68
68
69
69
$workflow.transition-supply.act(-> ($trans, $object) { say "Ticket '{ $object.ticket-number }' went from { $trans.from.name }' to '{ $trans.to.name }'" });
70
70
@@ -126,8 +126,8 @@ All those subroutines that would accept the supplied Tinky::Object will be calle
126
126
127
127
A similar mechanism is used for method callbacks.
128
128
129
-
class Tinky::State
130
-
-------------------
129
+
class Tinky::State
130
+
------------------
131
131
132
132
The [Tinky::State](Tinky::State) is the managed state that is applied to an object, it provides a mechanism for validating whether on object should enter or leave a particular state and supplies that emit objects that have entered or left a given state.
133
133
@@ -143,7 +143,7 @@ The constructor must be supplied with a `name` named parameter which must be uni
143
143
144
144
method enter(Object:D $object)
145
145
146
-
This is called with the [Tinky::Object](Tinky::Object) instance when the state has been entered by the object, the default implementation arranges for the object to be emitted on the `enter-supply`, so if it is over-ridden in a sub-class it should nonetheless call the base implementation with `nextsame` in order to provide the object to the supply. It would probably be better however to simply tap the [enter-supply](enter-supply).
146
+
This is called with the [Tinky::Object](Tinky::Object) instance when the state has been entered by the object, the default implementation arranges for the object to be emitted on the `enter-supply`, so if it is over-ridden in a sub-class it should nonetheless call the base implementation with `nextsame` in order to provide the object to the supply. It would probably be better however to simply tap the [enter-supply](enter-supply).
147
147
148
148
### method validate-enter
149
149
@@ -161,15 +161,15 @@ This returns a [Supply](Supply) to which is emitted each object that has success
161
161
162
162
method leave(Object:D $object)
163
163
164
-
This is called when an object leaves this state, with the object instance as the argument. Like <enter> the default implementation provides for the object to emitted on the `leave-supply` so any over-ride implementation should arrange to call this base method. Typically it would be preferred to tap the `leave-supply` if some action is required on leaving a state.
164
+
This is called when an object leaves this state, with the object instance as the argument. Like <enter> the default implementation provides for the object to emitted on the `leave-supply` so any over-ride implementation should arrange to call this base method. Typically it would be preferred to tap the `leave-supply` if some action is required on leaving a state.
This is called prior to the transition being actually performed and returns a [Promise](Promise) that will be kept with [True](True) if all of the leave validators return True, or False otherwise. It can be over-ridden in a sub-class if some other validation mechanism to the callbacks is required, but **must** return a [Promise](Promise)
171
171
172
-
### method leave-supply
172
+
### method leave-supply
173
173
174
174
method leave-supply() returns Supply
175
175
@@ -183,8 +183,8 @@ This returns a sensible string representation of the State,
183
183
184
184
### method ACCEPTS
185
185
186
-
multi method ACCEPTS(State:D $state) returns Bool
187
-
multi method ACCEPTS(Transition:D $transition) returns Bool
186
+
multi method ACCEPTS(State:D $state) returns Bool
187
+
multi method ACCEPTS(Transition:D $transition) returns Bool
188
188
multi method ACCEPTS(Object:D $object) returns Bool
189
189
190
190
This provides for smart-matching against another [State](State) ( returning true if they evaluate to the same state,) a [Transition](Transition) ( returning True if the `from` State of the transition is the same as this state,) or a [Tinky::Object](Tinky::Object) ( returnning True if the Object is at the State.)
@@ -215,16 +215,16 @@ Alternatively a sub-class can define validator methods with the `leave-validator
215
215
216
216
This may be useful if you have fixed states and wish to substitute runtime complexity.
217
217
218
-
class Tinky::Transition
219
-
------------------------
218
+
class Tinky::Transition
219
+
-----------------------
220
220
221
221
A transition is the configured change between two pre-determined states, Only changes described by a transition are allowed to be performed. The transaction class provides for validators that can indicate whether the transition should be applied to an object (distinct from the enter or leave state validators,) and provides a separate supply that emits the object whenever the transition is succesfully applied to an object's state. This higher level of granularity may simplify application logic when in some circumstances than taking both from state and to state individually.
The constructor of the class, The `name` parameter must be supplied, it need not be unique but will be used to create a helper method that will be applied to the target Object when the workflow is applied so should be a valid Perl 6 identifier. The mechanism for creating these methods is decribed under [Tinky::Workflow](Tinky::Workflow).
227
+
The constructor of the class, The `name` parameter must be supplied, it need not be unique but will be used to create a helper method that will be applied to the target Object when the workflow is applied so should be a valid Raku identifier. The mechanism for creating these methods is decribed under [Tinky::Workflow](Tinky::Workflow).
228
228
229
229
The `from` and `to` states must be supplied, A transition can only be supplied to an object that has a current state that matches `from`.
230
230
@@ -248,7 +248,7 @@ This can be over-ridden in a sub-class if some other validation mechanism is to
This is the top-level method that is used to check whether a transition should be applied, it returns a Promise that will be kept with True if all of the promises returned by the transition's `validate`, the `from` state's `leave-validate` and the `to` state's `enter-validate` are kept with True.
251
+
This is the top-level method that is used to check whether a transition should be applied, it returns a Promise that will be kept with True if all of the promises returned by the transition's `validate`, the `from` state's `leave-validate` and the `to` state's `enter-validate` are kept with True.
252
252
253
253
It is unlikely that this would need to over-ridden but any sub-class implementation must return a Promise that will be kept with a Bool.
254
254
@@ -268,10 +268,10 @@ Returns a plausible string representation of the transition.
268
268
269
269
### method ACCEPTS
270
270
271
-
multi method ACCEPTS(State:D $state) returns Bool
271
+
multi method ACCEPTS(State:D $state) returns Bool
272
272
multi method ACCEPTS(Object:D $object) returns Bool
273
273
274
-
This is used to smart match the transition against either a [Tinky::State](Tinky::State) (returning True if the State matches the transition's `from` state,) or a [Tink::Object](Tink::Object) (returning True if the object's current state matches the transition's `from` state.)
274
+
This is used to smart match the transition against either a [Tinky::State](Tinky::State) (returning True if the State matches the transition's `from` state,) or a [Tinky::Object](Tinky::Object) (returning True if the object's current state matches the transition's `from` state.)
275
275
276
276
### attribute validators
277
277
@@ -285,10 +285,10 @@ Alternatively validators can be supplied as methods with the `transition-validat
285
285
286
286
The same rules for execution based on the signature and the object to which the transition is being applied are true for methods as for validation subroutines.
287
287
288
-
class Tinky::Workflow
289
-
----------------------
288
+
class Tinky::Workflow
289
+
---------------------
290
290
291
-
The [Tinky::Workflow](Tinky::Workflow) class brings together a collection of transitions together and provides additional functionality to objects that consume the workflow as well as aggregating the various [Supply](Supply)s that are provided by State and Transition.
291
+
The [Tinky::Workflow](Tinky::Workflow) class brings together a collection of transitions together and provides additional functionality to objects that consume the workflow as well as aggregating the various [Supply](Supply)s that are provided by State and Transition.
292
292
293
293
Whilst it is possible that standalone transitions can be applied to any object that does the [Tinky::Object](Tinky::Object) role, certain functionality is not available if workflow is not known.
294
294
@@ -390,10 +390,10 @@ Alternatively validators can be supplied as methods with the `apply-validator` t
390
390
391
391
The same rules for execution based on the signature and the object to which the transition is being applied are true for methods as for validation subroutines.
392
392
393
-
role Tinky::Object
394
-
-------------------
393
+
role Tinky::Object
394
+
------------------
395
395
396
-
This is a role that should should be applied to any application object that is to have a state managed by [Tink::Workflow](Tink::Workflow), it provides the mechanisms for transition application and allows the transitions to be validated by the mechanisms described above for [Tinky::State](Tinky::State) and [Tinky::Transition](Tinky::Transition)
396
+
This is a role that should should be applied to any application object that is to have a state managed by [Tinky::Workflow](Tinky::Workflow), it provides the mechanisms for transition application and allows the transitions to be validated by the mechanisms described above for [Tinky::State](Tinky::State) and [Tinky::Transition](Tinky::Transition)
397
397
398
398
### method state
399
399
@@ -435,52 +435,53 @@ This returns the transition that would place the object in the supplied state fr
435
435
436
436
### method ACCEPTS
437
437
438
-
multi method ACCEPTS(State:D $state) returns Bool
438
+
multi method ACCEPTS(State:D $state) returns Bool
439
439
multi method ACCEPTS(Transition:D $trans) returns Bool
440
440
441
441
Used to smart match the object against either a State (returns True if the state matches the current state of the object,) or a Transition (returns True if the `from` state matches the current state of the object.)
442
442
443
443
EXCEPTIONS
444
444
----------
445
445
446
-
The methods for applying a transition to an object will signal an inability to apply the transition by means of an exception.
446
+
The methods for applying a transition to an object will signal an inability to apply the transition by means of an exception.
447
447
448
448
The below documents the location where the exceptions are thrown directly, of course they may be the result of some higher level method.
449
449
450
-
### class Tinky::X::Fail is Exception
450
+
### class Tinky::X::Fail is Exception
451
451
452
452
This is used as a base class for all of the exceptions thrown by Tinky, it will never be thrown itself.
453
453
454
454
### class Tinky::X::Workflow is Tinky::X::Fail
455
455
456
456
This is an additional sub-class of [Tinky::X::Fail](Tinky::X::Fail) that is used by some of the other exceptions.
457
457
458
-
### class Tinky::X::InvalidState is Tinky::X::Workflow
458
+
### class Tinky::X::InvalidState is Tinky::X::Workflow
459
459
460
-
### class Tinky::X::InvalidTransition is Tinky::X::Workflow
460
+
### class Tinky::X::InvalidTransition is Tinky::X::Workflow
461
461
462
462
This will be thrown by the helper methods provided by the application of the workflow if the current state of the object does match the `from` state of any of the applicable transitions. It will also be thrown by `apply-transition` if the `from` state of the transition supplied doesn't match the current state of the object.
463
463
464
-
### class Tinky::X::NoTransition is Tinky::X::Fail
464
+
### class Tinky::X::NoTransition is Tinky::X::Fail
465
465
466
466
This will be thrown when attempting to set the state of the object by assignment when there is no transition that goes from the object's current state to the supplied state.
467
467
468
-
### class Tinky::X::NoWorkflow is Tinky::X::Fail
468
+
### class Tinky::X::NoWorkflow is Tinky::X::Fail
469
469
470
470
This is thrown by `transitions` and `transitions-for-state` on the [Tinky::Object](Tinky::Object) if they are called when no workflow has yet been applied to the object.
471
471
472
-
### class Tinky::X::NoTransitions is Tinky::X::Fail
472
+
### class Tinky::X::NoTransitions is Tinky::X::Fail
473
473
474
474
This is thrown by the [Workflow](Workflow)`states` method if it is called and there are no transitions defined.
475
475
476
-
### class Tinky::X::TransitionRejected is Tinky::X::Fail
476
+
### class Tinky::X::TransitionRejected is Tinky::X::Fail
477
477
478
478
This is thrown by `apply-transition` when the transition validation resulted in a False value, because the transition, leave state or enter state validators returned false.
479
479
480
-
### class Tinky::X::ObjectRejected is Tinky::X::Fail
480
+
### class Tinky::X::ObjectRejected is Tinky::X::Fail
481
481
482
482
This is thrown on `apply-workflow` if one or more of the workflow's apply validators returned false.
483
483
484
-
### class Tinky::X::NoState is Tinky::X::Fail
484
+
### class Tinky::X::NoState is Tinky::X::Fail
485
485
486
486
This will be thrown by apply-transition if there is no current state on the object.
0 commit comments