Skip to content

Commit

Permalink
Some renaming and a light spring clean
Browse files Browse the repository at this point in the history
  • Loading branch information
jonathanstowe committed Jan 18, 2021
1 parent 418b41a commit 06db9c2
Show file tree
Hide file tree
Showing 15 changed files with 65 additions and 60 deletions.
3 changes: 3 additions & 0 deletions Changes
Original file line number Diff line number Diff line change
@@ -1,3 +1,6 @@
v0.1.0 Mon 18 Jan 10:15:01 GMT 2021
* Light renaming
* Move CI to github actions
v0.0.8 Wed 13 Mar 21:24:52 GMT 2019
* Small change to support Tinky::DB
v0.0.7 Tue 29 Jan 19:20:46 GMT 2019
Expand Down
65 changes: 33 additions & 32 deletions Documentation.md
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ SYNOPSIS

my $open = Tinky::Transition.new(name => 'open', from => $state-new, to => $state-open);

# Where more than one transition has the same name, the transition which matches the object's
# Where more than one transition has the same name, the transition which matches the object's
# current state will be use.
my $reject-new = Tinky::Transition.new(name => 'reject', from => $state-new, to => $state-rejected);
my $reject-open = Tinky::Transition.new(name => 'reject', from => $state-open, to => $state-rejected);
Expand Down Expand Up @@ -64,7 +64,7 @@ SYNOPSIS
my $workflow = Tinky::Workflow.new(:@transitions, name => 'ticket-workflow', initial-state => $state-new );

# The workflow aggregates the Supplies of the transitions and the states.
# This could be to a logging subsystem for instance.
# This could be to a logging subsystem for instance.

$workflow.transition-supply.act(-> ($trans, $object) { say "Ticket '{ $object.ticket-number }' went from { $trans.from.name }' to '{ $trans.to.name }'" });

Expand Down Expand Up @@ -126,8 +126,8 @@ All those subroutines that would accept the supplied Tinky::Object will be calle

A similar mechanism is used for method callbacks.

class Tinky::State
-------------------
class Tinky::State
------------------

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.

Expand All @@ -143,7 +143,7 @@ The constructor must be supplied with a `name` named parameter which must be uni

method enter(Object:D $object)

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).
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).

### method validate-enter

Expand All @@ -161,15 +161,15 @@ This returns a [Supply](Supply) to which is emitted each object that has success

method leave(Object:D $object)

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 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.

### method validate-leave

method validate-leave(Object $object) returns Promise

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)

### method leave-supply
### method leave-supply

method leave-supply() returns Supply

Expand All @@ -183,8 +183,8 @@ This returns a sensible string representation of the State,

### method ACCEPTS

multi method ACCEPTS(State:D $state) returns Bool
multi method ACCEPTS(Transition:D $transition) returns Bool
multi method ACCEPTS(State:D $state) returns Bool
multi method ACCEPTS(Transition:D $transition) returns Bool
multi method ACCEPTS(Object:D $object) returns Bool

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.)
Expand Down Expand Up @@ -215,16 +215,16 @@ Alternatively a sub-class can define validator methods with the `leave-validator

This may be useful if you have fixed states and wish to substitute runtime complexity.

class Tinky::Transition
------------------------
class Tinky::Transition
-----------------------

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.

### method new

method new(Tinky::Transition:U: Str :$!name!, Tinky::State $!from!, Tinky::State $!to!, :@!validators)

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).
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).

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`.

Expand All @@ -248,7 +248,7 @@ This can be over-ridden in a sub-class if some other validation mechanism is to

method validate-apply(Object:D $object) returns Promise

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.
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.

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.

Expand All @@ -268,10 +268,10 @@ Returns a plausible string representation of the transition.

### method ACCEPTS

multi method ACCEPTS(State:D $state) returns Bool
multi method ACCEPTS(State:D $state) returns Bool
multi method ACCEPTS(Object:D $object) returns Bool

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.)
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.)

### attribute validators

