HTML-Mason

 view release on metacpan or  search on metacpan

Changes  view on Meta::CPAN

      environment. If you use the previewer, you now have to explicitly "use
      HTML::Mason::Preview" in your handler.pl.
    - Improved documentation about argument/GET/POST handling (suggested
      by Ken Williams)
    - Added cache option 'busy_lock', which prevents multiple processes
      from recomputing an expire cache value at the same time.  (suggested
      by Dennis Watson)
    - Inserted work-around for Perl 5.005 $r scoping bug (submitted by
      Rafael Weinstein)
    - Fixed "new CGI" example in Components.pod (submitted by Austin Lin)
    - Fixed "return if content-type..." line in handler.pl and Mason.pod
      (submitted by Patrick Kane)
    - Added CREDITS file

0.4  January 06, 1999
    - Added support for using Perl profiler in conjunction with debug
      files
    - Fixed bug in previewer HTML trace introduced in 0.3
    - Created Perl status section for Mason
    - Removed most warnings when PerlWarn is on (suggested by Philip Gwyn)
    - Added code_cache_mode parameter to control caching of components in

MANIFEST  view on Meta::CPAN

lib/HTML/Mason/Tools.pm
lib/HTML/Mason/Utils.pm
live-tests/live/CGIHandler.t
live-tests/live/apache-filter.t
live-tests/live/cgi-no-handler.t
live-tests/live/cgi-with-handler.t
live-tests/live/libapreq-no-handler.t
live-tests/live/libapreq-with-handler.t
live-tests/live/multi-conf.t
live-tests/live/no-config.t
live-tests/live/set-content-type.t
live-tests/live/single-level-server-root.t
live-tests/live/taint.t
samples/README
samples/dump-request
samples/show-env
t/00-report-prereqs.dd
t/00-report-prereqs.t
t/01-syntax.t
t/01a-comp-calls.t
t/02-sections.t

lib/HTML/Mason/Devel.pod  view on Meta::CPAN


Two global per-request objects are available to all components: $r and
$m.

$r, the mod_perl request object, provides a Perl API to the current
Apache request.  It is fully described in Apache.pod. Here is a
sampling of methods useful to component developers:

    $r->uri             # the HTTP request URI
    $r->header_in(..)   # get the named HTTP header line
    $r->content_type    # set or retrieve content-type
    $r->header_out(..)  # set or retrieve an outgoing header

    $r->content         # don't use this one! (see Tips and Traps)

$m, the Mason request object, provides an analogous API for
Mason. Almost all Mason features not activated by syntactic tags are
accessed via $m methods.  You'll be introduced to these methods
throughout this document as they are needed.  For a description of all
methods see B<L<HTML::Mason::Request|HTML::Mason::Request>>.

lib/HTML/Mason/FAQ.pod  view on Meta::CPAN

