GSP
Quick Navigator

Search Site

Unix VPS
A - Starter
B - Basic
C - Preferred
D - Commercial
MPS - Dedicated
Previous VPSs
* Sign Up! *

Support
Contact Us
Online Help
Handbooks
Domain Status
Man Pages

FAQ
Virtual Servers
Pricing
Billing
Technical

Network
Facilities
Connectivity
Topology Map

Miscellaneous
Server Agreement
Year 2038
Credits
 

USA Flag

 

 

Man Pages
Mason::Manual::FAQ(3) User Contributed Perl Documentation Mason::Manual::FAQ(3)

Mason::Manual::FAQ - Frequently asked questions about Mason

Mason components each run in their own packages, so if you set a regular global in one you won't be able to see it in the others.

But you can use allow_globals and set_global to create globals accessible from all components.

See Whitespace And Newlines in the syntax manual. To suppress extra newlines you can use a backslash at the end of each line, or you can use the NoBlankLines filter.

To emit binary data without the risk of inserting extra whitespace, surround your code with $m->clear_buffer and $m->abort:

    <%init>
    $m->clear_buffer;
    open(my $fh, '<', 'binary-file') or die $!;
    my $buffer;
    while (read $fh, $buffer, 8192) {
        $m->print($buffer);
    }
    $m->abort;
    </%init>

This is almost always caused by unwanted whitespace or other output at the beginning or end of your binary data. Use $m->clear_buffer and $m->abort as in previous answer.

See Comments section in the syntax manual for reference.
  • Put general comments in the "<%doc>" section.
  • Within code blocks ("<%class>", "<%init>", "<%perl>", etc.), use standard Perl comments ('#').
  • Use "<% # %>" for single or multi-line comments anywhere outside of Perl sections.
  • If you are producing HTML, you can use standard HTML comments delimited by <!-- -->. The difference is that these comments will appear in the final output.

For HTML, you might be tempted to surround the section with "<!-- -->". But be careful! Any code inside the section will still execute. Here's a example of commenting out a call to an ad server:

    <!-- temporarily comment out
    <& /shared/fetch_ad.mi &>
    -->

The ad will still be fetched and counted, but not displayed!

A better way to block out a section is "if (0)":

    % if (0) {
      ...
    % }

Code blocked out in this way will neither be executed nor displayed, and multiple "if (0)" blocks can be nested inside each other (unlike HTML comments).

Another way to block out code is with a "<%doc>" tag, although this not cannot be nested.

Use $m->scomp.

Use $m->capture.

Use $m->glob_paths, e.g.

    my @paths = $m->glob_paths('/some/comp/path/*');

This will work even with multiple component roots; you'll get a combined list of all matching component paths in all component roots.

Use Mason::Request->current_request:

    package Foo;

    sub bar {
        my $m = Mason::Request->current_request;
    }

Multiple component roots were designed to work just like Perl's @INC. A given component path matches exactly one file, the first file found in an ordered search through the roots. There is no way to explicitly ask for a file in a specific root.

You need to use Mason in conjunction with a web framework. Poet is a web framework designed specially for Mason. Catalyst and Dancer can also use Mason for their templating layer. See Mason::Manual::Setup.

See the "H" filter in Mason::Plugin::HTMLFilters. If you want to do this automatically for all "<% %>" tags, see Mason::Plugin::DefaultFilter.

Under standard CGI you must load all modules and initialize your environment with every request. Mason's startup cost (mostly due to Moose) will make this particularly sub-optimal. Ask yourself whether you absolutely have to use CGI, and if not, switch to a persistent solution like mod_perl or Fast CGI or Starman.

Mason

Jonathan Swartz <swartz@pobox.com>

This software is copyright (c) 2012 by Jonathan Swartz.

This is free software; you can redistribute it and/or modify it under the same terms as the Perl 5 programming language system itself.

2015-05-16 perl v5.32.1

Search for    or go to Top of page |  Section 3 |  Main Index

Powered by GSP Visit the GSP FreeBSD Man Page Interface.
Output converted with ManDoc.