in reply to How to determine if a package method is defined

If you mean 'how do I test if a class, or any of its ancestors, supports a method?', then can is your friend i.e. in your case, the test would become $TEST->can(q/test_sub/).

Otherwise, if the question revolves around a sub/method being defined in a specific module, then you were close, but you forgot to consider precedence - if you'd have written defined &{$TEST->test_sub} or defined &{qq/${TEST}::test_sub/}...

P.S. Thanx for the tip almut - originally forgot the braces in the string

A user level that continues to overstate my experience :-))

Replies are listed 'Best First'.
Re^2: How to determine if a package method is defined
by almut (Canon) on Sep 30, 2009 at 23:06 UTC
    defined &{$TEST->test_sub}

    This would actually (try to) call the method...

    #!/usr/bin/perl my $TEST = "foo"; if ( defined &{$TEST->test_sub} ) { } __END__ Can't locate object method "test_sub" via package "foo" (perhaps you f +orgot to load "foo"?) at ./798474.pl line 4. --- #!/usr/bin/perl my $TEST = "foo"; if ( defined &{$TEST->test_sub} ) { } package foo; sub test_sub { print "hi\n" } __END__ hi