#!./perl -w
# Regression tests for attributes.pm and the C< : attrs> syntax.
BEGIN {
chdir 't' if -d 't';
}
eval $_[0];
}
eval 'sub e1 ($) : plugh ;';
eval 'sub e3 ($) : plugh(0,0 xyzzy ;';
like $@, qr/Unterminated attribute parameter in attribute list at/;
eval 'sub e4 ($) : plugh + xyzzy ;';
eval_ok 'my main $x : = 0;';
eval_ok 'my $x : = 0;';
eval_ok 'my $x ;';
eval_ok 'my ($x) : = 0;';
eval_ok 'my ($x) ;';
eval_ok 'my ($x) : ;';
eval_ok 'my ($x,$y) : = 0;';
eval_ok 'my ($x,$y) ;';
eval_ok 'my ($x,$y) : ;';
eval 'my ($x,$y) : plugh;';
# bug #16080
eval '{my $x : plugh}';
# More syntax tests from the attributes manpage
eval 'my $x : switch(10,foo(7,3)) : expensive;';
eval 'my $x : _5x5;';
eval 'my $x : switch(10,foo();';
like $@, qr/^Unterminated attribute parameter in attribute list at/;
like $@, qr/^Unterminated attribute parameter in attribute list at/;
eval 'my $x : 5x5;';
eval 'my $x : Y2::north;';
sub A::MODIFY_SCALAR_ATTRIBUTES { return }
eval 'my A $x : plugh;';
eval 'my A $x : plugh plover;';
sub X::foo { 1 }
eval 'package Z; sub Y::bar : foo';
eval 'package Z; sub Y::baz : locked {}';
sub Z::DESTROY { }
# Test ability to modify existing sub's (or XSUB's) attributes.
eval 'package A; sub X { $_[0] } sub X : lvalue';
# Above not with just 'pure' built-in attributes.
eval 'package Z; sub L { $_[0] } sub L : Z lvalue';
# Begin testing attributes that tie
{
sub DESTROY {}
sub FETCH { ${$_[0]} }
sub STORE {
::pass;
${$_[0]} = $_[1]*2;
}
}
eval_ok '
package Tloop;
for my $i (0..2) {
my $x : TieLoop = $i;
$x != $i*2 and ::is $x, $i*2;
}
';
# bug #15898
eval 'our ${""} : foo = 1';