Skip to content

Instantly share code, notes, and snippets.

@schwern
Created March 21, 2011 14:00
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save schwern/879481 to your computer and use it in GitHub Desktop.
Save schwern/879481 to your computer and use it in GitHub Desktop.
Method::Signatures performing the MooseX::Method::Signatures synopsis
{
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