B-Hooks-EndOfScope

 view release on metacpan or  search on metacpan

lib/B/Hooks/EndOfScope/PP/FieldHash.pm  view on Meta::CPAN

use Tie::Hash ();
use Hash::Util::FieldHash 'fieldhash';

# Here we rely on a combination of several behaviors:
#
# * %^H is deallocated on scope exit, so any references to it disappear
# * A lost weakref in a fieldhash causes the corresponding key to be deleted
# * Deletion of a key on a tied hash triggers DELETE
#
# Therefore the DELETE of a tied fieldhash containing a %^H reference will
# be the hook to fire all our callbacks.

fieldhash my %hh;
{
  package # hide from pause too
    B::Hooks::EndOfScope::PP::_TieHintHashFieldHash;
  our @ISA = ( 'Tie::StdHash' );  # in Tie::Hash, in core
  sub DELETE {
    my $ret = shift->SUPER::DELETE(@_);
    B::Hooks::EndOfScope::PP::__invoke_callback($_) for @$ret;
    $ret;

lib/B/Hooks/EndOfScope/PP/HintHash.pm  view on Meta::CPAN

    if _NEEDS_MEMORY_CORRUPTION_FIXUP;

  sub B::Hooks::EndOfScope::PP::HintHash::__GraveyardTransport::DESTROY {

    # Resurrect the hinthash being destroyed, persist it into the graveyard
    push @Hint_Hash_Graveyard, $_[0];

    # ensure we won't try to re-resurrect during GlobalDestroy
    bless $_[0], 'B::Hooks::EndOfScope::PP::HintHash::__DeactivateGraveyardTransport';

    # Perform explicit free of elements (if any) triggering all callbacks
    # This is what would have happened without this code being active
    %{$_[0]} = ();
  }
}

1;



( run in 2.748 seconds using v1.01-cache-2.11-cpan-9b1e4054eb1 )