use base qw/Exporter/;
-our @EXPORT = qw/init check/;
+our @EXPORT = qw/init_watcher watch/;
sub _types {
my $t = shift;
our ($wiz, $prefix, %mg);
-sub init ($;$) {
+sub init_watcher ($;$) {
croak 'can\'t initialize twice' if defined $wiz;
my $types = _types shift;
$prefix = (defined) ? "$_: " : '' for shift;
return $wiz;
}
-sub check (&;$$) {
+sub watch (&;$$) {
my $code = shift;
my $exp = _types shift;
my $desc = shift;
+ my $want = wantarray;
+ my @ret;
local %mg = ();
local $Test::Builder::Level = ($Test::Builder::Level || 0) + 1;
- my @ret = eval { $code->() };
+ if (defined $want and not $want) { # scalar context
+ $ret[0] = eval { $code->() };
+ } else {
+ @ret = eval { $code->() };
+ }
is $@, '', $prefix . $desc . ' doesn\'t croak';
is_deeply \%mg, $exp, $prefix . $desc . ' triggers magic correctly';
- return @ret;
+ return $want ? @ret : $ret[0];
}
our $mg_end;