1 package Variable::Magic::TestValue;
8 use Variable::Magic qw<wizard cast>;
10 use base qw<Exporter>;
12 our @EXPORT = qw<init_value value>;
14 our ($exp, $prefix, $desc);
18 return if $data->{guard};
19 local $data->{guard} = 1;
20 local $Test::Builder::Level = ($Test::Builder::Level || 0) + 3;
21 is_deeply $_[0], $exp, $desc;
25 sub init_value (\[$@%&*]$;$) {
27 $prefix = (defined) ? "$_: " : '' for $_[2];
28 my $wiz = eval "wizard data => sub { +{ guard => 0 } }, $type => \\&value_cb";
29 is $@, '', $prefix . 'wizard() doesn\'t croak';
30 eval { &cast($_[0], $wiz, $prefix) };
31 is $@, '', $prefix . 'cast() doesn\'t croak';
36 my ($code, $_exp, $_desc) = @_;
38 $_desc = 'value' unless defined $desc;
39 $_desc = $prefix . $_desc;
42 local $Test::Builder::Level = ($Test::Builder::Level || 0) + 1;
45 if (defined $want and not $want) { # scalar context
46 $ret[0] = eval { $code->() };
48 @ret = eval { $code->() };
50 is $@, '', $desc . ' doesn\'t croak';
52 return $want ? @ret : $ret[0];