abort ()
Ends the current request, finishing the page without returning through components.
"abort" is implemented by throwing an "Mason::Exception::Abort" object and can thus be caught by
"eval". The "aborted" method is a shortcut for determining whether a caught error was generated by
"abort".
aborted ([$err])
Returns true or undef indicating whether the specified $err was generated by "abort". If no $err was
passed, uses $@.
In this Try::Tiny code, we catch and process fatal errors while letting "abort" exceptions pass
through:
try {
code_that_may_fail_or_abort()
} catch {
die $_ if $m->aborted($_);
# handle fatal errors...
};
add_cleanup (code)
Add a code reference to be executed when the request is cleaned up.
clear_and_abort ()
This method is syntactic sugar for calling "clear_buffer()" and then "abort()". If you are aborting
the request because of an error (or, in a web environment, to do a redirect), you will often want to
clear the buffer first so that any output generated up to that point is not sent to the client.
capture (code)
Execute the code, capturing and returning any Mason output instead of outputting it. e.g. the
following
my $buf = $m->capture(sub { $m->comp('/foo') });
is equivalent to
my $buf = $m->scomp('/foo');
clear_buffer ()
Clears the Mason output buffer. Any output sent before this line is discarded. Useful for handling
error conditions that can only be detected in the middle of a request.
clear_buffer is, of course, thwarted by flush_buffer.
comp (path[, params ...])
Creates a new instance of the component designated by path, and calls its "main" method. params, if
any, are passed to the constructor.
The "<& &>" tag provides a shortcut for "$m->comp".
comp_exists (path)
Makes the component path absolute if necessary, and calls Interp comp_exists to determine whether a
component exists at that path.
current_comp_class ()
Returns the current component class. This is determined by walking up the Perl caller() stack until
the first Mason::Component subclass is found.
current_request ()
This class method returns the "Mason::Request" currently in use. If called when no Mason request is
active it will return "undef".
construct (path[, params ...])
Constructs and return a new instance of the component designated by path. params, if any, are passed
to the constructor. Throws an error if path does not exist.
decline ()
Clears the output buffer and tries the current request again, but acting as if the previously chosen
page component(s) do not exist.
For example, if the following components exist:
/news/sports.mc
/news/dhandler.mc
/dhandler.mc
then a request for path "/news/sports" will initially resolve to "/news/sports.mc". A call to
"$m->decline" would restart the request and resolve to "/news/dhandler.mc", a second "$m->decline"
would resolve to "/dhandler.mc", and a third would throw a "not found" error.
filter (filter_expr, [filter_expr...], string|coderef)
Applies one or more filters to a string or to a coderef that returns a string.
my $filtered_string = $m->filter($.Trim, $.NoBlankLines, $string);
flush_buffer ()
Flushes the main output buffer. Anything currently in the buffer is sent to the request's out_method.
Note that anything output within a "$m->scomp" or "$m->capture" will not have made it to the main
output buffer, and thus cannot be flushed.
go ([request params], path, args...)
Performs an internal redirect. Clears the output buffer, runs a new request for the given path and
args, and then aborts when that request is done.
The first argument may optionally be a hashref of parameters which are passed to the "Mason::Request"
constructor.
See also visit.
interp ()
Returns the Interp object associated with this request.
load (path)
Makes the component path absolute if necessary, and calls Interp load to load the component class
associated with the path.
log ()
Returns a "Log::Any" logger with a log category specific to the current component. The category for
a component "/foo/bar" would be "Mason::Component::foo::bar".
notes ([key[, value]])
The "notes()" method provides a place to store application data between components - essentially, a
hash which persists for the duration of the request.
"notes($key, $value)" stores a new entry in the hash; "notes($key)" returns a previously stored
value; and "notes()" without any arguments returns a reference to the entire hash of key-value pairs.
Consider storing this kind of data in a read-write attribute of the page component.
print (string)
Add the given string to the Mason output buffer. This happens implicitly for all content placed in
the main component body.
page ()
Returns the page component originally called in the request.
path_info ()
Returns the remainder of the request path beyond the path of the page component, with no leading
slash. e.g. If a request for '/foo/bar/baz' resolves to "/foo.mc", the path_info is "bar/baz". For an
exact match, it will contain the empty string (never undef), so you can determine whether there's a
path_info with
if ( length($m->path_info) )
rel_to_abs (path)
Converts a component path to absolute form based on the current component, if it does not already
begin with a '/'.
request_args ()
Returns the original hashref of arguments passed to the request, e.g. via "$interp->run".
request_path ()
Returns the original path passed to the request, e.g. in "$interp->run".
scomp (comp, args...)
Like comp, but returns the component output as a string instead of printing it. (Think sprintf versus
printf.)
See also capture.
visit ([request params], path, args...)
Performs a subrequest with the given path and args, with output being sent to the current output
buffer.
The first argument may optionally be a hashref of parameters which are passed to the "Mason::Request"
constructor. e.g. to capture the output of the subrequest:
$m->visit({out_method => \my $buffer}, ...);
See also go.