TAILIEUCHUNG - Embedding Perl in HTML with Mason Chapter 5: Advanced Features-P1

Tham khảo tài liệu 'embedding perl in html with mason chapter 5: advanced features-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ả | Chapter 5 Advanced Features-Pl In the previous chapters you have been introduced to the basic features of Mason and you should have a fairly good idea by now of how you might actually go about constructing a dynamic web site from Mason components. You have seen a few of Mason s unique features such as the autohandler mechanism the dhandler mechanism and the ability to pass arbitrary data between components. In this chapter we ll go beyond the basics and learn more about advanced ways to use Mason components to design large dynamic sites. You ll learn how to define multiple components in the same text file how to create components on the fly from Perl strings how to manage multiple component root directories and finally how to use all of Mason s object-oriented features. Subcomponents Although we often imagine a one-to-one correspondence between text files and Mason components it is actually possible to define multiple components in a single text file. This is achieved by using a def def block a special Mason directive that defines one component from within another. The component embedded within the def block is called a subcomponent and it is visible only to the component within which it resides component A may not access component B s subcomponents directly. The subcomponent may use any of the standard Mason component directives such as args init -lines and so on. The only exceptions are that you may not use def or method blocks within subcomponents nor may you use global blocks like once or shared . Subcomponents are most useful when you have some piece of processing to repeat several times that is used only in a certain specific situation and doesn t merit its own separate component file. Here is an example of defining and calling a subcomponent. Note that the component is assigned a name inside the def tag the name often starts with a period purely by convention and that you use the regular component-calling mechanisms m- comp or a tag to invoke it. h2 .

TỪ KHÓA LIÊN QUAN
Đã phát hiện trình chặn quảng cáo AdBlock
Trang web này phụ thuộc vào doanh thu từ số lần hiển thị quảng cáo để tồn tại. Vui lòng tắt trình chặn quảng cáo của bạn hoặc tạm dừng tính năng chặn quảng cáo cho trang web này.