יובל קוג'מן (Yuval Kogman) > Class-Workflow > Class::Workflow::Transition::Validate

Download:
Class-Workflow-0.11.tar.gz

Dependencies

Annotate this POD

CPAN RT

Open  0
View/Report Bugs
Source   Latest Release: Class-Workflow-0.11_01

NAME ^

Class::Workflow::Transition::Validate - Provide a hook for validating a transition (conditionals, input validators, etc).

SYNOPSIS ^

        package MyTransition;
        use Moose;

        with qw/
                Class::Workflow::Transition
                Class::Workflow::Transition::Validate
        /;

        sub validate {
                my ( $self, $instance, %args ) = @_;

                die "only the owner can apply this transition"
                        unless $args{user} eq $instance->owner;
        }

DESCRIPTION ^

This role will call the validate method at the appropriate time.

validate receives the same arguments as apply, and is expected to die if any of the parameters for the transition are invalid.

Technically, this role doesn't do much more than adding syntactic sugar for before 'apply'. However, it's value is in the convention that you can call validate without applying the body. This eases writing side effect free introspection of transitions.

syntax highlighting: