10.07.2015 Views

Beginning Web Development With Perl : From Novice to ... - Nabo

Beginning Web Development With Perl : From Novice to ... - Nabo

Beginning Web Development With Perl : From Novice to ... - Nabo

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

CHAPTER 13 ■ PERL WEB SITES WITH MASON 269I’ve also had <strong>to</strong> bring some legacy CGI scripts over <strong>to</strong> the site. In doing so, I found thatI needed <strong>to</strong> set the MasonArgsMethod <strong>to</strong> CGI, away from its default of mod_perl. I suspect (orhope) that I’ll have time <strong>to</strong> port these scripts <strong>to</strong> mod_perl by the time you’re reading this book.In addition <strong>to</strong> that basic configuration, I’ve also tightened the security for the site bysending a “404: Not Found” error whenever someone tries <strong>to</strong> access one of the Mason-specificcomponents that I might or might not use. I accomplish this with the help of a directive and Apache::Constants::NOT_FOUND, as directed by the perldoc for HTML::Mason::Admin.Here is the full configuration for Mason as it appears in my httpd.conf. Your configurationmay vary from this, but my hope is <strong>to</strong> pass along some practical information about a real-worldimplementation of Mason.<strong>Perl</strong>Module HTML::Mason::ApacheHandlerSetHandler perl-script<strong>Perl</strong>Handler HTML::Mason::ApacheHandler<strong>Perl</strong>SetVar MasonCompRoot /home/suehring/www<strong>Perl</strong>SetVar MasonDataDir /home/suehring/mason#sws 5/27/2005<strong>Perl</strong>SetVar MasonArgsMethod CGISetHandler perl-script<strong>Perl</strong>InitHandler Apache::Constants::NOT_FOUND<strong>With</strong> the appropriate configuration for your Apache installation in place, you can restartthe Apache server.Mason SyntaxIt’s time <strong>to</strong> create a “Hello World” example, Mason-style. In general, I’m fed up with “HelloWorld” examples, though, so I’m going <strong>to</strong> create something even more annoying: a page thatuses the HTML tag. I’ll do this by wrapping the output inside of a block in thepage. Listing 13-1 shows the simple text for this page.Listing 13-1. A Mason-Style Page Using <strong>to</strong> Print a Blinking Tag print "This is the blinkin' example.\n"; The page can be saved within the direc<strong>to</strong>ry you configured as the MasonCompRoot andviewed in a web browser. When I viewed the page, I saw blinking text. It’s difficult <strong>to</strong> illustrateblinking text in a screenshot, however, so Figure 13-2 shows the text when it appears.

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!