使用Mason2。有3个组件。梅森方法范围 - 覆盖
/Base.mc
/tmp/Base.mc
/tmp/index.mc
的/tmp/index.mc
与内容:
hello from <% $m->request_path %></br>
<% $.Some %>
的$.Some
处于/Base.mc
定义的方法:
<%augment wrap><% inner() %></%augment>
<%method Some>
The default "Some" method defined in the <% __PACKAGE__ %>
</%method>
的/tmp/Base.mc
仅包含
<%augment wrap><% inner() %></%augment>
个
请求/tmp/index
打印:
hello from /tmp/index
The default "Some" method defined in the MC0::Base_mc
现在加入Some
方法为/tmp/Base.mc
<%method Some>
Redefined "Some" method in <% __PACKAGE__ %>
</%method>
再次请求/tmp/index
,它打印:
hello from /tmp/index
Redefined "Some" method in MC0::tmp_Base_mc
它兑现了重新定义Some
方法在包裹/tmp/Base.mc
的问题是:
如果梅森允许重新定义如上方法,什么是<%override method>
的目的是什么? <%override Some>
有什么不同? (当我测试时,它打印相同)。
EDIT也许这个问题可以简化为下面的perl代码。
use 5.014;
use warnings;
package My;
use Moose;
sub some { say "some from " . __PACKAGE__ }
package My2;
use Moose;
extends 'My';
sub some { say "another some from " . __PACKAGE__ }
#the above line is an correct way to refefine a sub "some"?
#so don;t need to use the
#override 'some' => sub { say "another some from " . __PACKAGE__ };
package main;
use My2;
my $m = My2->new();
$m->some();
在这两种情况下
(例如“纯”重新定义,并用“覆盖”重新定义)打印:
another some from My2
所以,唯一不同的是要求在some
与override
的super()
的可能性?和抱歉,如果我错过了一些基本knowlegde ...;(
所以唯一的区别是:当使用'<%override ...>'我可以调用'<% super() %>',但是当简单重新定义方法时,我不能调用'<% super() %>'? – cajwine 2014-09-21 08:06:00
编辑这个问题 - 也许它更清晰的是“梅森”。 – cajwine 2014-09-21 09:01:42
我会更新我的答案。 – 2014-09-21 09:27:38