home *** CD-ROM | disk | FTP | other *** search
/ PC Professionell 2004 December / PCpro_2004_12.ISO / files / webserver / tsw / TSW_3.4.0.exe / Apache2 / perl / Mason.pm < prev    next >
Encoding:
Perl POD Document  |  2003-12-12  |  6.6 KB  |  180 lines

  1. package HTML::Mason;
  2. # Copyright (c) 1998-2003 by Jonathan Swartz. All rights reserved.
  3. # This program is free software; you can redistribute it and/or modify it
  4. # under the same terms as Perl itself.
  5.  
  6. use 5.005;
  7.  
  8. $HTML::Mason::VERSION = '1.25';
  9.  
  10. use HTML::Mason::Interp;
  11.  
  12. sub version
  13. {
  14.     return $HTML::Mason::VERSION;
  15. }
  16.  
  17. 1;
  18.  
  19. __END__
  20.  
  21. =head1 NAME
  22.  
  23. Mason - High-performance, dynamic web site authoring system
  24.  
  25. =head1 SYNOPSIS
  26.  
  27.     PerlModule HTML::Mason::ApacheHandler
  28.  
  29.     <Location />
  30.         SetHandler perl-script
  31.         PerlHandler HTML::Mason::ApacheHandler
  32.     </Location>
  33.  
  34. =head1 DESCRIPTION
  35.  
  36. Mason is a tool for building, serving and managing large web
  37. sites. Its features make it an ideal backend for high load sites
  38. serving dynamic content, such as online newspapers or database driven
  39. e-commerce sites.
  40.  
  41. Actually, Mason can be used to generate any sort of text, whether for
  42. a web site or not.  But it was originally built for web sites and
  43. since that's why most people are interested in it, that is the focus
  44. of this documentation.
  45.  
  46. Mason's various pieces revolve around the notion of "components''. A
  47. component is a mix of HTML, Perl, and special Mason commands, one
  48. component per file. So-called "top-level" components represent entire
  49. web-pages, while smaller components typically return HTML snippets for
  50. embedding in top-level components. This object-like architecture
  51. greatly simplifies site maintenance: change a shared component, and
  52. you instantly changed all dependant pages that refer to it across a
  53. site (or across many virtual sites).
  54.  
  55. Mason's component syntax lets designers separate a web page into
  56. programmatic and design elements. This means the esoteric Perl bits
  57. can be hidden near the bottom of a component, preloading simple
  58. variables for use above in the HTML. In our own experience, this frees
  59. content managers (i.e., non-programmers) to work on the layout without
  60. getting mired in programming details. Techies, however, still enjoy
  61. the full power of Perl.
  62.  
  63. Mason works by intercepting innocent-looking requests (say,
  64. http://www.yoursite.com/index.html) and mapping them to requests for
  65. Mason components.  Mason then compiles the component, runs it, and
  66. feeds the output back to the client.
  67.  
  68. Consider this simple Mason component:
  69.  
  70.     % my $noun = 'World';
  71.     Hello <% $noun %>!
  72.     How are ya?
  73.  
  74. The output of this component is:
  75.  
  76.     Hello World!
  77.     How are ya?
  78.  
  79. In this component you see a mix of standard HTML and Mason
  80. elements. The bare '%' prefixing the first line tells Mason that this
  81. is a line of Perl code. One line below, the embedded S<E<lt>%
  82. ... %E<gt>> tag gets replaced with the return value of its contents,
  83. evaluated as a Perl expression.
  84.  
  85. Beyond this trivial example, components can also embed serious chunks
  86. of Perl code (say, to pull records from a database). They can also
  87. call other components, cache results for later reuse, and perform all
  88. the tricks you expect from a regular Perl program.
  89.  
  90. =head1 INSTALLATION
  91.  
  92. Mason has been tested under Linux, FreeBSD, Solaris, HPUX, and
  93. Win32. As an all-Perl solution, it should work on any machine that has
  94. working versions of Perl 5.00503+, mod_perl, and the required CPAN
  95. modules.
  96.  
  97. Mason has a standard MakeMaker-driven installation. See the README
  98. file for details.
  99.  
  100. =head1 CONFIGURING MASON
  101.  
  102. This section assumes that you are able to install and configure a
  103. mod_perl server. Relevant documentation is available at
  104. http://www.apache.org (Apache) and http://perl.apache.org
  105. (mod_perl). The mod_perl mailing list, archive, and guide are also
  106. great resources.
  107.  
  108. The simplest configuration of Mason requires a few lines in your
  109. httpd.conf:
  110.  
  111.     PerlModule HTML::Mason::ApacheHandler
  112.  
  113.     <Location />
  114.         SetHandler perl-script
  115.         PerlHandler HTML::Mason::ApacheHandler
  116.     </Location>
  117.  
  118. The PerlModule directive simply ensures that the Mason code is loaded
  119. in the parent process before forking, which can save some memory when
  120. running mod_perl.
  121.  
  122. The <Location> section routes all requests to the Mason handler, which
  123. is a simple way to try out Mason. A more refined setup is discussed
  124. in the L<Controlling Access via Filename Extension|HTML::Mason::Admin/Controlling Access via Filename Extension> section of the administrator's manual.
  125.  
  126. Once you have added the configuration directives, restart the
  127. server. First, go to a standard URL on your site to make sure you
  128. haven't broken anything. If all goes well you should see the same page
  129. as before. If not, recheck your Apache config files and also tail your
  130. server's error log.
  131.  
  132. If you are getting "404 Not Found" errors even when the files clearly
  133. exist, Mason may be having trouble with your document root. One
  134. situation that will unfortunately confuse Mason is if your document
  135. root goes through a symbolic link. Try expressing your document root
  136. in terms of the true filesystem path.
  137.  
  138. Next, try adding the tag <% 2+2 %> at the top of some HTML file. If you
  139. reload this page and see a "4", Mason is working!
  140.  
  141. =head1 DOCUMENTATION ROADMAP
  142.  
  143. Once Mason is on its feet, the next step is to write a component or
  144. two. The L<Mason Developer's Manual|HTML::Mason::Devel> is a
  145. complete tutorial for writing, using, and debugging components. A
  146. reference companion to the Developer's Manual is the Request API
  147. documentation, L<HTML::Mason::Request|HTML::Mason::Request>.
  148.  
  149. Whoever is responsible for setting up and tuning Mason should read the
  150. L<Administrator's Manual|HTML::Mason::Admin>, though developers
  151. will also benefit from reading it as well. This document covers more
  152. advanced configuration scenarios and performance optimization. The
  153. reference companion to the Administrator's manual is the
  154. L<Parameters Reference|HTML::Mason::Params>, which describes all the
  155. parameters you can use to configure Mason.
  156.  
  157. Most of this documentation assumes that you're running Mason on top of
  158. mod_perl, since that is the most common configuration.  If you would
  159. like to run Mason via a CGI script, refer to the
  160. L<HTML::Mason::CGIHandler|HTML::Mason::CGIHandler> documentation.
  161. If you are using Mason from a standalone program, refer to
  162. the L<Using Mason from a Standalone Script|HTML::Mason::Admin/Using Mason from a Standalone Script> section of the administrator's manual.
  163.  
  164. There is also a book about Mason, I<Embedding Perl in HTML with
  165. Mason>, by Dave Rolsky and Ken Williams, published by O'Reilly and
  166. Associates.  The book's website is at http://www.masonbook.com/.  This
  167. book goes into detail on a number of topics, and includes a chapter of
  168. recipes as well as a sample Mason-based website.
  169.  
  170. =head1 AUTHORS
  171.  
  172. Jonathan Swartz <swartz@pobox.com>, Dave Rolsky <autarch@urth.org>, Ken Williams <ken@mathforum.org>
  173.  
  174. =head1 SEE ALSO
  175.  
  176. L<HTML::Mason::Devel|HTML::Mason::Devel>,
  177. L<HTML::Mason::Admin|HTML::Mason::Admin>
  178.  
  179. =cut
  180.