views:

141

answers:

2

Hi,

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?

+6  A: 

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

perigrin
Please provide a link to the place to submit this? thanks!
Ether
A: 

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?

/I3az/

draegtun