反正有$self
變成MooseX::Types
強制?我在對象中有其他數據,我想用它來將我的強制從String
接種到Object
。或者,有沒有什麼像Class::MOP
的initializer
,這將允許我這樣做 - 它必須在之前觸發類型檢查。
請求的僞代碼:
with 'DBHandle';
has 'database' => (isa => 'Str', is => 'ro', default => 'Db');
has 'schema' => (isa => 'Str', is => 'ro', default => 'schema');
has 'table' => (isa => 'Str', is => 'ro', default => 'column);
has 'columns' => (isa => DBCols, is => 'ro', default => sub {[qw/foo bar baz/]});
在這裏,我想 「列」 要挾到DBCols
- DBCol的(對象)的數組引用 - 需要使用catalog
,schema
和col
屬性發現在課堂上,以及由DBHandle
提供的dbh/singleton。
爲了減少這種僞現象,實際情況只會稍微複雜一些。我能夠完成以上around
,現在我想我做的就是創建一個屬性特徵,將允許這句法:
has 'column_id' => (
isa => Int
, is => 'ro'
, traits => ['DBKey']
, default => 5
, column => 'foo'
);
凡DBKey
提供的屬性特徵column
,脅迫到DBCol
以同樣的方式上述columns
會:這將需要能夠訪問類database
,schema
,table
,並再次爲dbh
的單身人士。
你能給出一個僞代碼的例子嗎? – Ether 2010-12-17 17:52:02
更新了僞代碼 – 2010-12-17 18:16:36