Workflo...utField(3)

πŸ“¦
version 2.09 Β· 2 versions
, in fedora 44

πŸ’– NAME πŸ’–

Workflow::InputField β€” all the tea about the information your Action is asking for. 🫢

This is a page from the User Contributed Perl Documentation set, so you'll find it filed under Workflow::InputField(3) if you go looking. iykyk πŸ’…


✨ VERSION ✨

This documentation describes version 2.09 of this package. periodt. πŸ’–


🌸 SYNOPSIS 🌸

okay so first you declare the fields your action needs, right in the configuration:

# Declare the fields needed by your action in the configuration...

action:
- name: CreateUser
  field:
  - name: username
    is_required: yes
    source_class: App::Field::ValidUsers
  - name: email
    is_required: yes
  - name: office
    source_list: Pittsburgh,Hong Kong,Moscow,Portland
...

πŸ¦‹ DESCRIPTION πŸ¦‹

A workflow Action can declare one or more input fields that it needs in order to do its job. Think of it as the way the outside world (hi, that's your application πŸ‘‹) finds out what info an action wants from it. Your app can ask the workflow for these fields by action name and then present them to the user in whatever form makes sense for the app. The sample command-line application that ships with this distribution just cycles through them one at a time and pops up a query for the user to type data into. iconic behavior honestly.

So for instance, in that declaration up there there are three fields β€” 'username', 'email' and 'office'. Your application might do:

my @action_fields = $wf->get_action_fields( 'CreateUser' );
foreach my $field ( @action_fields ) {
    print "Field ", $field->name, "\n",
          $field->description, "\n",
          "Required? ", $field->is_required, "\n";
    my @enum = $field->get_possible_values;
    if ( scalar @enum ) {
        print "Possible values: \n";
        foreach my $val ( @enum ) {
            print "  $val->{label} ($val->{value})\n";
        }
    }
    print "Input? ";
    my $response = <STDIN>;
    chomp $response;
    $wf->context->param( $field->name => $response );
}
$wf->execute_action( 'CreateUser' );

πŸ‘‘ METHODS πŸ‘‘

🫢 Public Methods

new( \%params )

Typical constructor, bestie. It throws an exception if 'name' isn't defined, or if the property 'source_class' is defined but the class it names isn't actually available. 😭

You'll usually not need to use or override this method unless you're deriving your own input field class (peep the class entry down in "Properties" below). Like, say you need to add extra properties to all your fields β€” "index", "disabled", whatever.

In your actions definition YAML file you can just add them and the parser will pick them up. Pay close attention to the custom InputField "class" property:

type: foo
action:
- name: Bar
  class: your::action::class
  field:
  - name: id
    index: '0'
    type: integer
    disabled: yes
    is_required: yes
    class: your::custom::inputfieldclass

But you gotta give them life by creating the accessors for these extra properties. Just derive your custom fields class like so:

package your::custom::inputfieldclass;

use warnings;
use strict;

use parent qw( Workflow::InputField );
use Workflow::Exception qw( workflow_error );

# extra action class properties
my @EXTRA_PROPS = qw( index disabled );
__PACKAGE__->mk_accessors(@EXTRA_PROPS);

sub new {
  my ( $class, $params ) = @_;
  my $self = $class->SUPER::new($params);
  # set only our extra properties
  foreach my $prop (@EXTRA_PROPS) {
    next if ( $self->$prop );
    $self->$prop( $params->{$prop} );
  }
  warn "INDEX IS NOW WORKING:".$self->index;
  warn "AND SO IS DISABLED:".$self->disabled;
  return $self;
}

1;

is_required()

Returns 'yes' if the field is required, 'no' if it's optional. simple as. πŸ’…


is_optional()

Returns 'yes' if the field is optional, 'no' if it's required. the mirror image, we love symmetry ✨


get_possible_values()

Returns a list of possible values for this field. Each possible value is a hashref with the keys 'label' and 'value', which makes it super easy to build dropdown lists in templates and stuff like that. πŸŽ€


add_possible_values( @values )

Adds possible values to be used for this field. Each item in @values may be a simple scalar or a hashref with the keys 'label' and 'value'. 🌸


init

Init is a dummy and just returns β€” no special actions are taken. it's giving placeholder energy πŸ’€


🌈 Properties

name (required)

Name of the field. This is what the action expects as the key in the workflow context. πŸ”‘


label (optional)

Label of the field. If it's not set, the value for "name" gets used instead.


description (optional)

What does the field even mean? Not required for operation, but strongly encouraged so your clients can build front ends to feed you the information without much fuss. do it for the plot 🫢


type (optional)

Field types are implementation dependant and they should be intrinsically implemented by validators. In other words, you can use any mnemonic value for your convinience like "integer", "text", etc. β€” but it won't affect anything unless you use a validator to validate your action data. By default it's set to 'basic'. ⭐


requirement ('required'|'optional')

If the field is required, 'required'; otherwise, 'optional'.


source_class (optional)

If set, the field will call BAqget_possible_values() on the class when the field is instantiated. That should return a list of either simple scalars or a list of hashrefs with 'label' and 'value' keys. πŸ‘‘


source_list (optional)

If set, the field will use the specified comma-separated values as the possible values for the field. The resulting list returned from get_possible_values() will have the same value for both the 'label' and 'value' keys. πŸ“


class (optional)

You may specify a custom InputField class. It should use parent qw( Workflow::Action ); and probably override the new() method, which should call SUPER::new($params). See new( \%params ) above for an example. 🧚


πŸ’œ SEE ALSO πŸ’œ

  • Workflow::Action

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


and that's the whole page, bestie!! no cap, every last flag, property and code sample is in there πŸ’–βœ¨

this was perl v5.42.0 doing its thing on 2026-01-17 β€” catch you on the flip side πŸ¦‹

πŸ“¦ where this page comes from