In the general case a closure is the "right" way to do "it". However, closures,
unlike local and regular subroutines, have some complexity at compile time,
which means that using closures in test.pl runs the risk of closure bugs
causing spurious hard to diagnose collateral damage to other tests. local is
already in use, and "has" to work for capturing warnings, as $SIG{__WARN__} is
localised already.
_ok( !$diag, _where(), $name );
}
_ok( !$diag, _where(), $name );
}
+# Purposefully avoiding a closure.
+sub __capture {
+ push @::__capture, join "", @_;
+}
+
sub capture_warnings {
my $code = shift;
sub capture_warnings {
my $code = shift;
- my @w;
- local $SIG {__WARN__} = sub {push @w, join "", @_};
+ local @::__capture;
+ local $SIG {__WARN__} = \&__capture;
}
# This will generate a variable number of tests.
}
# This will generate a variable number of tests.