I'm still not sure what the use case is, but you can overload
the class to handle code dereferencing.
package ExampleClass;
use overload '&{}' => &__call__; # Or an anon sub.
sub new {
bless {@_}, shift;
}
sub __call__ {
sub { warn "calling an instance event" };
}
package main;
my $obj = ExampleClass->new;
$obj->();
&$obj(); # same as $obj->()
Typical output:
$ perl 44956235.pl
calling an instance event at 44956235.pl line 7.
calling an instance event at 44956235.pl line 7.
与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…