in reply to Ref to Method?

I'm intrigued. Presumably the run_test sub can test a variety of methods in different packages, thus saving you some typing and giving you all the benefits that flow from Not Repeating Yourself.

Could you possibly share an example?

The benefits may be worth the tedium of having to type

$new = sub { return Foo->new(@_) }; run_test( $new );

Then again, Perl can save you this tedium by way of a wrapper for run_test. How about the following? (Untested.)

sub test_package_method { my ($package, $method) = @_; my $code_ref = sub{ return $package->$method() }; run_test( $code_ref ); }

Replies are listed 'Best First'.
Re^2: Ref to Method?
by pileofrogs (Priest) on Mar 04, 2009 at 21:47 UTC

    Yup. That's the basic idea. A huge number of tests I write look like:

    my $thing = eval { blort($value) }; ok( !$@, 'blort didn't blow up') || diag $@;

    If I can, I like to populate a data structure with test specifics and then run a sub against the contents of that structure. One nice side affect is you can calculate plan tests => X. Ultimately, I'd like to be able to write tests in a config file.