If you have control over the first object, you can use Class::Observable:
package FirstObject;
use base qw( Class::Observable );
...
sub DESTROY {
my ( $self ) = @_;
$self->notify_observers( 'DESTROY' );
}
package SecondObject;
sub take_first_object {
my ( $class, $first_object ) = @_;
$first_object->add_observer( $class );
}
sub update {
my ( $class, $first_object, $type ) = @_;
return unless ( $type eq 'DESTROY' );
... do stuff with $first_object ...
}
If you don't have control over the first object and it's well designed, maybe you could subclass it to add the Observable behavior.
Chris
M-x auto-bs-mode