in reply to adding temporary method to a class

If don't want to add the method just locally, you can remove it using undef *Class::method;. Here's an example:
my $foo = Foo->new; *Foo::bar = sub { print "bar\n"; }; $foo->bar(); undef *Foo::bar; $foo->bar(); package Foo; sub new { return bless {}, shift; } 1;
bar Can't locate object method "bar" via package "Foo" at line 9.