Mason (HTML::Mason) 开发指南:从基础到项目实践
1. 嵌入 Perl 代码示例
在 Mason 中,可以轻松地嵌入 Perl 代码到 HTML 页面中。以下是一个简单的示例:
# we can also include function definitions - this function # is called in the HTML below sub hello_world { return "hello, world!" } </%perl> Hello <b><% $client %></b>. <br> You are using <b><% $agent %></b>. <br> The local time is <b><% $time %></b>. <br> Your request method is <b><% $method %></b>. <br> A message: <b><% hello_world() %></b>. </table> </body> </html>要查看这段代码的运行结果,可以将以下任意一个 URL 加载到浏览器中:
-http://localhost/mason/perl.html
-