I have put together a little test case to demonstrate my problem:
我已经整理了一个小测试用例来演示我的问题:
package P1;
use Moose;
use MooseX::Storage;
with Storage;
has 'blah' => (
is => 'rw',
);
package P2;
use Moose;
use MooseX::Storage;
with Storage;
has 'lol' => (
is => 'rw',
traits => ['DoNotSerialize']
);
package P3;
use Moose;
extends 'P2';
has 'magic' => (
is => 'rw',
);
package Test;
my $obj = P3->new(
magic => 'This ok!',
lol => sub { 'weee' }
);
my $stored = P1->new(blah => $obj);
use Data::Dumper; print Dumper ($stored->pack);
I would expect this to print the object, but not the 'lol' attribute in the P2 package - however, I can still see this in the result of $stored->pack
我希望这打印对象,但不打包P2包中的'lol'属性 - 但是,我仍然可以在$ stored-> pack的结果中看到这一点
$VAR1 = {
'__CLASS__' => 'P1',
'blah' => bless( {
'magic' => 'This ok!',
'lol' => sub { "DUMMY" }
}, 'P3' )
};
Am I using MooseX::Storage wrong, or does this look like buggy behaviour?
我使用MooseX :: Storage是错误的,还是看起来像马车行为?
2 个解决方案
#1
You can make 'blah' an isa of P3....
你可以让'blah'成为P3的isa ....
has 'blah' => (
is => 'rw',
isa => 'P3',
);
and now Dumper( $stored->pack ) shows this....
现在Dumper($ stored-> pack)显示了这个....
$VAR1 = {
'__CLASS__' => 'P1',
'blah' => {
'__CLASS__' => 'P3',
'magic' => 'This ok!'
}
};
which looks like the correct serialisation for this Moose object?
看起来像这个Moose对象的正确序列化?
#2
Yup that looks like a bug. Can you turn this into a test that uses Test::More and submit it to the RT queue and someone (probably me) will fix that.
看起来像个臭虫的Yup。你能把它变成一个使用Test :: More并将它提交到RT队列的测试,有人(可能是我)会修复它。
Note that if you Dump $obj->store you see that the trait is properly applied to the direct attribute but it seems that it's getting lost during the inheritance process.
请注意,如果您转储$ obj-> store,您会看到该特征已正确应用于direct属性,但它似乎在继承过程中丢失了。
You can report bugs against MooseX::Storage in RT
您可以在RT中报告针对MooseX :: Storage的错误
#1
You can make 'blah' an isa of P3....
你可以让'blah'成为P3的isa ....
has 'blah' => (
is => 'rw',
isa => 'P3',
);
and now Dumper( $stored->pack ) shows this....
现在Dumper($ stored-> pack)显示了这个....
$VAR1 = {
'__CLASS__' => 'P1',
'blah' => {
'__CLASS__' => 'P3',
'magic' => 'This ok!'
}
};
which looks like the correct serialisation for this Moose object?
看起来像这个Moose对象的正确序列化?
#2
Yup that looks like a bug. Can you turn this into a test that uses Test::More and submit it to the RT queue and someone (probably me) will fix that.
看起来像个臭虫的Yup。你能把它变成一个使用Test :: More并将它提交到RT队列的测试,有人(可能是我)会修复它。
Note that if you Dump $obj->store you see that the trait is properly applied to the direct attribute but it seems that it's getting lost during the inheritance process.
请注意,如果您转储$ obj-> store,您会看到该特征已正确应用于direct属性,但它似乎在继承过程中丢失了。
You can report bugs against MooseX::Storage in RT
您可以在RT中报告针对MooseX :: Storage的错误