Embedding Perl in HTML with Mason Chapter 1: Introduction
Số trang: 31
Loại file: pdf
Dung lượng: 0.00 B
Lượt xem: 13
Lượt tải: 0
Xem trước 4 trang đầu tiên của tài liệu này:
Thông tin tài liệu:
Tại trái tim của nó, Mason chỉ đơn giản là một cơ chế để nhúng vào mã Perlđồng bằng văn bản. Nó chỉ là một trong nhiều cơ chế như vậy mà tất cả làm nhiều hơn hoặc ít hơncùng một điều. Tuy nhiên, Mason đại diện cho một tập hợp các lựa chọn vềcách nhúng này nên được thực hiện, và nhiều người đã thấy rằngcách Mason hiện những điều rất đơn giản và cực kỳ thuận lợi chonhận được công việc làm....
Nội dung trích xuất từ tài liệu:
Embedding Perl in HTML with Mason Chapter 1: IntroductionEmbedding Perl in HTML with Mason Chapter 1: IntroductionAt its heart, Mason is simply a mechanism for embedding Perl code intoplain text. It is only one of many such mechanisms that all do more or lessthe same thing. However, Mason represents a particular set of choices abouthow this embedding should be done, and many people have found that theway Mason does things is very straightforward and extremely conducive togetting jobs done.In this chapter well introduce you to some of Masons key features andstrengths, show you a couple of examples of how to use Mason, and talkabout some alternatives to Mason. After reading this chapter, you shouldhave a fairly good idea of how Mason relates to its peers and what kinds oftasks you can accomplish with Mason.The most common application of Mason is in building large dynamic websites, and this book focuses mostly on web site building. Mason is broadlyapplicable to any situation in which fine control over document content isrequired, however, such as generating mail-merged form letters, creatingcustom configuration file sets, and even building dynamic GIF images basedon varying input parameters. We intend to give you enough facility withMason that after reading this book, you can imagine Mason-based solutionsto problems we havent ever thought of.Before we get into the details of Mason and comparisons with itsalternatives, well just briefly mention some of its guiding design principles.Mason was designed to help you build, organize, and maintain large websites or other groups of dynamically generated documents. It cooperatesfully with Perl, leveraging all the solutions and techniques that Perldevelopers have come to depend on and that have made Perl such a powerfuland widespread tool. It encourages thinking about your site in structuralterms rather than as a collection of procedural scripts or modules. All ofthese things are conducive to getting your job done effectively, letting youconcentrate on your goals while Mason takes care of the details.A First ExampleTo help make this discussion a little more concrete (this thing is calledMason, after all), lets look at an example. Well give more in-depthtreatment to the details of Masons syntax later in the book; these examplesare just to put some Mason code in front of your eyes and show you what itlooks like.The following code is a complete chunk of Mason code, called a component: % my $planet = World; Hello, !When Mason runs this code, the output is: Hello, World!Well talk more about the details of component syntax in Chapter 2, but twobasic elements in the preceding example deserve mention here. The first isthat any line that begins with a % character tells Mason that the line containsPerl code. The Perl code can be any syntactically correct Perl -- Masondoesnt care what it is or what it does. In this case, it simply sets the value ofa variable that will be used later in the component.The other element in the previous Mason component is the substitution tag,denoted by the sequence . Mason will evaluate the contents of anysuch tag and insert the result into the surrounding text. In this case, thevariable $planet evaluates to World, and the output of the entirecomponent is Hello, World! Note that any text that isnt a specialMason construct simply becomes part of the output of the component.These two lines are relatively simple and not particularly exciting, but theyshould give you a taste for how Mason code looks in its simplest form.The Main Features of MasonThere are more templating systems written in Perl than you could possiblykeep in your head all at once. To help you make sense of Masons place inthe world, this section presents Masons most important and distinctivefeatures. By the end of this section, you should see that Mason pushes theboundaries of the term templating system, with lots of features aimed athelping you manage the larger tasks of site design and maintenance.Components: Modular Design ElementsAs we mentioned before, the basic unit of Mason code is called acomponent. It is a chunk of Mason code that can accept input parametersand generate output text. An important feature of Mason is that anycomponent may call any other component at any point during its execution,much like a Perl subroutine calling another Perl subroutine. Because of thisfeature, a component may represent a single web page, a part of a web page(like a side navigation bar), or even a shared utility function that generatesno output of its own. This separation of design elements allows you to useMason as a sort of glorified server-side include (SSI) mechanism, as inExample 1-1, Example 1-2, and Example 1-3. Executing mainpage.mas willproduce a full page of HTML with the header and footer inserted in place.Example 1-1. ...
Nội dung trích xuất từ tài liệu:
Embedding Perl in HTML with Mason Chapter 1: IntroductionEmbedding Perl in HTML with Mason Chapter 1: IntroductionAt its heart, Mason is simply a mechanism for embedding Perl code intoplain text. It is only one of many such mechanisms that all do more or lessthe same thing. However, Mason represents a particular set of choices abouthow this embedding should be done, and many people have found that theway Mason does things is very straightforward and extremely conducive togetting jobs done.In this chapter well introduce you to some of Masons key features andstrengths, show you a couple of examples of how to use Mason, and talkabout some alternatives to Mason. After reading this chapter, you shouldhave a fairly good idea of how Mason relates to its peers and what kinds oftasks you can accomplish with Mason.The most common application of Mason is in building large dynamic websites, and this book focuses mostly on web site building. Mason is broadlyapplicable to any situation in which fine control over document content isrequired, however, such as generating mail-merged form letters, creatingcustom configuration file sets, and even building dynamic GIF images basedon varying input parameters. We intend to give you enough facility withMason that after reading this book, you can imagine Mason-based solutionsto problems we havent ever thought of.Before we get into the details of Mason and comparisons with itsalternatives, well just briefly mention some of its guiding design principles.Mason was designed to help you build, organize, and maintain large websites or other groups of dynamically generated documents. It cooperatesfully with Perl, leveraging all the solutions and techniques that Perldevelopers have come to depend on and that have made Perl such a powerfuland widespread tool. It encourages thinking about your site in structuralterms rather than as a collection of procedural scripts or modules. All ofthese things are conducive to getting your job done effectively, letting youconcentrate on your goals while Mason takes care of the details.A First ExampleTo help make this discussion a little more concrete (this thing is calledMason, after all), lets look at an example. Well give more in-depthtreatment to the details of Masons syntax later in the book; these examplesare just to put some Mason code in front of your eyes and show you what itlooks like.The following code is a complete chunk of Mason code, called a component: % my $planet = World; Hello, !When Mason runs this code, the output is: Hello, World!Well talk more about the details of component syntax in Chapter 2, but twobasic elements in the preceding example deserve mention here. The first isthat any line that begins with a % character tells Mason that the line containsPerl code. The Perl code can be any syntactically correct Perl -- Masondoesnt care what it is or what it does. In this case, it simply sets the value ofa variable that will be used later in the component.The other element in the previous Mason component is the substitution tag,denoted by the sequence . Mason will evaluate the contents of anysuch tag and insert the result into the surrounding text. In this case, thevariable $planet evaluates to World, and the output of the entirecomponent is Hello, World! Note that any text that isnt a specialMason construct simply becomes part of the output of the component.These two lines are relatively simple and not particularly exciting, but theyshould give you a taste for how Mason code looks in its simplest form.The Main Features of MasonThere are more templating systems written in Perl than you could possiblykeep in your head all at once. To help you make sense of Masons place inthe world, this section presents Masons most important and distinctivefeatures. By the end of this section, you should see that Mason pushes theboundaries of the term templating system, with lots of features aimed athelping you manage the larger tasks of site design and maintenance.Components: Modular Design ElementsAs we mentioned before, the basic unit of Mason code is called acomponent. It is a chunk of Mason code that can accept input parametersand generate output text. An important feature of Mason is that anycomponent may call any other component at any point during its execution,much like a Perl subroutine calling another Perl subroutine. Because of thisfeature, a component may represent a single web page, a part of a web page(like a side navigation bar), or even a shared utility function that generatesno output of its own. This separation of design elements allows you to useMason as a sort of glorified server-side include (SSI) mechanism, as inExample 1-1, Example 1-2, and Example 1-3. Executing mainpage.mas willproduce a full page of HTML with the header and footer inserted in place.Example 1-1. ...
Tìm kiếm theo từ khóa liên quan:
thủ thuật máy tính công nghệ thông tin tin học quản trị mạng computer networkTài liệu liên quan:
-
52 trang 433 1 0
-
24 trang 358 1 0
-
Top 10 mẹo 'đơn giản nhưng hữu ích' trong nhiếp ảnh
11 trang 319 0 0 -
Làm việc với Read Only Domain Controllers
20 trang 309 0 0 -
74 trang 303 0 0
-
96 trang 297 0 0
-
Báo cáo thực tập thực tế: Nghiên cứu và xây dựng website bằng Wordpress
24 trang 291 0 0 -
Đồ án tốt nghiệp: Xây dựng ứng dụng di động android quản lý khách hàng cắt tóc
81 trang 284 0 0 -
EBay - Internet và câu chuyện thần kỳ: Phần 1
143 trang 277 0 0 -
Tài liệu hướng dẫn sử dụng thư điện tử tài nguyên và môi trường
72 trang 269 0 0