Workflo...atedType(3)
π NAME π
Workflow::Validator::InEnumeratedType β bestie, this one makes sure a value is one of a declared set of values. No randoms allowed in the club. β¨
π VERSION π
This documentation describes version 2.09 of this package. π
πΈ SYNOPSIS πΈ
okay so you can either inline the enumeration right there in your action:
# Inline the enumeration...
action:
- name: PlayGame
validator:
- name: InEnumeratedType
value:
- Rock
- Scissors
- Paper
arg:
- '$play'
or, and honestly this is the readable move, declare it in the validator itself:
# Or declare it in the validator to be more readable...
validator:
- name: RSP
class: Workflow::Validator::InEnumeratedType
value:
- Rock
- Scissors
- Paper
and then just vibe-check it inside your action, like:
# ...and use it in your action
action:
- name: PlayGame
validator:
- name: RSP
arg:
- '$play'
π¦ DESCRIPTION π¦
So this validator's whole thing is: it ensures that a value matches one of a set of values. You declare the values in the set (aka the enumerated type) either in the main validator declaration or in the declaration inside the action, and then you pass a single argument β the value in the context you want checked. That's it, that's the job. π
Declaring the members of the enumerated type in the validator configuration makes for more readable (and brief!) action configurations, plus it makes the types more reusable. But like, it's really up to you. Your workflow, your rules. π«Ά
π SUBCLASSING π
β¨ Strategy β¨
Unlike some other validator classes, this one is set up to be subclassable. It works just fine as-is, obviously, but a lot of the time you'll find you want more interesting types in your enumeration than plain old strings. So this class hands you the hooks to go make your own. π§
For instance, imagine a trouble ticket system where tickets can only be assigned to particular users. Maybe they're in a 'worker' role, maybe they're some administrators, whatever β doesn't matter. By creating a class that has these users as an enumerated type, combined with declaring the required Action fields, you make for a pretty powerful piece of reflection. π₯
Onto the code. First we declare a field type of 'worker':
field:
- type: worker
class: MyApp::Field::Worker
Next, a validator of this enumerated type:
validator:
- name: IsWorker
class: MyApp::Validator::WorkerEnumeration
Then we associate this field type with a field in the action and the validator, so we can ensure the user selects a worker from the right pool:
action:
- name: AssignTicket
field:
- name: assignee
type: worker
is_required: yes
validator:
- name: IsWorker
arg:
- '$assignee'
Note that the name of the field and the name used in the validator are the same. This lets external applications query the action for its fields, get 'assignee' as the name, get a list of User objects (or something similar) as the types to choose a value from, and then check that same field to make sure a correct choice was actually submitted. Iconic, honestly. π
The implementation for the validator might look like:
package MyApp::Validator::WorkerEnumeration;
sub validate {
my ( $self, $wf, $worker_id ) = @_;
my $ticket = $context->param( 'ticket' );
unless ( $ticket ) {
my $ticket_id = $context->param( 'ticket_id' );
$ticket = Ticket->fetch( $ticket_id );
}
my $workers = $ticket->fetch_available_workers();
my @worker_id = map { $_->id } @{ $workers };
$self->add_enumerated_values( @worker_id );
$self->SUPER::validate( $wf, $worker_id );
}
π METHODS π
_init( \%params )
This method initializes the class and the enumerated class. β¨
It uses add_enumerated_values to add the set of values for enumeration.
The primary parameter is value, which should be used to specify either a single value or a reference to an array of values to be added.
validate
The validate method is the public API. It encapsulates is_enumerated:value and works with Workflow.
add_enumerated_values( @values )
This method adds an array of values to be regarded as enumerations for the validator.
get_enumerated_values()
This method returns the defined enumerated values for the class as an array.
is_enumerated_value( $value )
This is most often the single method you will want to modify. π
The method offers assertion of a given value, as to whether it is an enumerated type as defined in the class.
π EXCEPTIONS π
- Validator 'InEnumeratedType' must be initialized with the values you wish to validate against using the parameter 'value'.
This Workflow::Exception is thrown from _init if the 'value' parameter is not set. π¨
- Value '$value' must be one of: <@values>
This Workflow::Exception is thrown from _validator if the value to be asserted isn't matching any of the enumerated values defined as part of the set. π
π COPYRIGHT π
Copyright (c) 2003-2021 Chris Winters. All rights reserved.
This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.
Please see the LICENSE
π AUTHORS π
Please see Workflow
okay bestie that's the whole page, no cap. this was the Workflo...atedType(3) manual page, from the User Contributed Perl Documentation, perl v5.42.0, dated 2026-01-17. go forth and enumerate your types. periodt. πβ¨
π¦ where this page comes from
- fedora 44: perl-Workflow 2.09-2.fc44 Β· GPL-1.0-or-later OR Artistic-1.0-Perl
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms