josh803316 has asked for the wisdom of the Perl Monks concerning the following question:

I have a package MyModule which uses an eval call for finding an object in a database.
package MyModule; eval { # $class is User (which uses Object as base) # example $db_response = User->find($query) $db_response = $class->$method($query); };
but for some reason inside my base class Object using method find the caller is not seen as the $class (User) it is seen as the Package (MyModule) that contains the eval. How would I change this to test for the correct Caller with caller->isa since the caller is not seen as $class.

Replies are listed 'Best First'.
Re: caller package and eval
by ikegami (Patriarch) on Sep 02, 2009 at 01:48 UTC

    caller indicates the package in effect when the calling code was compiled. If you want to change what caller returns, you'll need to change what package directive is in effect when the calling code was compiled.

    ...but are you sure you want caller? What's on the left-hand side of the arrow (->) is passed to the method as the first argument, not via caller.

      You mean just use if $class->isa instead of worrying about the caller. Thanks, that makes sense....I got too stuck copying example code I think.
        I don't understand how isa fits in here. If you mean to do the following, it seems useless to me.
        package User; sub find { my ($class, $query) = @_; die("Bad class") if !$class->isa('User'); ... }

        Someone would have to put effort into making that condition fail.