in reply to ->isn't('UNIVERSAL') - stopping UNIVERSAL pollution?

how about using something like Class::Can?
my $obj = bless {}, 'Bar'; $obj->violation; package Bar; use Class::Can; CHECK { ## See what UNIVERSAL can do.. my %uni_can = Class::Can->interrogate('UNIVERSAL'); ## These are ok.. delete $uni_can{$_} foreach qw( can isa VERSION ); ## Anything left is not ok.. my @bad_methods = keys %uni_can; foreach my $method ( @bad_methods ) { *{ __PACKAGE__ . "::$method" } = sub { die "UNIVERSAL::$method not allowed"; }; } } package UNIVERSAL; sub violation { print "haha, a violation\n"; }
it's not perfect. someone can put methods into UNIVERSAL that 'override' Bar's methods, so maybe you want to expand the 'ok' list to those methods declared by package Bar. there's probably another gotcha or two this doesn't account for, but it's a start..

Replies are listed 'Best First'.
Re^2: ->isn't('UNIVERSAL') - stopping UNIVERSAL pollution?
by diotalevi (Canon) on Sep 05, 2006 at 21:42 UTC

    I'm already doing this with Devel::Symdump and watching for when B::sub_generation increments because then that's time to renew my prohibitions.

    ⠤⠤ ⠙⠊⠕⠞⠁⠇⠑⠧⠊