On 15 Aug 2005, at 17:12, Yitzchak Scott-Thoennes wrote:
[snip]
The throw_ok { ... } syntax only works because the throw_ok sub exists
and has a prototype that specifies a subref is expected; if you don't
load Test::Exception by the time the throw_ok call is compiled, it
is parsed as an indirect object call of the "throw_ok" method on the
object or class returned by the {} block:

$ perl -MO=Deparse,-p -we'throws_ok { Net::Pcap::lookupdev() } "/ ^Usage: Net::Pcap::lookupdev\(err\)/", "calling lookupdev() with no argument"'
BEGIN { $^W = 1; }
do {
    Net::Pcap::lookupdev()
}->throws_ok('/^Usage: Net::Pcap::lookupdev(err)/', 'calling lookupdev() with no
 argument');
-e syntax OK

which is perfectly valid perl, but unlikely to do what you want.

I love it when other people answer the bug reports first :-) Thanks.

Sébastien - You can fix the problem by either wrapping the provisional load of T::E in a BEGIN block like this:

  BEGIN {
      eval "use Test::Exception";
      plan skip_all => "Test::Exception needed" if $@;
  }

  # ... tests that need T::E here ...

Or, alternatively, use non-prototyped calls to T::E. for example:

  dies_ok( sub { $dev = Net::Pcap::lookupdev(undef)},
'/^arg1 not a reference/', "calling lookupdev() with no reference" );

Cheers,

Adrian


Reply via email to