| Jifty documentation | view source | Contained in the Jifty distribution. |
Jifty::Param::Schema - Declare parameters of a Jifty action with ease.
package MyApp::Action::Login;
use Jifty::Param::Schema;
use Jifty::Action schema {
param email =>
label is 'Email address',
is mandatory,
ajax validates;
param password =>
type is 'password',
label is 'Password',
is mandatory;
param remember =>
type is 'checkbox',
label is 'Remember me?',
hints is 'If you want, your browser can remember your login for you',
default is 0;
};
This module provides a simple syntax to declare action parameters.
It re-exports defer and lazy from Scalar::Defer, for setting
parameter fields that must be recomputed at request-time:
param name =>
default is defer { Jifty->web->current_user->name };
See Scalar::Defer for more information about defer.
The schema block from a Jifty::Action subclass describes an action
for a Jifty application.
Within the schema block, the localization function _ is redefined
with defer, so that it resolves into a dynamic value that will be
recalculated upon each request, according to the user's current language
preference.
Each param statement inside the schema block sets out the name
and attributes used to describe one named parameter, which is then used
to build a Jifty::Param object. That class defines possible field names
to use in the declarative syntax here.
The param function is not available outside the schema block.
In addition to the labels provided by Jifty::Web::Form::Field and Jifty::Param, this module offers the following aliases:
ajax validates, # ajax_validates is 1
ajax canonicalizes, # ajax_canonicalizes is 1
order is -1, # sort_order is -1
default is 0, # default_value is 0
valid are qw( 1 2 3 ), # valid_values are qw( 1 2 3 )
available are qw( 1 2 3 ), # available_values are qw( 1 2 3 )
render as 'select', # render_as is 'select'
Takes two hashrefs. Merges them together and returns the merged hashref.
- Empty fields in subclasses don't override nonempty fields in superclass anymore.
- Arrays don't merge; e.g. if parent class's valid_values is [1,2,3,4], and
subclass's valid_values() is [1,2], they don't somehow become [1,2,3,4,1,2].
BUG: This should either be a private routine or factored out into Jifty::Util
| Jifty documentation | view source | Contained in the Jifty distribution. |