Skip to content

Commit b98995e

Browse files
committed
Test that class handles __PACKAGE__ and sets VERSION correctly
1 parent 648986c commit b98995e

File tree

1 file changed

+30
-0
lines changed

1 file changed

+30
-0
lines changed

t/class/class.t

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,4 +40,34 @@ no warnings 'experimental::class';
4040
is(Test3::Foo->new->hello, "This", 'Class supports fully-qualified package names');
4141
}
4242

43+
# Class {BLOCK} syntax parses like package
44+
{
45+
my $result = "";
46+
eval q{
47+
$result .= "a(" . __PACKAGE__ . "/" . eval("__PACKAGE__") . ")\n";
48+
class Test4 1.23 {
49+
$result .= "b(" . __PACKAGE__ . "/" . eval("__PACKAGE__") . ")\n";
50+
}
51+
$result .= "c(" . __PACKAGE__ . "/" . eval("__PACKAGE__") . ")\n";
52+
} or die $@;
53+
is($result, "a(main/main)\nb(Test4/Test4)\nc(main/main)\n",
54+
'class sets __PACKAGE__ correctly');
55+
is($Test4::VERSION, 1.23, 'class NAME VERSION { BLOCK } sets $VERSION');
56+
}
57+
58+
# Unit class syntax parses like package
59+
{
60+
my $result = "";
61+
eval q{
62+
$result .= "a(" . __PACKAGE__ . "/" . eval("__PACKAGE__") . ")\n";
63+
class Test5 4.56;
64+
$result .= "b(" . __PACKAGE__ . "/" . eval("__PACKAGE__") . ")\n";
65+
package main;
66+
$result .= "c(" . __PACKAGE__ . "/" . eval("__PACKAGE__") . ")\n";
67+
} or die $@;
68+
is($result, "a(main/main)\nb(Test5/Test5)\nc(main/main)\n",
69+
'class sets __PACKAGE__ correctly');
70+
is($Test5::VERSION, 4.56, 'class NAME VERSION; sets $VERSION');
71+
}
72+
4373
done_testing;

0 commit comments

Comments
 (0)