in reply to Re^3: How to know function name and package from its ref?
in thread How to know function name and package from its ref?

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.