Re: Revert use_ok() change to allow lexical effects?

Michael G Schwern <[email protected]>
Newsgroups gmane.comp.lang.perl.quality-assurance
Message-ID <[email protected]>
On 2012.4.11 7:35 AM, Andy Lester wrote:
> So is there ANY legit use for use_ok()?

Yes.  Sometimes you want to conditionally test if a module can be loaded and
its import does not blow up.

It's a convenience function so it can be more easily understood what's going
on and we don't each write it a million different ways.  require_ok() solves a
big chunk of the problem.

    if( something something ) {
        use_ok 'Foo';

#       Here's one long hand way...
#       require_ok 'Foo';
#       ok eval { Foo->import; 1; } or diag $@;

#       or maybe this, hope you remember that 1;
#       eval 'use Foo; 1;' or diag $@;
    }

Similar to how like() is basically a convenience for...

    my $regex = qr/bar/;
    ok $foo =~ $regex or diag "$foo does not match $regex";

If it didn't already exist, it could probably be argued that it's not needed.
 But it's there and can be left alone.


-- 
87. If the thought of something makes me giggle for longer than 15
    seconds, I am to assume that I am not allowed to do it.
    -- The 213 Things Skippy Is No Longer Allowed To Do In The U.S. Army
           http://skippyslist.com/list/
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.