The relevant things are pretty big and messy:
In general, I'm attempting to make a event dispatcher class. Obviously, the EventDispatcher has to store event listeners in some form. Moreover, I want the whole thing to be thread compatible, so the EventDispatcher object should be shared.
This is the part of code related to the topic. The whole thing is too big (several files).
package Dispatcher; use strict; use threads::shared; sub new { my($inv,%arg) = @_; my $class = ref $inv || $inv; # I forgot the name of the function. # It's provided by the new version of threads::shared. # It returns a shared version of data, very convenient, # so we don't have to recursively share things. my $data = shared_data { %arg, _listeners => { 'EVENT_FOO' => [], 'EVENT_BAR' => [] } }; return bless $data,$class; } sub addListener { my($self,$e_name,$ref) = @_; die if ! exists $self->{_listeners}{$e_name}; # here will throw an error # as the sub ref cannot be put into shared store push @{$self->{_listeners}{$e_name}}, $ref; } sub dispatchEvent { my $event = shift; my $e_name = $event->eventName; die if ! exists $self->{_listeners}{$e_name}; foreach my $func ( @{$self->{_listeners}{$e_name};} ) { &$func($event); } }
So, I use Package::Function name instead, and works well.

In reply to Re^4: How to know function name and package from its ref? by llancet
in thread How to know function name and package from its ref? by llancet

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.