Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How come MooseX::Storage doesn't seem to follow attribute traits for some objects?

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?

like image 612
ocharles Avatar asked Mar 07 '09 14:03

ocharles


2 Answers

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

like image 118
perigrin Avatar answered Oct 15 '22 00:10

perigrin


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?

like image 30
draegtun Avatar answered Oct 15 '22 00:10

draegtun