Class-Std-Slots
view release on metacpan or search on metacpan
lib/Class/Std/Slots.pm view on Meta::CPAN
package Class::Std::Slots;
use warnings;
use strict;
use Carp;
use Scalar::Util qw(blessed refaddr weaken);
our $VERSION = '0.31';
my %signal_map = (); # maps id -> signame -> array of connected slots
my %signal_busy = (); # maps id -> signame -> busy flag
my %patched = (); # classes whose DESTROY we've patched
# Subs we export to caller's namespace
my @exported_subs = qw(
connect
lib/Class/Std/Slots.pm view on Meta::CPAN
_connect_usage() unless ref( $dst_obj ) eq 'CODE';
}
my $options = shift || {};
my $src_id = refaddr( $src_obj );
my $caller = ref( $src_obj );
_check_signals_exist( $caller, $sig_names )
unless $options->{undeclared};
my $weaken = !( $options->{strong} || ref( $dst_obj ) eq 'CODE' );
for my $sig_name ( @{$sig_names} ) {
# Stash the object and method so we can call it later.
my $dst_data = [ $dst_obj, $dst_method, $options ];
weaken( $dst_data->[0] ) if $weaken;
push @{ $signal_map{$src_id}->{$sig_name} }, $dst_data;
}
# Now badness: we replace the DESTROY that Class::Std dropped into
# the caller's namespace with our own. See the note under BUGS AND
# LIMITATIONS about this technique for replacing Class::Std's
# destructor.
unless ( exists $patched{$caller} ) {
# If there's nothing in the hash for this object we can't have
lib/Class/Std/Slots.pm view on Meta::CPAN
The options recognised by C<connect> itself are:
=over
=item reveal_source
Modify slot arg list to include a hash that describes the source of the signal.
=item strong
Normally the reference to the object containing the slot method is weakened (by
calling C<Scalar::Util::weaken> on it). Set this option to make the reference
strong - which means that once an object has been connected to no other
references to it need be kept.
Anonymous subroutine slots are always strongly referred to - so there is no
need to specify the C<strong> option for them.
=item undeclared
Allow a connection to be made to an undefined signal. It is possible for an object
to emit arbitrary signals by calling C<emit_signal>. Normally C<connect> checks that
( run in 0.336 second using v1.01-cache-2.11-cpan-a9ef4e587e4 )