为什么 MooseX::Storage 似乎不遵循某些对象的属性特征?
我整理了一个小测试用例来演示我的问题:
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);
我希望它能打印对象,但不会打印 P2 包中的“lol”属性 - 但是,我仍然可以在 $stored 的结果中看到这一点->pack
$VAR1 = {
'__CLASS__' => 'P1',
'blah' => bless( {
'magic' => 'This ok!',
'lol' => sub { "DUMMY" }
}, 'P3' )
};
我是否使用了 MooseX::Storage 错误,或者这看起来像是错误行为?
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
$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?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以将“blah”设为 P3 的 isa...
,现在 Dumper( $stored->pack ) 显示了这一点...
这看起来像是此 Moose 对象的正确序列化?
You can make 'blah' an isa of P3....
and now Dumper( $stored->pack ) shows this....
which looks like the correct serialisation for this Moose object?
是的,这看起来像一个错误。 您能否将其转换为使用 Test::More 的测试并将其提交到 RT 队列,然后有人(可能是我)会修复该问题。
请注意,如果您转储 $obj->store,您会发现该特征已正确应用于直接属性,但似乎它在继承过程中丢失了。
您可以在 RT
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.
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.
You can report bugs against MooseX::Storage in RT