package WorkerResource; use Thread::Queue::Queueable; use base qw(Thread::Queue::Queueable); sub new { my $class = shift; my %obj : shared = (); # # ...do some object init.. # return bless \%obj, $class; } # # overload Thread::Queue::Queueable marshal methods # sub curse { # # marshall any complex object members into something # that can be passed over a Thread::Queue::Duplex, # i.e., either a scalar, or a threads::shared ref # note that, if your object is threads::shared, # it implies all its members are either scalar or # threads::shared, so you can use the default TQQ::curse() # # } sub redeem { my ($class, $obj) = @_; # # unmarshall any complex object members and rebless the # object back into its class. # note that, if your object is threads::shared, # it implies all its members are either scalar or # threads::shared, so you can use the default TQQ::redeem(), # which just blesses # } package main; my $q = Thread::Queue::Duplex->new(); my $thread = threads->new(\&run, $q); my $resource = WorkerResource->new(); my $msgid = $q->enqueue($resource); my $result = $q->wait($msgid);