add begin.t from Method::Signatures
[p5sagit/Function-Parameters.git] / t / attrs.t
CommitLineData
231ddb47 1#!perl
2
3use Test::More tests => 10;
4
5use warnings FATAL => 'all';
6use strict;
7
8use Function::Parameters {
9 fun => 'function',
10 method => 'method',
11 elrond => {
12 attrs => ':lvalue',
13 },
14};
15
16is eval('use Function::Parameters { fun => { attrs => "nope" } }; 1'), undef;
17like $@, qr/nope.*attributes/;
18
19is eval('use Function::Parameters { fun => { attrs => ": in valid {" } }; 1'), undef;
20like $@, qr/in valid.*attributes/;
21
22elrond hobbard($ref) { $$ref }
23{
24 my $x = 1;
25 hobbard(\$x) = 'bling';
26 is $x, 'bling';
27
28}
29$_ = 'fool';
30chop hobbard \$_;
31is $_, 'foo';
32
33{
34 package BatCountry;
35
36 fun join($group, $peer) {
37 return "* $peer has joined $group";
38 }
39
40 ::is eval('join("left", "right")'), undef;
41 ::like $@, qr/Ambiguous.*CORE::/;
42}
43
44{
45 package CatCountry;
46
47 method join($peer) {
48 return "* $peer has joined $self->{name}";
49 }
50
51 ::is join('!', 'left', 'right'), 'left!right';
52
53 my $obj = bless {name => 'kittens'};
54 ::is $obj->join("twig"), "* twig has joined kittens";
55}