This seems to do the automatic wrapping properly. It just needs some clean-up and modulification, and it should be ready to ruin the day of anyone foolish enough to use it.

use strict; # Symbol table experiments. use Data::Dumper; #use Win32::SerialPort; # All entries in symbol table are uniquely identified by a typeglob. #print join "\n", # $::{'main::'}, # $main::{'main::'}, # $main::main::{'main::'}, # $main::main::main::{'main::'}, # ; my %OMIT; BEGIN { my @OMIT = qw( *main::UNIVERSAL:: ); @OMIT{@OMIT} = (); } wrap_destroy($_) foreach find_namespaces( 'main::' ); eval { my $f = Foo->new(); die 'adsfasdf'; }; eval { my $f = Foo::Foo->new(); die 'adsfasdf'; }; eval { my $f = Foo::Foo::Foo->new(); die 'adsfasdf'; }; eval { my $f = Foo::Foo::Bar->new(); die 'adsfasdf'; }; sub find_namespaces { my $seen = ref($_[0]) eq 'HASH' ? shift : {} ; my @names = @_; my @results; foreach my $name ( @names ) { no strict 'refs'; foreach my $entry ( keys %{$name} ) { next unless $entry =~ /::$/; my $typeglob = ${$name}{$entry}; next if $$seen{$typeglob}++; find_namespaces( $seen, $typeglob ); } } return keys %$seen ; } sub has_destroy { my $namespace = shift; no strict 'refs'; if ( exists ${$namespace}{DESTROY} ) { print "\t$namespace has DESTROY\n"; } } sub inherits_destroy { my $namespace = shift; $namespace =~ s/^\*(main::)?//; $namespace =~ s/::$//; return UNIVERSAL::can( $namespace, 'DESTROY' ); } sub wrap_destroy { my $namespace = shift; no warnings; no strict 'refs'; my $eater = $namespace . "DESTROY"; return if exists $OMIT{$namespace}; my $sub; if( has_destroy( $namespace ) ) { my $orig = \&{ ${$namespace}{DESTROY} }; $sub = sub { print "$eater Ate $namespace\n"; my @caller = caller(1); my @this = caller(1); $orig->(@_); eval{}; }; } elsif ( inherits_destroy( $namespace ) ) { print "$namespace inherits DESTROY\n";; } else { print "$namespace has no DESTROY\n";; $sub = sub { print "$eater Swallowed $namespace\n"; eval{}; } } *{ "$eater" }= $sub; } package Foo; sub new { bless {}, __PACKAGE__; } sub DESTROY { 1; } package Foo::Bar; sub new { bless {}, __PACKAGE__; } sub DESTROY { 1; } package Foo::Foo; sub new { bless {}, __PACKAGE__; } sub DESTROY { 1; } package Foo::Foo::Foo; sub new { bless {}, __PACKAGE__; } use base 'Foo::Foo'; package Foo::Foo::Bar; sub new { bless {}, __PACKAGE__; }


TGI says moo


In reply to Re: RFC: Acme::ExceptionEater by TGI
in thread RFC: Acme::ExceptionEater by kyle

Title:
Use:  <p> text here (a paragraph) </p>
and:  <code> code here </code>
to format your post, it's "PerlMonks-approved HTML":



  • Posts are HTML formatted. Put <p> </p> tags around your paragraphs. Put <code> </code> tags around your code and data!
  • Titles consisting of a single word are discouraged, and in most cases are disallowed outright.
  • Read Where should I post X? if you're not absolutely sure you're posting in the right place.
  • Please read these before you post! —
  • Posts may use any of the Perl Monks Approved HTML tags:
    a, abbr, b, big, blockquote, br, caption, center, col, colgroup, dd, del, details, div, dl, dt, em, font, h1, h2, h3, h4, h5, h6, hr, i, ins, li, ol, p, pre, readmore, small, span, spoiler, strike, strong, sub, summary, sup, table, tbody, td, tfoot, th, thead, tr, tt, u, ul, wbr
  • You may need to use entities for some characters, as follows. (Exception: Within code tags, you can put the characters literally.)
            For:     Use:
    & &amp;
    < &lt;
    > &gt;
    [ &#91;
    ] &#93;
  • Link using PerlMonks shortcuts! What shortcuts can I use for linking?
  • See Writeup Formatting Tips and other pages linked from there for more info.