Beefy Boxes and Bandwidth Generously Provided by pair Networks
Welcome to the Monastery
 
PerlMonks  

Re: RFC: Acme::ExceptionEater

by TGI (Parson)
on Sep 08, 2007 at 00:44 UTC ( [id://637775]=note: print w/replies, xml ) Need Help??


in reply to RFC: Acme::ExceptionEater

Why not take arguments in your use statement, and then inject an exception eating DESTROY method into any listed classes. Just pervert the code tye posted in response to you, et viola!

package Acme::ExceptionEater; my %done; sub import { shift @_; for my $pkg ( @_ ) { next if $done{$pkg}++; $pkg .= "::DESTROY"; my $orig= \&{$pkg}; no warnings; *{$pkg}= sub { $orig->(@_); eval{}; } } }

Warning: This is a totally untested copy/paste/perversion of tye's code.

Assuming I didn't break it, then you can do:

use Happy::Friendly::Package; use Acme::ExceptionEater qw( Happy::Friendly::Package );

And you too will have mysteriously silent failures in your code!


TGI says moo

Replies are listed 'Best First'.
Re^2: RFC: Acme::ExceptionEater
by kyle (Abbot) on Sep 08, 2007 at 02:27 UTC

    Wow, TGI, I love that idea! I regret that I have but one vote to give for it. Thank you!

      I don't think my mother wants me to play with you guys.
Re^2: RFC: Acme::ExceptionEater
by itub (Priest) on Sep 11, 2007 at 13:50 UTC
    While you are at it, you could look at the symbol table and inject the exception-eating DESTROY into every package that happens to be loaded! ;-)

      I was thinking about that yesterday, but I couldn't figure out where to look to get the required info in a reliable fashion.

      The obvious place to look is in %INC. But that gives you munged names, and only on a per file included basis. Files that define multiple packages would not be handled properly.

      Based on my investigation of perlguts and perlapi each namespace has a stash associated with it. So if you have a list of all the stashes, you can get their names, and if you have their names, you have all the namespaces you want to add a perverse DESTROY method to.

      Do you have any idea where to find either a list of active namespaces or stashes?


      TGI says moo

        You usually start in %main:: (which is also %::) and look for keys ending in "::" that have a hash entry defined and recurse (skipping over %main::main::, etc).

        - tye        

        I got this with some monkeying around:

        use Data::Dumper; package Foo::Empty; package Foo::OneVar; $one_var = 'foo!'; package main; my %done; sub seek_destroy { my ( $name ) = @_; return if $done{$name}++; foreach my $package ( grep { /::$/ } keys %{$name} ) { print "$name$package\n"; print "!!! $name$package" . "DESTROY!!\n" if exists ${"$name$package"}{DESTROY}; seek_destroy( "$name::$package" ) if defined $package; } } seek_destroy( 'main::' );

        It finds both "Foo::OneVar" and "Foo::Empty", and it sees the DESTROY methods of Data::Dumper and main::Regex. It spews warnings like crazy, but I can polish that up later.

Re^2: RFC: Acme::ExceptionEater
by samizdat (Vicar) on Sep 10, 2007 at 12:39 UTC
    now we know what the phrase "evil hacker" really means... ;-]

    Don Wilde
    "There's more than one level to any answer."

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://637775]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others studying the Monastery: (6)
As of 2024-03-28 11:50 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found