NAME
Jifty::Web - Web framework for a Jifty application
METHODS
new
Creates a new Jifty::Web
object
mason
Returns a HTML::Mason::Request object
out
Send a string to the browser. The default implementation uses Mason->out;
url
Returns the root url of this Jifty application. This is pulled from the configuration file.
serial
Returns a unique identifier, guaranteed to be unique within the runtime of a particular process (ie, within the lifetime of Jifty.pm). There's no sort of global uniqueness guarantee, but it should be good enough for generating things like moniker names.
SESSION MANAGEMENT
setup_session
Sets up the current session
object (a Jifty::Web::Session tied hash). Aborts if the session is already loaded.
session
Returns the current session's hash. In a regular user environment, it persists, but a request can stop that by handing it a regular hash to use.
CURRENT USER
current_user [USER]
Getter/setter for the current user; this gets or sets the 'user' key in the session. These are Jifty::Record objects.
If a temporary_current_user has been set, will return that instead.
If the current application has no loaded current user, we get an empty app-specific CurrentUser
object. (This is determined by theframework
configuration varialbe CurrentUserClass
and defaults to $AppName::CurrentUser
, a subclass of Jifty::CurrentUser. $AppName::CurrentUser
is autogenerated if it doesn't exist.
temporary_current_user [USER]
Sets the current request's current_user to USER if set.
This value will _not_ be persisted to the session at the end of the request. To restore the original value, set temporary_current_user to undef.
REQUEST
handle_request [REQUEST]
This method sets up a current session, and then processes the given Jifty::Request object. If no request object is given, processes the request object in "request".
Each action on the request is vetted in three ways -- first, it must be marked as active
by the Jifty::Request (this is the default). Second, it must be in the set of allowed classes of actions (see "is_allowed", below). Finally, the action must validate. If it passes all of these criteria, the action is fit to be run.
Before they are run, however, the request has a chance to be interrupted and saved away into a continuation, to be resumed at some later point. This is handled by "save_continuation".
If the continuation isn't being saved, then handle_request
goes on to run all of the actions. If all of the actions are successful, it looks to see if the request wished to call any continuations, possibly jumping back and re-running a request that was interrupted in the past. This is handled by "call_continuation".
For more details about continuations, see Jifty::Continuation.
request [VALUE]
Gets or sets the current Jifty::Request object.
response [VALUE]
Gets or sets the current Jifty::Response object.
ACTIONS
actions
Gets the actions that have been created with this framework with new_action
(whether automatically via a Jifty::Request, or in Mason code), as Jifty::Action objects.
allow_actions RESTRICTIONS
Takes a list of strings or regular expressions, and adds them in order to the list of limits for the purposes of "is_allowed". See "restrict_actions" for the details of how limits are processed.
deny_actions RESTRICTIONS
Takes a list of strings or regular expressions, and adds them in order to the list of limits for the purposes of "is_allowed". See "restrict_actions" for the details of how limits are processed.
restrict_actions POLARITY RESTRICTIONS
Method that "allow_actions" and and "deny_actions" call internally; POLARITY is either allow
or deny
. Allow and deny limits are evaluated in the order they're called. The last limit that applies will be the one which takes effect. Regexes are matched against the class; strings are fully qualified with the application's ActionBasePath (if they not already) and used as an exact match against the class name.
If you call:
Jifty->web->allow_actions ( qr'.*' );
Jifty->web->deny_actions ( qr'Foo' );
Jifty->web->allow_actions ( qr'FooBar' );
Jifty->web->deny_actions ( qr'FooBarDeleteTheWorld' );
calls to MyApp::Action::Baz will succeed. calls to MyApp::Action::Foo will fail. calls to MyApp::Action::FooBar will pass. calls to MyApp::Action::TrueFoo will fail. calls to MyApp::Action::TrueFooBar will pass. calls to MyApp::Action::TrueFooBarDeleteTheWorld will fail. calls to MyApp::Action::FooBarDeleteTheWorld will fail.
is_allowed CLASS
Returns false if the CLASS name (which is fully qualified with the application's ActionBasePath if it is not already) is allowed to be executed. See "restrict_actions" above for the rules that the class name must pass.
form
Returns the current Jifty::Web::Form object, creating one if there isn't one already.
new_action class => CLASS, moniker => MONIKER, order => ORDER, arguments => PARAMHASH
Creates a new action (an instance of a subclass of Jifty::Action)
CLASS
is appended to the ActionBasePath
found in the configuration file, and an instance of that class is created, passing the Jifty::Web
object, the MONIKER
, and any other arguments that new_action
was supplied.
MONIKER
is a unique designator of an action on a page. The moniker is content-free and non-fattening, and may be auto-generated. It is used to tie together arguments that relate to the same action.
ORDER
defines the order in which the action is run, with lower numerical values running first.
ARGUMENTS
are passed to the "new" in Jifty::Action method. In addition, if the current request ($self-
request>) contains an action with a matching moniker, any arguments that are in that requested action but not in the PARAMHASH
list are set. This implements "sticky fields".
new_action_from_request REQUESTACTION
Given a Jifty::Request::Action, creates a new action using new_action
.
failed_actions
Returns an array of Jifty::Action objects, one for each Jifty::Request::Action that is marked as failed in the current response.
succeeded_actions
As "failed_actions", but for actions that completed successfully; less often used.
REDIRECTS AND CONTINUATIONS
next_page [VALUE]
Gets or sets the next page for the framework to show. This is normally set during the take_action
method or a Jifty::Action
redirect_required
Returns true if we need to redirect, now that we've processed all the actions. The current logic just looks to see if a different "next_page" has been set. We probably want to make it possible to force a redirect, even if we're redirecting back to the current page
redirect [URL]
Redirect to the next page. If you pass this method a parameter, it redirects to that URL rather than next_page.
It creates a continuation of where you want to be, and then calls it.
save_continuation
Saves the current request and response if we've been asked to. If we save the continuation, we redirect to the next page -- the call to save_continuation
never returns.
multipage START_URL, ARGUMENTS
Note: This API is very much not finalized. Don't use it yet!
Create a multipage action. The first argument is the URL of the start of the multipage action -- the user will be redirected there if they try to enter the multipage action on any other page. The rest of the arguments are passed to "add_action" in Jifty::Request to create the multipage action.
caller
Returns the Jifty::Request of our enclosing continuation, or an empty Jifty::Request if we are not in a continuation.
HTML GENERATION
tangent PARAMHASH
If called in non-void context, creates and renders a Jifty::Web::Form::Clickable with the given PARAMHASH, forcing a continuation save.
In void context, does a redirect to the URL that the Jifty::Web::Form::Clickable object generates.
Both of these versions preserve all state variables by default.
goto PARAMHASH
Does an instant redirect to the url generated by the Jifty::Web::Form::Clickable object generated by the PARAMHASH.
link PARAMHASH
Generates and renders a Jifty::Web::Form::Clickable using the given PARAMHASH.
return PARAMHASH
Generates and renders a Jifty::Web::Form::Clickable using the given PARAMHASH, additionally defaults to calling the current continuation.
render_messages
Outputs any messages that have been added, in a <div id="messages"> tag. Messages are added by calling "message" in Jifty::Result.
render_request_debug_info
Outputs the request arguments.
query_string KEY => VALUE [, KEY => VALUE [, ...]]
Returns an URL-encoded query string piece representing the arguments passed to it.
escape STRING
HTML-escapes the given string and returns it
navigation
Returns the Jifty::Web::Menu for this web request; one is automatically created if it hasn't been already.
STATE VARIABLES
get_variable NAME
Gets a page specific variable from the request object.
set_variable NAME VALUE
Takes a key-value pair for variables to serialize and hand off to the next page.
Behind the scenes, these variables get serialized into every link or form that is marked as 'state preserving'. See Jifty::Web::Form::Clickable.
state_variables
Returns all of the state variables that have been set for the next request, as a hash; they have already been prefixed with J:V-
REGIONS
get_region [QUALIFIED NAME]
Given a fully QUALIFIED NAME
of a region, returns the Jifty::Web::PageRegion with that name, or undef if no such region exists.
region PARAMHASH,
Creates and renders a Jifty::Web::PageRegion; the PARAMHASH
is passed directly to its "new" in Jifty::Web::PageRegion method. The region is then added to the stack of regions, and the fragment is rendered.
current_region
Returns the name of the current Jifty::Web::PageRegion, or undef if there is none.
qualified_region
Returns the fully qualified name of the current Jifty::Web::PageRegion, or the empty string if there is none..
serve_fragments
If the request is for individuals fragments, and not a full page, then this method fetches the requested fragments and serves them up, returning an XML document.