Embedding Perl in HTML with Mason Chapter 2: Components- P2

Tham khảo tài liệu 'embedding perl in html with mason chapter 2: components- 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ả | Chapter 2 Components- P2 This example demonstrates all the syntax possibilities for this block. First of all we have argument types and names. The valid types are scalar array and hash represented by their corresponding Perl sigil @ or exactly as would be expected. It is possible to give an argument a default value to be used if none is provided when the component is called. Any argument without a default is considered a required argument. Calling a component without specifying all its required arguments will cause a fatal exception to be thrown. An argument s default can refer to an earlier argument so this is completely legal args x y x 2 20 50 100 args While this block looks as if it contains Perl it is important to realize that its syntax is actually something unique to Mason. Importantly lines should not end with a semicolon or comma and each variable definition must be on a single line. It is possible to have comments both after an argument declaration and on their own line. Comments start with the character and continue to the end of the line just as in Perl. Blank lines are also allowed. filter blocks A filter block is called after a component has finished running. It is given the entire output of the component in the _ variable and any changes to this variable are reflected in the output of the component. For example this filter uppercases all of the component s output filter s w U 1 g filter once blocks This block is executed whenever the component is loaded into memory. It is executed before any other block including an init block . Any variables declared here remain in existence and in scope until the component is flushed from memory or the Perl interpreter running Mason shuts down whichever comes first. The once section is useful for things like creating database handles or instantiating large resourceintensive objects. The universe is this big size once my size calculate_size_of_universe once cleanup blocks The cleanup block is executed right before .

Không thể tạo bản xem trước, hãy bấm tải xuống
TỪ KHÓA LIÊN QUAN
TÀI LIỆU MỚI ĐĂNG
16    75    2    27-06-2024
Đã 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.