From: Shawn M Moore Date: Sun, 9 Nov 2008 06:27:25 +0000 (+0000) Subject: "method" keyword X-Git-Tag: 0.05~90 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=209e00d2c51c3a7bfac41825dfa3de93ffdd248c;p=gitmo%2FMooseX-Role-Parameterized.git "method" keyword --- diff --git a/lib/MooseX/Role/Parameterized.pm b/lib/MooseX/Role/Parameterized.pm index d024424..cd9d732 100644 --- a/lib/MooseX/Role/Parameterized.pm +++ b/lib/MooseX/Role/Parameterized.pm @@ -9,7 +9,8 @@ use MooseX::Role::Parameterized::Meta::Role::Parameterizable; our $CURRENT_METACLASS; __PACKAGE__->setup_import_methods( - with_caller => ['parameter', 'role', 'has'], + with_caller => ['parameter', 'role', 'method'], + as_is => ['has'], ); sub parameter { @@ -53,9 +54,7 @@ sub has { confess "has must be called within the role { ... } block." unless $CURRENT_METACLASS; - my $caller = shift; - my $names = shift; - + my $names = shift; $names = [$names] if !ref($names); for my $name (@$names) { @@ -63,5 +62,22 @@ sub has { } } +sub method { + confess "method must be called within the role { ... } block." + unless $CURRENT_METACLASS; + + my $caller = shift; + my $name = shift; + my $body = shift; + + my $method = Moose::Meta::Method->wrap( + package_name => $caller, + name => $name, + body => $body, + ); + + $CURRENT_METACLASS->add_method($name => $method); +} + 1;