in reply to Attempt to make shared Moose object

A few things:

  1. "shared_clone" returns a new object, and your code does not store that value anywhere.
  2. BUILD does not change the value returned by 'new'. I think you need to use an "around" modifier for "new".
  3. I don't see any reason bar would have a value except that you must have left some code out of the example somewhere.

To sum up:

use threads; use strict; { package ThreadableObj; use Moose; use threads::shared; use Data::Dumper; around 'new' => sub { my $orig = shift; my $class = shift; my $self = $class->$orig(@_); my $shared_self : shared = shared_clone($self); # here the blessed() already be the version in threads::shared print Dumper($shared_self),"\n"; return $shared_self; }; has foo => ( is => 'rw', isa => 'Str' ); has bar => ( is => 'rw', isa => 'Int' ); } # here lives my $obj : shared = ThreadableObj->new(foo=>'foovalue');

Replies are listed 'Best First'.
Re^2: Attempt to make shared Moose object
by llancet (Friar) on Mar 02, 2010 at 02:05 UTC
    Thanks a lot!
    (delete faulse reply)