Beefy Boxes and Bandwidth Generously Provided by pair Networks
good chemistry is complicated,
and a little bit messy -LW
 
PerlMonks  

Re: Ref to Method?

by Narveson (Chaplain)
on Mar 04, 2009 at 19:39 UTC ( [id://748294]=note: print w/replies, xml ) Need Help??


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.

Log In?
Username:
Password:

What's my password?
Create A New User
Domain Nodelet?
Node Status?
node history
Node Type: note [id://748294]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this?Last hourOther CB clients
Other Users?
Others making s'mores by the fire in the courtyard of the Monastery: (4)
As of 2024-04-25 07:20 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    No recent polls found