in reply to ->isn't('UNIVERSAL') - stopping UNIVERSAL pollution?
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..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"; }
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: ->isn't('UNIVERSAL') - stopping UNIVERSAL pollution?
by diotalevi (Canon) on Sep 05, 2006 at 21:42 UTC |