ロールを適用できるように別のモジュールを拡張することだけを目的としているパッケージに、どのように名前を付けますか? (サブクラス) Template::ContextをMooseで拡張するパッケージが必要なので、それに適用する役割と特性を作成できますが、このパッケージ (クラス) の名前がわかりません。何かアドバイス?
2 に答える
3
Moose 固有の役割設定なので、名前に Moose を付けたいと思います。Template::Context::Moos化。または Template::Context::WithAntlers。
しかし、役割を固定できるようにするためだけに中間サブクラスを用意するのは奇妙です。その仲介者をスキップして、構成されたクラスを直接宣言するだけです。
package Template::Context::ForBreakfast;
use Moose;
extends "Template::Context";
with "Bacon", "Eggs", "Toast";
クラス名はロール構成から外れる必要があります。
于 2010-08-04T07:15:01.647 に答える
1
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.
于 2010-08-10T04:54:33.680 に答える