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

发布于 2024-07-14 06:36:13 字数 963 浏览 7 评论 0原文

我整理了一个小测试用例来演示我的问题:

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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

戏剧牡丹亭 2024-07-21 06:36:14

您可以将“blah”设为 P3 的 isa...

has 'blah' => (
    is  => 'rw',
    isa => 'P3',
);

,现在 Dumper( $stored->pack ) 显示了这一点...

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

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

You can make 'blah' an isa of P3....

has 'blah' => (
    is  => 'rw',
    isa => 'P3',
);

and now Dumper( $stored->pack ) shows this....

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

which looks like the correct serialisation for this Moose object?

彻夜缠绵 2024-07-21 06:36:13

是的,这看起来像一个错误。 您能否将其转换为使用 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

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文