Danh mục

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

Số trang: 12      Loại file: pdf      Dung lượng: 40.06 KB      Lượt xem: 9      Lượt tải: 0    
Hoai.2512

Phí tải xuống: 1,000 VND Tải xuống file đầy đủ (12 trang) 0
Xem trước 2 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- p2, 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- P2 Chapter 4: APIs- P2SubrequestsSubrequests are request objects that inherit all their settable properties fromtheir parent. The main difference between calling a component with asubrequest versus using a regular component call is that subrequests willinvoke the autohandler and dhandler mechanisms, whereas a regularcomponent call will execute only the called component. Subrequests arecovered in a more detail in Chapter 5. • make_subrequest(comp => component, args => [ ... ], ...) This method creates a new subrequest object, which you can then execute via its exec() method. This gives you a chance to override the parent objects properties by passing in arguments to this method. • subexec(comp, args) This combines the make_subrequest() method and the subrequests exec() method in one step. Any argument list given to subexec() will become the argument list for the called component. This doesnt give you a chance to set properties of the request, however. For that, youll need to use the full two-step approach of calling make_subrequest() and then exec() on the returned object. • is_subrequest This method returns a boolean value indicating whether the given object is a subrequest. • parent_request Calling this method returns the parent request object for a subrequest. If called on the top-level request object, it just returns undef.Methods Available Only When Using ApacheHandlerWhen you are using Mason under mod_perl with theHTML::Mason::ApacheHandler class, which is covered in Chapter 7,the Request object will contain several additional methods. • ah This method returns the current HTML::Mason::ApacheHandler object for this request. • apache_req This method returns the current Apache object for the request. This object is also available in all components as the variable $r. If you chose to use Apache::Request to handle incoming parameters by setting args_method to mod_perl, this object will be an Apache::Request object; otherwise, it will be an Apache object. Incoming parameter handling is covered in Chapter 7.Methods Available When Using ApacheHandler or CGIHandlerTwo additional request methods are available when using theHTML::Mason::ApacheHandler or HTML::Mason::CGIHandlerclasses. The latter class is covered in Chapter 9. • cgi_object This method is always available when using HTML::Mason::CGIHandler . If you are using HTML::Mason::ApacheHandler, this is available only if you chose to use the CGI.pm module to handle incoming request parameters. This method will return the CGI.pm object that was used to handle incoming parameters. • redirect(url) Given a URL, this generates a proper HTTP redirect, which is then sent immediately to the client. This will not work if any output has been previously sent, which may be the case if flush_buffer() has been called or if the request is in autoflush mode.Getting in Close with BuffersUnderneath the hood of the request object, output is handled via bufferobjects, which by default are of the HTML::Mason::Buffer class.The request object maintains a buffer stack. Output goes to the top buffer onthe stack, which can then manipulate it and pass it on to the next buffer inthe stack, which can in turn do the same, and so on.Buffers are also used to implement features like the requests scomp()method.So why would you want to play with buffers? Chances are you wont want tosimply add more plain old HTML::Mason::Buffer objects to the stack.That wouldnt achieve much.But if you were to create a custom buffer subclass, you might want toselectively stick one onto the stack. For example, if you made a buffer thattraced the source of all output it received, you might want to put it on thestack only for certain parts of your site during debugging. Just be sure toremove any buffers you add, or Mason may get confused and your outputmay never get sent.The other buffer-related methods are potentially useful for introspection anddebugging: • top_buffer Returns the current top-level buffer object for the request. This is the buffer to which output is currently being sent. • buffer_stack Returns all the buffers on the stack, starting from the top buffer and ending with the bottom buffer, which is the one at the bottom of the stack. • push_buffer_stack(Buffer object) Pushes a new buffer onto the top of the stack. Mason pushes new buffers onto the stack when calling new components. • pop_buffer_stack Pops the top buffer off the stack and returns it. Mason pops a ...

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