tailieunhanh - Embedding Perl in HTML with Mason Chapter 11: Recipes- P2

Tham khảo tài liệu 'embedding perl in html with mason chapter 11: recipes- 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 11 Recipes- P2 Making Use of Autoflush Every once in a while you may have to output a very large component or file to the client. Simply letting this accumulate in the buffer could use up a lot of memory. Furthermore the slow response time may make the user think that the site has stalled. Example 11-4 sends out the contents of a potentially large file without sucking up lots of memory. Example 11-4. args filename args init local FILE open FILE filename or die Cannot open filename m- autoflush 1 while FILE m- print _ m- autoflush 0 init If each line wasn t too huge you might just flush the buffer every once in a while as in Example 11-5. Example 11-5. args filename args init local FILE open FILE filename or die Cannot open filename while FILE m- print _ m- flush_buffer unless . 10 m- flush_buffer init The unless . 10 bit makes use of the special Perl variable . which is the current line number of the file being read. If this number modulo 10 is equal to zero we flush the buffer. This means that we flush the buffer every 10 lines. Replace the number 10 with any desired value. User Authentication and Authorization One problem that web sites have to solve over and over is user authentication and authorization. These two topics are related but not the same as some might think. Authentication is the process of figuring out if someone is who he says he is and usually involves checking passwords or keys of some sort. Authorization comes after this when we want to determine whether or not a particular person is allowed to perform a certain action. There are a number of modules on CPAN intended to help do these things under mod_perl. In fact Apache has separate request-handling phases for both authentication and authorization that mod_perl can handle. It is certainly possible to use these modules with Mason. You can also do authentication and authorization using Mason components as seen in Chapter 8 . .

TỪ KHÓA LIÊN QUAN