Expand All @@ -285,10 +285,10 @@ Alternatively validators can be supplied as methods with the `transition-validat

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.

class Tinky::Workflow
----------------------
class Tinky::Workflow
---------------------

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.
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.

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.

Expand Down Expand Up @@ -390,10 +390,10 @@ Alternatively validators can be supplied as methods with the `apply-validator` t

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.

role Tinky::Object
-------------------
role Tinky::Object
------------------

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)
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)

### method state

Expand Down Expand Up @@ -435,52 +435,53 @@ This returns the transition that would place the object in the supplied state fr

### method ACCEPTS

multi method ACCEPTS(State:D $state) returns Bool
multi method ACCEPTS(State:D $state) returns Bool
multi method ACCEPTS(Transition:D $trans) returns Bool

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.)

EXCEPTIONS
----------

The methods for applying a transition to an object will signal an inability to apply the transition by means of an exception.
The methods for applying a transition to an object will signal an inability to apply the transition by means of an exception.

The below documents the location where the exceptions are thrown directly, of course they may be the result of some higher level method.

### class Tinky::X::Fail is Exception
### class Tinky::X::Fail is Exception

This is used as a base class for all of the exceptions thrown by Tinky, it will never be thrown itself.

### class Tinky::X::Workflow is Tinky::X::Fail

This is an additional sub-class of [Tinky::X::Fail](Tinky::X::Fail) that is used by some of the other exceptions.

### class Tinky::X::InvalidState is Tinky::X::Workflow
### class Tinky::X::InvalidState is Tinky::X::Workflow

### class Tinky::X::InvalidTransition is Tinky::X::Workflow
### class Tinky::X::InvalidTransition is Tinky::X::Workflow

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.

### class Tinky::X::NoTransition is Tinky::X::Fail
### class Tinky::X::NoTransition is Tinky::X::Fail

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.

### class Tinky::X::NoWorkflow is Tinky::X::Fail
### class Tinky::X::NoWorkflow is Tinky::X::Fail

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.

### class Tinky::X::NoTransitions is Tinky::X::Fail
### class Tinky::X::NoTransitions is Tinky::X::Fail

This is thrown by the [Workflow](Workflow) `states` method if it is called and there are no transitions defined.

### class Tinky::X::TransitionRejected is Tinky::X::Fail
### class Tinky::X::TransitionRejected is Tinky::X::Fail

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.

### class Tinky::X::ObjectRejected is Tinky::X::Fail
### class Tinky::X::ObjectRejected is Tinky::X::Fail

This is thrown on `apply-workflow` if one or more of the workflow's apply validators returned false.

### class Tinky::X::NoState is Tinky::X::Fail
### class Tinky::X::NoState is Tinky::X::Fail

This will be thrown by apply-transition if there is no current state on the object.

5 changes: 3 additions & 2 deletions META6.json
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
{
"name": "Tinky",
"version": "0.0.8",
"version": "0.1.0",
"auth": "github:jonathanstowe",
"api": "1.0",
"description": "An Experimental Workflow / State Management toolit",
Expand All @@ -11,6 +11,7 @@
"bugtracker": "https://github.com/jonathanstowe/Tinky/issues"
},
"perl": "6.*",
"raku": "6.*",
"resources": [ ],
"build-depends": [ ],
"depends": [ ],
Expand All @@ -29,5 +30,5 @@
"authors": [
"Jonathan Stowe <jns+git@gellyfish.co.uk>"
],
"meta-version": "0"
"meta-version": "1"
}
10 changes: 5 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
# Tinky

An experimental workflow module for Perl 6
An experimental workflow module for Raku

[![Build Status](https://travis-ci.org/jonathanstowe/Tinky.svg?branch=master)](https://travis-ci.org/jonathanstowe/Tinky)

Expand All @@ -9,6 +9,7 @@ An experimental workflow module for Perl 6
This is quite long [skip to the Description](#description) if you are impatient.

```perl6

use Tinky;


Expand Down Expand Up @@ -126,7 +127,7 @@ transition application,) is provided by Supplies which are available at

I have taken somewhat of a "kitchen-sink" toolkit approach with this to
provide a somewhat rich interface that can be more easily used to create
higher level applications which interact nicely with Perl 6's reactive
higher level applications which interact nicely with Raku's reactive
and composable nature. I've taken some ideas from similar software in
other languages that I have used and added features that I would have
liked for the problems that I was solving and ended up providing myself.
Expand All @@ -144,8 +145,7 @@ The full documentation is available [here](Documentation.md).

## Installation

Assuming you have a working perl6 installation you should be able to
install this with *zef* :
Assuming you have a working Rakudo installation you should be able to install this with *zef* :

# From the source directory

Expand All @@ -169,4 +169,4 @@ This is free software.

Please see the [LICENCE](LICENCE) file in the distribution.

