From: Lukas Mai Date: Tue, 19 Jun 2012 03:40:16 +0000 (+0200) Subject: test 'attrs' / ':method' X-Git-Tag: v0.06~6^2 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=p5sagit%2FFunction-Parameters.git;a=commitdiff_plain;h=231ddb47b1dd3cd1d9d7cf9148a6c256ff6951ec test 'attrs' / ':method' --- diff --git a/t/attrs.t b/t/attrs.t new file mode 100644 index 0000000..437d457 --- /dev/null +++ b/t/attrs.t @@ -0,0 +1,55 @@ +#!perl + +use Test::More tests => 10; + +use warnings FATAL => 'all'; +use strict; + +use Function::Parameters { + fun => 'function', + method => 'method', + elrond => { + attrs => ':lvalue', + }, +}; + +is eval('use Function::Parameters { fun => { attrs => "nope" } }; 1'), undef; +like $@, qr/nope.*attributes/; + +is eval('use Function::Parameters { fun => { attrs => ": in valid {" } }; 1'), undef; +like $@, qr/in valid.*attributes/; + +elrond hobbard($ref) { $$ref } +{ + my $x = 1; + hobbard(\$x) = 'bling'; + is $x, 'bling'; + +} +$_ = 'fool'; +chop hobbard \$_; +is $_, 'foo'; + +{ + package BatCountry; + + fun join($group, $peer) { + return "* $peer has joined $group"; + } + + ::is eval('join("left", "right")'), undef; + ::like $@, qr/Ambiguous.*CORE::/; +} + +{ + package CatCountry; + + method join($peer) { + return "* $peer has joined $self->{name}"; + } + + ::is join('!', 'left', 'right'), 'left!right'; + + my $obj = bless {name => 'kittens'}; + ::is $obj->join("twig"), "* twig has joined kittens"; +}