如何命名类/包/模块,例如

发布于 2024-09-12 22:51:43 字数 324 浏览 9 评论 0原文

如果一个包的唯一目的是扩展另一个模块以便您可以对其应用角色,您会如何命名该包?我需要一个扩展(子类) Template::Context 的包Moose 这样我就可以创建角色和特征应用于它,但我不知道如何命名这个包(类)。有什么建议吗?

How would you name a package who's sole purpose was to extend another module so you could apply roles to it? I need a package that extends (sub classes) Template::Context with Moose So I can then create roles and traits to apply to it, but I don't know what to name this package (class). Any advice?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

雨后彩虹 2024-09-19 22:51:43

由于它是驼鹿特定的角色化,所以我在名字中加入了驼鹿。模板::上下文::Moosified。或 Template::Context::WithAntlers。

但是拥有一个中间子类只是为了让你可以将角色附加到它上面,这很奇怪。您可以跳过该中间人,直接声明组合类。

package Template::Context::ForBreakfast;

use Moose;
extends "Template::Context";
with "Bacon", "Eggs", "Toast";

类名应该不属于角色构成。

Since its Moose-specific role-ification, I'd have Moose in the name. Template::Context::Moosified. Or Template::Context::WithAntlers.

But having an intermediate subclass just so you can stick roles onto it is weird. You can skip that middleman and simply declare composed classes directly.

package Template::Context::ForBreakfast;

use Moose;
extends "Template::Context";
with "Bacon", "Eggs", "Toast";

The class name should fall out of the role composition.

森林迷了鹿 2024-09-19 22:51:43

我不确定这是否已获得批准,但您始终可以尝试直接应用该角色。

package R; 
use Moose::Role; 
sub f { say 42 } 

package main; 
use URI;
R->meta->apply( Moose::Meta::Class->initialize( 'URI' ) ); 
URI->new->f

当然,这需要一些补充,绝对不能保证长期有效,而且可能完全不受支持。然而,这就是无糖 MOP 的有效工作原理。

I'm not sure this is approved but you can always try applying the Role directly.

package R; 
use Moose::Role; 
sub f { say 42 } 

package main; 
use URI;
R->meta->apply( Moose::Meta::Class->initialize( 'URI' ) ); 
URI->new->f

Granted this needs some sugaring up, has absolutely no guarantees to work long term, and is probably totally unsupported. This is however how the MOP unsugared effectively works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文