Chinaunix首页 | 论坛 | 博客
  • 博客访问: 574826
  • 博文数量: 207
  • 博客积分: 10128
  • 博客等级: 上将
  • 技术积分: 2440
  • 用 户 组: 普通用户
  • 注册时间: 2004-10-10 21:40
文章分类

全部博文(207)

文章存档

2009年(200)

2008年(7)

我的朋友

分类:

2009-04-25 07:50:23

看来用 Moose 的还真不少,如果 perl5 的 OOP 能做些改进就好了  

Seems the iBroadcast team in the BBC has now drunk the Moose Kool-Aid and they're happy with it. They're particularly happy with using roles instead of inheritance. They've found a bug with the excellent and they'll be filing a report later. Basically, mixing normal and parameterized roles in a single 'with' statement caused the parameterized roles to be ignored (if I read the report correctly). This forces them to fall back to multiple 'with' statements until this is fixed.

That raises another issue. When you use multiple 'with' statements, you don't get the composition safety. What you do get is a predictable behavior, but one which is nonetheless surprising if you're thinking of roles as "mixins":

  package Role1;
  use Moose::Role;
  sub foo { __PACKAGE__ }

  package Role2;
  use Moose::Role;
  sub foo { __PACKAGE__ }

  package Foo;
  with 'Role1';
  with 'Role2';
  print Foo->foo;

If those roles were mixins, that would print 'Role2'. That actually prints 'Role1', not 'Role2'. This behavior is different from mixins which employ a "last wins" strategy. Since the first 'with' provides the 'foo' method, the second 'with' will see the method and silently fail to provide its own. The dev version of Moose (0.75_01) should warn if this happens.

阅读(568) | 评论(0) | 转发(0) |
给主人留下些什么吧!~~