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"; }
In reply to Re: ->isn't('UNIVERSAL') - stopping UNIVERSAL pollution?
by mreece
in thread ->isn't('UNIVERSAL') - stopping UNIVERSAL pollution?
by diotalevi
| For: | Use: | ||
| & | & | ||
| < | < | ||
| > | > | ||
| [ | [ | ||
| ] | ] |