Danh mục

Embedding Perl in HTML with Mason Chapter 7: Using Mason with mod_perl

Số trang: 22      Loại file: pdf      Dung lượng: 55.39 KB      Lượt xem: 6      Lượt tải: 0    
Thư viện của tui

Phí tải xuống: 13,000 VND Tải xuống file đầy đủ (22 trang) 0
Xem trước 3 trang đầu tiên của tài liệu này:

Thông tin tài liệu:

Tham khảo tài liệu embedding perl in html with mason chapter 7: using mason with mod_perl, công nghệ thông tin, kỹ thuật lập trình phục vụ nhu cầu học tập, nghiên cứu và làm việc hiệu quả
Nội dung trích xuất từ tài liệu:
Embedding Perl in HTML with Mason Chapter 7: Using Mason with mod_perl Chapter 7: Using Mason with mod_perlWhile Mason can be used in any text generation context, it is mostfrequently used to create dynamic web sites. As you probably know,executing Perl (or anything else for that matter) as a CGI can be very slow.Mason, because it is not a small amount of code, can be sluggish when runas a CGI under heavy loads.To that end, Mason has been designed to play nice when run undermod_perl. In fact, Mason has quite a number of features that make itnicely suited to running under mod_perl.This chapter assumes that you are familiar with Apache, particularlyApaches configuration files, and with mod_perl. If youre not, heres ateaser: mod_perl embeds a Perl interpreter inside the Apache web server.Because Perl is already loaded, no external processes need to be launched toserve Perl-generated content. mod_perl also allows many server tasks tobe configured and executed using Perl, which can be a great convenience.More information on Apache can be found via the Apache web site athttp://httpd.apache.org/, as well as in OReillys Apache: The DefinitiveGuide, 3rd Edition (Ben and Peter Laurie, 2003).For more information on mod_perl, the mod_perl site athttp://perl.apache.org/ is useful, as is Stas Bekmans fabulous mod_perlguide, which can be found at the same location. Also useful is WritingApache Modules with Perl and C (the Eagle Book) by Lincoln Stein andDoug MacEachern, also published by OReilly.1 Despite the title, it is reallyprimarily about mod_perl.A recent book from Sams Publishing, The mod_perl Developers Cookbookby Geoffrey Young, Paul Lindner, and Randy Kobes, is also an extremelyvaluable resource for anyone whos going to spend a significant amount oftime working with mod_perl. It fills a different niche in the developersmental toolkit.With Apache 2.0 and mod_perl 2.0 on the horizon as this is being written,please note that this chapter assumes that you are using Apache 1.3.x andmod_perl 1.22 or greater. In addition, your mod_perl should have beencompiled with PERL_METHOD_HANDLERS=1 andPERL_TABLE_API=1, or with EVERYTHING=1 .We expect Mason to work immediately under the 1.x compatibility layerthat mod_perl 2.0 will provide. And of course, once mod_perl andApache 2.0 are out, we hope to find new features for Mason to exploit.Configuring MasonMason can be configured under mod_perl in two different ways. Theeasiest of the two merely requires that you add a few directives to Apachesconfiguration files. This method is very easy to use and is appropriate formost uses of Mason. Its commonly called configuration via httpd.conf,though many configuration directives can be placed anywhere Apache willsee them, such as in an .htaccess file.The other way is to write a custom piece of Perl code to bind Mason andmod_perl together, which you instruct mod_perl to use when handlingrequests. This method is very flexible but is a bit more complicated. It is notusually necessary, but it can be useful for a particularly complex or dynamicconfiguration. This configuration method is commonly called configurationvia a handler.pl, though the handler.pl file can be called anything you like.For simplicitys sake, we always refer to the httpd.conf and handler.pl filesthroughout the book.Configuration via httpd.confTo make Mason work under mod_perl, we need to set up a few Masonconfiguration variables and then tell mod_perl to use Mason as aPerlContentHandler . Here is the simplest possible configuration: SetHandler perl-script PerlHandler HTML::Mason::ApacheHandlerThe SetHandler directive just tells Apache to use mod_perl for thisrequest. The PerlHandler directive is provided by mod_perl, and ittells Apache that the given module is a content handler. This means that themodule will respond to the request and generate content to be sent to theclient.Putting the previous snippet in your configuration file will cause every fileyour web server processes to be handled by Mason. This is probably notwhat you want most of the time, so lets narrow it down a bit: PerlSetVar MasonCompRoot/path/to/doc/root/mason SetHandler perl-script PerlHandler HTML::Mason::ApacheHandler This tells Apache that only requests that have a path starting with /masonwill be handled by Mason. Weve narrowed down the component rootcorrespondingly, though this is not required. In fact, its important to realizethat component root and document root are not the same thing. There will bemore on this later.Alternately, we might want to specify that only certain file extensions willbe handled by Mason: AddType text/html .mhtml SetHandler perl-script PerlHandler HTML::Mason::ApacheHandler The first direc ...

Tài liệu được xem nhiều: