Maybe you need to escape the "$self" as "\$self" since eval will first evaluate the $code, in which case $self will be subsititued by its value, something like "ClassName->HASH(...)". The following seemed to work:
package Foo;
use strict;
sub new{
return bless {}, shift;
}
sub foo{
my $self = shift;
print "Foo called\n";
}
sub bar{
my $self = shift;
print "Bar called\n";
my $code = "\$self->foo()"; # it won't work withouth the "\"
eval $code;
}
1;
then:
use strict;
use warnings;
use Foo;
my $c = Foo->new();
$c->foo();
$c->bar();
__OUTPUT__
Foo called
Bar called
Foo called