I've posted a sample working app of the issue I'm facing below: In summary I'm trying to pass a blessed object resulting from a call to the Net::Twitter constructor to my worker thread but keep encountering the following error:
Invalid value for shared scalar at thread_test.pl line 77.
use threads; use threads::shared; use Thread::Queue; use strict; use Wx; my %thread_hash; share(%thread_hash); use Net::Twitter; package MyApp; use base 'Wx::App'; sub OnInit { my $self = shift; my $frame = MyFrame->new(); $frame->Show(1); $self->SetTopWindow($frame); return 1; } package MyFrame; use base 'Wx::Frame'; use Wx qw(wxTE_MULTILINE wxVERTICAL wxID_DEFAULT); use Wx::Event qw(EVT_COMMAND EVT_CLOSE EVT_BUTTON); my $done_event : shared = Wx::NewEventType; sub new { my $class = shift; my $self = $class->SUPER::new(undef, -1, "Testing Threads"); $self->{text} = Wx::TextCtrl->new($self, -1, "", [-1,-1], [300, 30 +0], wxTE_MULTILINE); $self->{button} = Wx::Button->new($self, -1, "&Run Test"); my $sizer = Wx::BoxSizer->new(wxVERTICAL); $sizer->Add($self->{text}); $sizer->Add($self->{button}); $self->SetSizer($sizer); $self->{text}->AppendText("test\n"); EVT_COMMAND($self, -1, $done_event, \&done); EVT_CLOSE($self, \&on_close); EVT_BUTTON($self,$self->{button}, \&on_button ); my $sendqueue = Thread::Queue->new(); my $worker = threads->create(\&worker, $self, $sendqueue ); $self->{queue} = $sendqueue; $self->{worker} = $worker; InitTwit(); $self->Fit; return $self; } sub InitTwit { my $user = 'twitter'; my $pass = 'twit_password'; my $twit = Net::Twitter->new( username => $user, password => $pass ); $thread_hash{'twit'} = $twit; } sub on_button { my ($self, $event) = @_; $self->{queue}->enqueue('GO'); } sub on_close { my ($self, $event) = @_; $self->{queue}->enqueue('STOP'); $self->{worker}->join; $event->Skip(1); } sub done { my ($self, $event) = @_; my $text = $event->GetData; $self->{text}->AppendText("$text\n"); } sub worker { my($self, $event) = @_; while (my $message = $event->dequeue ) { return 1 if $message eq 'STOP'; eval { my $result = $thread_hash{'twit'}->update('Hello, world!'); }; if ( my $err = $@ ) { die $@ unless blessed $err && $err->isa('Net::Twitter::Error +'); warn "HTTP Response Code: ", $err->code, "\n", "HTTP Message......: ", $err->message, "\n", "Twitter error.....: ", $err->error, "\n"; } my ($text) = "Updated posted successfuly\n"; my $response : shared = $text; print "$response\n"; my $thread_event = Wx::PlThreadEvent->new(-1, $done_event, $re +sponse); Wx::PostEvent($self, $thread_event); } } package main; MyApp->new->MainLoop;

Any thoughts? I know the easiest solution is to simply call the constructor in the thread but at this point I really would like to understand why it isn't working.
Thanks again, Paul


In reply to passing shared blessed object part 2 by Anonymous Monk

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.