perl – 为什么MooseX :: Storage似乎不遵循某些对象的属性特征?

前端之家收集整理的这篇文章主要介绍了perl – 为什么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是错误的,还是看起来像有错误的行为?

解决方法

你可以把’等等’变成P3的isa ……
has 'blah' => (
    is  => 'rw',isa => 'P3',);

现在Dumper($stored-> pack)显示了这个….

$VAR1 = {
      '__CLASS__' => 'P1','blah' => {
                  '__CLASS__' => 'P3','magic' => 'This ok!'
                }
};

看起来像这个Moose对象的正确序列化?

猜你在找的Perl相关文章