Danh mục

Embedding Perl in HTML with Mason Chapter 4: APIs- P1

Số trang: 23      Loại file: pdf      Dung lượng: 58.68 KB      Lượt xem: 6      Lượt tải: 0    
Thu Hiền

Phí tải xuống: 8,000 VND Tải xuống file đầy đủ (23 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 4: apis- p1, 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 4: APIs- P1 Chapter 4: APIs- P1Mason is more than just a templating system. It provides a framework fortranslating requests into output.1 This framework has a number ofclass/object APIs worth knowing about. You certainly wont need to usemost of these methods very often, but you will probably want to use at leastsome of them in many of your Mason-based projects. This chapterdocuments those APIs. For a more concise reference to these methods, seeAppendix B.Request Class and Object APIThe request object in Mason represents the context of the current requestprocess. For example, it knows where in the component wrapping chain it is,what arguments have been passed to various component calls, if youve beenbad or good, and so on. It also allows you to change that context in variousways, such as by calling another component or aborting the request.The request API provides access to some of the most frequently used Masonfeatures, particularly those relating to component calls, autohandlers, andaborting in the middle of a request.Recall, as first mentioned in Chapter 2, that the Mason request object isavailable in all components as $m.The request class has only two class methods. The first,HTML::Mason::Request->new() , is intended for use by other Masonobjects and is not documented for external use. If you want to make a newrequest object, use the make_subrequest() method provided by therequest object, which is covered as part of the discussion of Masonssubrequest mechanism in Chapter 5.The second class method, HTML::Mason::Request->instance() ,returns the current Mason request object. This is useful if you have codeoutside of a Mason component that needs to access the request object. Insidecomponents, you can just use $m.The request objects methods can be grouped together into several functionalareas.Constructor ParametersA number ofparameters can be set when creating a new request object. You will mostoften set these by passing them to the ApacheHandlers constructor or bysetting them in your httpd.conf file. You may occasionally want to set one ofthese parameters on the fly for the current request. Finally, you will create anew request object when you want to make a subrequest, and you may wantto set these parameters then.All of the following parameters are also available as get/set methods of thesame name: • autoflush This attribute is discussed in Buffer-Related Methods, later in this chapter. • data_cache_defaults This returns a hash reference containing default options for the Request objects cache() method.• dhandler_name This is the name used for dhandlers. This defaults to dhandler.• error_format This may be brief , text , line , or html . These produce an error message with no trace, a multiline error with trace information, a single-line error with tab-separated fields (suitable for writing to a log), and a fancy HTML format. Each of these methods corresponds to a method in the HTML::Mason::Exception class, such as as_text() or as_line(). You can create your own method in the HTML::Mason::Exception namespace, such as as_you_wish(), in which case you could set this parameter to you_wish. This method will receive a single argument, the exception object, and is expected to return a string containing the formatted error message. In a mod_perl or CGI environment, this defaults to html format. Otherwise, the default is text .• error_mode This may be either fatal or output . In fatal mode, errors are thrown as exceptions. In output mode, the exception is converted to a text representation and sent to the same output stream as normal content. In a mod_perl or CGI environment, the default is output , which means that errors go the client. In any other environment, the default is fatal . If you set this to fatal in a web environment, errors will end up in your web servers logs. If you wish to implement your own exception-handling mechanism around Mason, set this to fatal and catch the exceptions yourself. • max_recurse This can be used to set the maximum stack size for component calls and subrequests. It defaults to 32, which is likely to be more than enough for any application. But if for some reason you need more, you can set this to a higher number. • out_method This parameter indicates where output should be sent and must be a reference to either a scalar or a subroutine. If it is a scalar reference, output will be appended to this scalar. If it is a subroutine reference (often called a code reference in Perl parlance), this subroutine will be called with a list of arguments whenever output need ...

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