Created
March 21, 2011 14:00
-
-
Save schwern/879481 to your computer and use it in GitHub Desktop.
Method::Signatures performing the MooseX::Method::Signatures synopsis
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
{ | |
package Foo; | |
# use Mouse; | |
use Moose; | |
# use MooseX::Method::Signatures; | |
use Method::Signatures; | |
method say (Str $msg) {} | |
method morning (Str $name) { | |
$self->say("Good morning ${name}!"); | |
} | |
method hello (Str :$who, Int :$age) { | |
$self->say("Hello ${who}, I am ${age} years old!"); | |
} | |
method greet (Str $name, Bool :$excited = 0) { | |
if ($excited) { | |
$self->say("GREETINGS ${name}!"); | |
} else { | |
$self->say("Hi ${name}!"); | |
} | |
} | |
} | |
my $foo = Foo->new; | |
sub test { | |
$foo->morning('Resi'); # This works. | |
$foo->hello(who => 'world', age => 42); # This too. | |
$foo->greet('Resi', excited => 1); # And this as well. | |
eval { | |
$foo->hello(who => 'world', age => 'fortytwo'); # This doesn't. | |
}; | |
eval { | |
$foo->morning; # Won't work. | |
}; | |
eval { | |
$foo->greet; # Will fail. | |
}; | |
} | |
test() for 1..20000; |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment