Perl - 当 <%method PREPARE> 被调用时

Perl - When <%method PREPARE> gets called

我是 Perl Mason 的新手。

我发现这个问题时建议将服务调用放在 PREPARE 块中。但是,当我将服务调用放入其中时,其中的代码似乎永远不会自行执行。

<%method PREPARE>

请建议以上块的用途及其用法。

来自 Mason 手册

The base component class, Mason::Component, has but a few built-in methods: handle, render, wrap, main, m, and cmeta.

The main method contains the mix of HTML and Perl in the main part of the component.

You can add other methods that output HTML via the section; these methods automatically have access to $self and $m.

<%method leftcol>
  <table><tr>
    <td><% $foo %></td>
    ...
  </tr></table>
</%method>

...

<% # call leftcol method and insert HTML here %>
<% $.leftcol %>

这意味着您通过 <%method PREPARE> 声明了一个名为 PREPARE 的方法,没有任何参数列表,并且在编写方法主体之后,您将使用 </%method>.

结束它

并且,稍后您将在某个地方使用 <% $.PREPARE %> 调用它。有关详细信息,请参阅 Mason Manual