12 tie my $c => 'Tie::Monitor';
15 my($ok, $got, $exp, $rexp, $wexp) = @_;
16 my($rgot, $wgot) = (tied $c)->init(0);
17 print $ok ? "ok $t\n" : "# expected $exp, got $got\nnot ok $t\n";
19 if ($rexp == $rgot && $wexp == $wgot) {
22 print "# read $rgot expecting $rexp\n" if $rgot != $rexp;
23 print "# wrote $wgot expecting $wexp\n" if $wgot != $wexp;
29 sub ok_undef { ok(!defined($_[0]), shift, "undef", @_) }
30 sub ok_numeric { ok($_[0] == $_[1], @_) }
31 sub ok_string { ok($_[0] eq $_[1], @_) }
35 ok_numeric($r = $c + 0, 0, 1, 0);
36 ok_string($r = "$c", '0', 1, 0);
39 ok_string($c . 'x', '0x', 1, 0);
40 ok_string('x' . $c, 'x0', 1, 0);
42 ok_string($s, '00', 2, 0);
45 ok_string($s, 'xy', 1, 1);
47 ok_string($s, '0x', 2, 1);
49 ok_string($s, 'x0', 2, 1);
51 ok_string($s, '00', 3, 1);
53 # adapted from Tie::Counter by Abigail
57 my($class, $value) = @_;
68 $self->{values}[$#{ $self->{values} }];
72 my($self, $value) = @_;
74 push @{ $self->{values} }, $value;
79 my @results = ($self->{read}, $self->{write});
80 $self->{read} = $self->{write} = 0;
81 $self->{values} = [ 0 ];