Unlike many templating systems, Mason comes with no obvious filenaming standards. While this flexibility was initially considered an advantage, in retrospect it has led to the proliferation of a million different component extensions (.m, .mc, .mhtml...

The Mason team now recommends a filenaming scheme with extensions like .html, .txt, .pl for top-level components, and .mhtml, .mtxt, .mpl for internal (non-top-level) components.

Whatever naming scheme you choose should ideally accomplish three things:

* Distinguish top-level from internal components. This is obviously crucial for security.

* Distinguish output components from those that compute and return values. This improves clarity, and forces the component writer to decide between outputting and returning, as it is bad style to do both. 

* Indicate the type of output of a component: text, html, xml, etc. This improves clarity, and helps browsers that ignore content-type headers (such as IE) process non-HTML pages correctly. 

=head2 Can I serve images through a HTML::Mason server?

If you put images in the same directories as components, you need to make sure that the images don't get handled through HTML::Mason. The reason is that HTML::Mason will try to parse the images and may inadvertently find HTML::Mason syntax (e.g. "<%"...

The simplest remedy is to have HTML::Mason decline image and other non-HTML requests, thus letting Apache serve them in the normal way.

Another solution is to put all images in a separate directory; it is then easier to tell Apache to serve them in the normal way. See the next question.

For performance reasons you should consider serving images from a completely separate (non-HTML::Mason) server. This will save a lot of memory as most requests will go to a thin image server instead of a large mod_perl server. See Stas Bekman's mod_p...

lib/HTML/Mason/FAQ.pod  view on Meta::CPAN

=head2 Some of my pages are being served with a content type other than text/html.  How do I get HTML::Mason to properly set the content type?

HTML::Mason doesn't actually touch the content type -- it relies on Apache to set it correctly. You can affect how Apache sets your content type in the configuration files (e.g. srm.conf). The most common change you'll want to make is to add the line

      DefaultType text/html

This indicates that files with no extension and files with an unknown extension should be treated as text/html. By default, Apache would treat them as text/plain.

=head2 Microsoft Internet Explorer displays my page just fine, but Netscape or other browsers just display the raw HTML code.

The most common cause of this is an incorrect content-type. All browsers are supposed to honor content-type, but MSIE tries to be smart and assumes content-type of text/html based on filename extension or page content.

The solution is to set your default content-type to text/html. See previous question.

=head2 My configuration prevents HTML::Mason from processing anything but html and text extensions, but I want to generate a dynamic image using HTML::Mason.  How can I get HTML::Mason to set the correct MIME type?

Use mod_perl's $r->content_type function to set the appropriate MIME type. This will allow you to output, for example, a GIF file, even if your component is called dynamicImage.html. However there's no guarantee that every browser (e.g. Internet Expl...

=head2 How do I bring in external modules?


Use the PerlModule directive in your httpd.conf, or if you have a startup.pl file, put the 'use module' in there. If you want components to be able to refer to symbols exported by the module, however, you'll need to use the module inside the HTML::Ma...

t/14a-fake_apache.t  view on Meta::CPAN

# Now create a fake apache object.
ok( my $r = HTML::Mason::FakeApache->new, "Create new FakeApache" );

# Check its basic methods.
is( $r->method, $ENV{REQUEST_METHOD}, "Check request method" );
ok( $r->content_type('text/xml'), 'Set content type' );
is( $r->content_type, 'text/xml', 'Check content type' );

# Check the headers out.
ok( $h = $r->headers_out, "Get headers out" );
is( $h->{'Content-Type'}, 'text/xml', 'Check header content-type' );
is( $h->{'content-type'}, 'text/xml', 'Check lc header content-type' );

# Check with get().
is( $h->get('Content-Type'), 'text/xml', 'Check header content-type' );
is( $h->get('content-type'), 'text/xml', 'Check lc header content-type' );

# Try getting an array.
ok( my %h = $r->headers_out, "Get headers out" );
is( $h{'Content-Type'}, 'text/xml', 'Check header content-type' );
is( $h{'content-type'}, undef, 'List context returns new hash list' );

# Try assigning a new value via header_out().
ok( $r->header_out('Annoyance-Level' => 'high'), "Set annoyance level" );
is( $r->header_out('Annoyance-Level'), 'high', "Check annoyance level" );
is( $h->{'annoyance-level'}, 'high', "Check the hash directly" );
ok( $h->unset('annoyance-level'), 'Unset annoyance level' );
is( $r->header_out('Annoyance-Level'), undef, "Check annoyance level again" );
is( $h->{'annoyance-level'}, undef, "Check the hash directly again" );

# Add some cookies

t/lib/Mason/ApacheTest.pm  view on Meta::CPAN

    my %p = @_;

    return ( { path  => '/comps/basic',
               extra =>
               [ sub { my $response = shift;
                       is( $response->headers()->header('Content-Type'),
                           'text/html; charset=i-made-this-up',
                           'Content type set by handler is preserved by Mason' ); },
                 sub { my $response = shift;
                       unlike( $response->content(), qr/Content-Type:/i,
                               'response body does not contain a content-type header' ); },
               ],
             },
             { path => '/comps/with_dhandler_no_ct/',
               extra =>
               [ sub { my $response = shift;
                       is( $response->headers()->header('Content-Type'),
                           'text/html; charset=i-made-this-up',
                           'Content type set by handler is preserved by Mason with directory request' ); },
                 sub { my $response = shift;
                       unlike( $response->content(), qr/Content-Type:/i,
                               'response body does not contain a content-type header with directory request' ); },
               ],
             },
           );
}

sub _multi_config_tests
{
    shift;
    my %p = @_;



( run in 2.502 seconds using v1.01-cache-2.11-cpan-524268b4103 )