71e11ce163fb957072f1a6b8bf05129f7ebf1612
[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 Things;
26
27     use Function::Parameters qw(:strict);
28
29     my $attrs;
30     my $cb_called;
31
32     sub MODIFY_CODE_ATTRIBUTES {
33         my ($pkg, $code, @attrs) = @_;
34         $cb_called = 1;
35         $attrs = \@attrs;
36         return ();
37     }
38
39     method moo($foo, $bar) : Bar Baz(fubar) {
40     }
41
42     # Torture test for the attribute handling.
43     method foo
44     :
45     Bar
46     :Moo(:Ko{oh)
47     : Baz(fu{bar:): { return {} }
48
49     ::ok($cb_called, 'attribute handler got called');
50     ::is_deeply($attrs, [qw/Bar Moo(:Ko{oh) Baz(fu{bar:)/], '... with the right attributes');
51 }