Commit | Line | Data |
633048d5 |
1 | #!perl |
2 | |
3 | # Test that you can change the invocant. |
4 | |
5 | use strict; |
6 | use warnings FATAL => 'all'; |
7 | |
1a52f2db |
8 | use Test::More |
9 | eval { require Moose } |
10 | ? (tests => 6) |
11 | : (skip_all => "Moose required for testing types") |
12 | ; |
633048d5 |
13 | |
14 | our $skip_no_invocants; |
15 | |
16 | { |
17 | package Stuff; |
18 | |
19 | use Test::More; |
20 | use Function::Parameters qw(:strict); |
21 | |
22 | sub new { bless {}, __PACKAGE__ } |
23 | |
24 | method bar($arg) { |
25 | return ref $arg || $arg; |
26 | } |
27 | |
28 | method invocant($class:) { |
29 | $class->bar(0); |
30 | } |
31 | |
32 | method with_arg($class: $arg) { |
33 | $class->bar($arg); |
34 | } |
35 | |
36 | method without_space($class:$arg) { |
37 | $class->bar($arg); |
38 | } |
39 | |
40 | eval q{ |
41 | |
1a52f2db |
42 | method no_invocant_class_type(Foo::Bar $arg) { |
633048d5 |
43 | $self->bar($arg); |
44 | } |
45 | |
1a52f2db |
46 | method no_invocant_named_param(Foo :$arg) { |
98e6239b |
47 | $self->bar($arg); |
48 | } |
633048d5 |
49 | |
50 | }; |
51 | is $@, '', 'compiles without invocant'; |
52 | } |
53 | |
54 | { |
55 | package Foo; |
56 | sub new { bless {}, __PACKAGE__ } |
57 | } |
58 | |
59 | { |
60 | package Foo::Bar; |
61 | sub new { bless {}, __PACKAGE__ } |
62 | } |
63 | |
64 | |
65 | is( Stuff->invocant, 0 ); |
66 | is( Stuff->with_arg(42), 42 ); |
67 | is( Stuff->without_space(42), 42 ); |
68 | |
69 | my $stuff = Stuff->new; |
70 | is( $stuff->no_invocant_class_type(Foo::Bar->new), 'Foo::Bar' ); |
98e6239b |
71 | is( $stuff->no_invocant_named_param(arg => Foo->new), 'Foo' ); |