Skip to content

Commit

Permalink
Implement $foo<bar> subscripting form
Browse files Browse the repository at this point in the history
  • Loading branch information
sorear committed Aug 7, 2010
1 parent 8a0b8ba commit 0e24f40
Show file tree
Hide file tree
Showing 2 changed files with 21 additions and 9 deletions.
6 changes: 6 additions & 0 deletions Niecza/Actions.pm
Expand Up @@ -610,6 +610,12 @@ sub postcircumfix__S_Cur_Ly { my ($cl, $M) = @_;
$M->{_ast} = { postcircumfix => '{ }',
args => $cl->semilist_to_args($M->{semilist}) };
}
sub postcircumfix__S_Lt_Gt { my ($cl, $M) = @_;
$cl->circumfix__S_Lt_Gt($M); #XXX
delete $M->{qpvalue};
$M->{_ast} = { postcircumfix => '{ }',
args => [ $M->{_ast} ] };
}

sub postop { my ($cl, $M) = @_;
$M->{_ast} = $M->{postcircumfix} ? $M->{postcircumfix}{_ast} :
Expand Down
24 changes: 15 additions & 9 deletions test2.pl
Expand Up @@ -42,17 +42,23 @@ sub postcircumfix:<{ }> is rawcall {
});
}

{
sub postcircumfix:<{ }> { @_.join("|") }
is 1<2 3>, '1|2|3', "angle bracket postcircumfix works";
}

my $foo;
ok !($foo{'x'}.defined), "fetch from hash, no value";
ok !($foo<x>.defined), "fetch from hash, no value";
ok !($foo.defined), "no autoviv for rvalue";
$foo{'x'} = 'foo';
is $foo{'x'}, 'foo', "values are retained";
ok !($foo{'y'}.defined), "no cross-slot leakage";
$foo<x> = 'foo';
is $foo<x>, 'foo', "values are retained";
ok !($foo<y>.defined), "no cross-slot leakage";
ok $foo ~~ Hash, "foo isa hash now";
$foo{'z'}{'a'} = 'pie';
is $foo{'z'}{'a'}, 'pie', "can autoviv deeply";
$foo{'y'}[2] = 'zed';
is $foo{'y'}[2], 'zed', "can mix array and hash viv";

$foo<z><a> = 'pie';
is $foo<z><a>, 'pie', "can autoviv deeply";
$foo<y>[2] = 'zed';
is $foo<y>[2], 'zed', "can mix array and hash viv";
$foo<12> = 'fry';
is $foo{12}, 'fry', "keys are strings";

done-testing;

0 comments on commit 0e24f40

Please sign in to comment.