784c07524590ecdc02a3fb13c1e2cf6b59778f00
[p5sagit/Function-Parameters.git] / t / foreign / Method-Signatures / attributes.t
1 #!perl
2 use strict;
3 use warnings FATAL => 'all';
4
5 use Test::More 'no_plan';
6
7 use attributes;
8
9 {
10     package Stuff;
11
12     use Test::More;
13     use Function::Parameters qw(:strict);
14
15     method echo($arg) {
16         return $arg;
17     }
18
19     is( Stuff->echo(42), 42 );
20     is_deeply( [attributes::get \&echo], ['method'] );
21 }
22
23
24 {
25     package Foo;
26
27     use Test::More;
28     use Function::Parameters qw(:strict);
29
30     my $code = fun () : method {};
31     is_deeply( [attributes::get $code], ['method'] );
32 }
33
34
35 {
36     package Things;
37
38     use Function::Parameters qw(:strict);
39
40     my $attrs;
41     my $cb_called;
42
43     sub MODIFY_CODE_ATTRIBUTES {
44         my ($pkg, $code, @attrs) = @_;
45         $cb_called = 1;
46         $attrs = \@attrs;
47         return ();
48     }
49
50     method moo($foo, $bar) : Bar Baz(fubar) {
51     }
52
53     # Torture test for the attribute handling.
54     method foo
55     :
56     Bar
57     :Moo(:Ko{oh)
58     : Baz(fu{bar:): { return {} }
59
60     ::ok($cb_called, 'attribute handler got called');
61     ::is_deeply($attrs, [qw/Bar Moo(:Ko{oh) Baz(fu{bar:)/], '... with the right attributes');
62 }