© Jonathan Stowe 2016 - 2019
© Jonathan Stowe 2016 - 2021
2 changes: 1 addition & 1 deletion examples/encode-files
Original file line number Diff line number Diff line change
Expand Up @@ -124,4 +124,4 @@ multi sub MAIN($dir, Str :$out-dir = '/tmp/flac') {
}
}

# vim: expandtab shiftwidth=4 ft=perl6
# vim: expandtab shiftwidth=4 ft=raku
2 changes: 1 addition & 1 deletion examples/synopsis
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!perl6
#!/usr/bin/env raku

use Tinky;

Expand Down
6 changes: 3 additions & 3 deletions lib/Tinky.pm
Original file line number Diff line number Diff line change
Expand Up @@ -308,7 +308,7 @@ from state and to state individually.
The constructor of the class, The C<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
should be a valid Raku identifier. The mechanism for creating these
methods is decribed under L<Tinky::Workflow>.
The C<from> and C<to> states must be supplied, A transition can only
Expand Down Expand Up @@ -727,7 +727,7 @@ current state on the object.
=end pod

module Tinky:ver<0.0.8>:auth<github:jonathanstowe>:api<1.0> {
module Tinky:ver<0.1.0>:auth<github:jonathanstowe>:api<1.0> {

# Stub here, definition below
class State { ... };
Expand Down Expand Up @@ -1170,4 +1170,4 @@ module Tinky:ver<0.0.8>:auth<github:jonathanstowe>:api<1.0> {
}
}
}
# vim: expandtab shiftwidth=4 ft=perl6
# vim: expandtab shiftwidth=4 ft=raku
4 changes: 2 additions & 2 deletions t/001-meta.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!perl6
#!/usr/bin/env raku

use v6;

Expand Down Expand Up @@ -36,4 +36,4 @@ else {


done-testing;
# vim: expandtab shiftwidth=4 ft=perl6
# vim: expandtab shiftwidth=4 ft=raku
4 changes: 2 additions & 2 deletions t/010-use.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!perl6
#!/usr/bin/env raku

use v6;

Expand All @@ -7,4 +7,4 @@ use Test;
use-ok('Tinky', 'Can load "Tinky" ok');

done-testing;
# vim: expandtab shiftwidth=4 ft=perl6
# vim: expandtab shiftwidth=4 ft=raku
4 changes: 2 additions & 2 deletions t/020-matches.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!perl6
#!/usr/bin/env raku

use v6;

Expand Down Expand Up @@ -32,4 +32,4 @@ ok @transitions[0] ~~ $obj, "transition matches object";


done-testing;
# vim: expandtab shiftwidth=4 ft=perl6
# vim: expandtab shiftwidth=4 ft=raku
4 changes: 2 additions & 2 deletions t/030-apply-simple.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!perl6
#!/usr/bin/env raku

use v6;

Expand Down Expand Up @@ -27,4 +27,4 @@ $obj = FooTest.new;
throws-like { $obj.apply-transition(@transitions[0]) }, Tinky::X::NoState, "should throw X::NoState with apply-transition and state not set";

done-testing;
# vim: expandtab shiftwidth=4 ft=perl6
# vim: expandtab shiftwidth=4 ft=raku
4 changes: 2 additions & 2 deletions t/040-workflow-object.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!perl6
#!/usr/bin/env raku

use v6;

Expand Down Expand Up @@ -76,4 +76,4 @@ subtest {
}, "initial state on Workflow";

done-testing;
# vim: expandtab shiftwidth=4 ft=perl6
# vim: expandtab shiftwidth=4 ft=raku
4 changes: 2 additions & 2 deletions t/050-supplies.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!perl6
#!/usr/bin/env raku

use v6;

Expand Down Expand Up @@ -57,4 +57,4 @@ ok $final, "and got the final event";
is $applied, 1, "and we saw the application of the workflow";

done-testing;
# vim: expandtab shiftwidth=4 ft=perl6
# vim: expandtab shiftwidth=4 ft=raku
4 changes: 2 additions & 2 deletions t/060-callbacks.t
Original file line number Diff line number Diff line change
@@ -1,4 +1,4 @@
#!perl6
#!/usr/bin/env raku

use v6;

Expand Down Expand Up @@ -190,4 +190,4 @@ lives-ok { WorkflowGood.new.apply-workflow($apply-wf-meths) }, "Workflow.apply-w


done-testing;
# vim: expandtab shiftwidth=4 ft=perl6
# vim: expandtab shiftwidth=4 ft=raku

0 comments on commit 06db9c2

Please sign in to comment.