2 use warnings FATAL => 'all';
4 use Test::More 'no_plan';
8 use Function::Parameters qw(:strict);
11 return bless {%args}, $self;
14 method set ($key, $val) {
15 return $self->{$key} = $val;
26 method empty_proto() {
34 method caller($height = 0) {
35 return (CORE::caller($height))[0..2];
39 method warn($foo = undef) {
41 local $SIG{__WARN__} = sub { $warning = join '', @_; };
42 CORE::warn "Testing warn";
47 # Method with the same name as a loaded class.
53 my $obj = Foo->new( foo => 42, bar => 23 );
55 is $obj->get("foo"), 42;
56 is $obj->get("bar"), 23;
59 is $obj->get("foo"), 99;
61 is_deeply [$obj->no_proto], [$obj];
62 for my $method (qw(empty_proto)) {
63 is_deeply [$obj->$method], [$obj];
64 ok !eval { $obj->$method(23); 1 };
65 like $@, qr{\QToo many arguments};
68 is_deeply [$obj->echo(1,2,3)], [$obj,1,2,3], "echo";
70 is_deeply [$obj->caller], [__PACKAGE__, $0, __LINE__], 'caller works';
72 is $obj->warn, "Testing warn at $0 line 42.\n";
74 is eval { $obj->strict }, 42;