
Jifty::Action - The ability to Do Things in the framework

package MyApp::Action::Foo;
use base qw/MyApp::Action Jifty::Action/;
sub take_action {
...
}
1;

Jifty::Action is the superclass for all actions in Jifty. Action classes form the meat of the Jifty framework; they control how form elements interact with the underlying model.
See also Jifty::Action::Record for data-oriented actions, Jifty::Result for how to return values from actions.
See Jifty::Action::Schema;

These common methods are designed to
Construct a new action. Subclasses who need do custom initialization should start with:
my $class = shift; my $self = $class->SUPER::new(@_)
Do not call this yourself; always go through Jifty->web->new_action! The arguments that this will be called with include:
The moniker of the action. Defaults to an autogenerated moniker.
An integer that determines the ordering of the action's execution. Lower numbers occur before higher numbers. Defaults to 0.
A hash reference of default values for the arguments of the action. Defaults to none.
A boolean value that determines if the form fields are sticky when the action fails. Defaults to true.
A boolean value that determines if the form fields are sticky when the action succeeds. Defaults to false.
Note: this API is now deprecated in favour of the declarative syntax offered by Jifty::Param::Schema.
This method, along with "take_action", is the most commonly overridden method. It should return a hash which describes the arguments this action takes:
{
argument_name => {label => "properties go in this hash"},
another_argument => {mandatory => 1}
}
Each argument listed in the hash will be turned into a Jifty::Web::Form::Field object. For each argument, the hash that describes it is used to set up the Jifty::Web::Form::Field object by calling the keys as methods with the values as arguments. That is, in the above example, Jifty will run code similar to the following:
# For 'argument_name' $f = Jifty::Web::Form::Field->new; $f->name( "argument_name" ); $f->label( "Properties go in this hash" );
If an action has parameters that must be passed to it to execute, these should have the constructor property set. This is separate from the mandatory property, which deal with requiring that the user enter a value for that field.
This routine, unsurprisingly, actually runs the action.
If the result of the action is currently a success (validation did not fail), run calls "take_action", and finally "cleanup".
If you're writing your own actions, you probably want to override take_action instead.
Checks authorization with "check_authorization", calls /setup, canonicalizes and validates each argument that was submitted, but doesn't actually call "take_action".
The outcome of all of this is stored on the "result" of the action.
Returns true if whoever invoked this action is authorized to perform this action.
By default, always returns true.
. setup is expected to return a true value, or "run" will skip all other actions.
By default, does nothing.
Do whatever the action is supposed to do. This and "arguments" are the most commonly overridden methods.
By default, does nothing.
The return value from this method is NOT returned. (Instead, you should be using the "result" object to store a result).
Perform any action-specific cleanup. By default, does nothing.
Runs after "take_action" -- whether or not "take_action" returns success.
Returns the moniker for this action.
Returns the value from the argument with the given name, for this action. If VALUE is provided, sets the value.
Returns true if the action has been provided with an value for the given argument, including a default_value, and false if none was ever passed in.
Returns a Jifty::Web::Form::Field object for this argument. If there is no entry in the "arguments" hash that matches the given ARGUMENT, returns undef.
Returns a Jifty::Web::Form::Field object that renders a display value instead of an editable widget for this argument. If there is no entry in the "arguments" hash that matches the given ARGUMENT, returns undef.
A shortcut for specifying a form field ARGUMENT which should render as a hidden form field, with the default value VALUE.
Gets or sets the order that the action will be run in. This should be an integer, with lower numbers being run first. Defaults to zero.
Returns the Jifty::Result method associated with this action. If an action with the same moniker existed in the last request, then this contains the results of that action.
Registers this action as being present, by outputting a snippet of HTML. This expects that an HTML form has already been opened. Note that this is not a guarantee that the action will be run, even if the form is submitted. See Jifty::Request for the definition of "active" actions.
Normally, "new_action" in Jifty::Web takes care of calling this when it is needed.
Render any the "error" in Jifty::Result of this action, if any, as HTML. Returns nothing.
Create and render a button. It functions nearly identically like "link" in Jifty::Web, except it takes arguments in addition to parameters, and defaults to submitting this Jifty::Action. Returns nothing.
Creates and renders a button, like "button", which additionally defaults to calling the current continuation.
Takes an additional argument, to, which can specify a default path to return to if there is no current continuation.

These methods return the names of HTML form elements related to this action.
Returns the name of the "registration" query argument for this action in a web form.
Turn one of this action's arguments into a fully qualified name; takes the name of the field as an argument.
Turn one of this action's arguments into a fully qualified "fallback" name; takes the name of the field as an argument.
This is specifically to support checkboxes, which only show up in the query string if they are checked. Jifty creates a checkbox with the value of form_field_name as its name and a value of 1, and a hidden input with the value of fallback_form_field_name as its name and a value of 0; using this information, Jifty::Request can both determine if the checkbox was present at all in the form, as well as its true value.
Turn one of this action's arguments into the id for the div in which its errors live; takes name of the field as an argument.
Turn one of this action's arguments into the id for the div in which its warnings live; takes name of the field as an argument.

Returns the list of argument names. This information is extracted from "arguments".
Canonicalizes each of the arguments that this action knows about.
This is done by calling "_canonicalize_argument" for each field described by "arguments".
Canonicalizes the value of an argument. If the argument has an attribute named canonicalizer, call the subroutine reference that attribute points points to.
If it doesn't have a canonicalizer attribute, but the action has a canonicalize_ARGUMENT function, also invoke that function.
If neither of those are true, by default canonicalize dates using _canonicalize_date
Parses and returns the date using Jifty::DateTime::new_from_string.
Validates the form fields. This is done by calling "_validate_argument" for each field described by "arguments"
Validate your form fields. If the field ARGUMENT is mandatory, checks for a value. If the field has an attribute named validator, call the subroutine reference validator points to.
If the action doesn't have an explicit validator attribute, but does have a validate_ARGUMENT function, invoke that function.
Get back a list of possible completions for ARGUMENT. The list should either be a list of scalar values or a list of hash references. Each hash reference must have a key named value. There can also additionally be a key named label which, if present, will be used as the user visible label. If label is not present then the contents of value will be used for the label.
If the field has an attribute named autocompleter, call the subroutine reference autocompleter points to.
If the field doesn't have an explicit autocompleter attribute, but does have a autocomplete_ARGUMENT function, invoke that function.
Given an parameter name, returns the list of valid values for it, based on its valid_values field.
This method returns a hash referenece with a display field for the string to display for the value, and a value field for the value to actually send to the server.
(Avoid using this -- this is not the appropriate place for this logic to be!)
Just like valid_values, but if our action has a set of available recommended values, returns that instead. (We use this to differentiate between a list of acceptable values and a list of suggested values)
Used to report an error during validation. Inside a validator you should write:
return $self->validation_error( $field => "error");
..where $field is the name of the argument which is at fault.
Used to report a warning during validation. Inside a validator you should write:
return $self->validation_warning( $field => "warning");
..where $field is the name of the argument which is at fault.
Used to report that a field does validate. Inside a validator you should write:
return $self->validation_ok($field);
Autogenerated Actions will always return true when this method is called. "Regular" actions will return false.