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