update foreign tests
[p5sagit/Function-Parameters.git] / t / foreign / Method-Signatures / invocant.t
1 #!perl
2
3 # Test that you can change the invocant.
4
5 use strict;
6 use warnings FATAL => 'all';
7
8 use Test::More
9     eval { require Moose }
10     ? (tests => 6)
11     : (skip_all => "Moose required for testing types")
12 ;
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
42         method no_invocant_class_type(Foo::Bar $arg) {
43             $self->bar($arg);
44         }
45
46         method no_invocant_named_param(Foo :$arg) {
47             $self->bar($arg);
48         }
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' );
71 is( $stuff->no_invocant_named_param(arg => Foo->new),  'Foo' );