My patchwork readings lead me to believe I could test Perl 6's
tie-like feature with something like the below code, which I don't
expect to even compile, what with '???' in places. My question is:
am I on the right track? Obviously there are details I haven't nailed
down, and any guidance would be appreciated.
Thanks!
# Scalar is Any does Container does Order
class ScalarTester is Scalar {
has @.log;
multi STORE ( Any $thing ) {
@.log.push( STORE => $thing );
nextsame;
}
multi FETCH() {
@.log.push( 'FETCH' );
nextsame;
}
multi TEMP() {
@.log.push( 'TEMP' );
nextsame;
}
multi infix:<=> ( ??? ) {
@.log.push( 'infix:<=>' );
nextsame;
}
multi infix:<:=> ( ??? ) {
@.log.push( 'infix:<:=>' );
nextsame;
}
multi infix:<::=> ( ??? ) {
@.log.push( 'infix:<::=>' );
nextsame;
}
multi infix:<=:=> ( ??? ) {
@.log.push( 'infix:<=:=>' );
nextsame;
}
# since Scalar does Order, there are ~20 other methods to test.
}
my $t is ScalarTester;
is $t.log, (), 'log is empty';
lives_ok { $t = 'bughunt' }, 'can assign to test scalar';
is $t.log, ( 'STORE' => 'bughunt' ), 'log reflects assignment';
lives_ok { my $discard = $t }, 'can access test scalar';
is $t.log, ( 'STORE' => 'bughunt', 'FETCH' ), 'log reflects access';