From: Shawn M Moore Date: Sun, 9 Nov 2008 06:27:07 +0000 (+0000) Subject: Begin supporting methods by defining get_method_map and add_method which don't poke... X-Git-Tag: 0.05~91 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=caada7de0ae119b3179bb1afdf4f1b38d6450206;p=gitmo%2FMooseX-Role-Parameterized.git Begin supporting methods by defining get_method_map and add_method which don't poke at packages (should probably port these back up to Moose and CMOP for anon classes) --- diff --git a/lib/MooseX/Role/Parameterized/Meta/Role/Parameterized.pm b/lib/MooseX/Role/Parameterized/Meta/Role/Parameterized.pm index bed9b3a..56eae06 100644 --- a/lib/MooseX/Role/Parameterized/Meta/Role/Parameterized.pm +++ b/lib/MooseX/Role/Parameterized/Meta/Role/Parameterized.pm @@ -9,6 +9,28 @@ has parameters => ( required => 1, ); +# we override get_method_map because this is an anonymous role, there's no +# package to check +sub get_method_map { + my $self = shift; + + return $self->{'methods'} ||= {}; +} + +# we override add_method because we don't want to install methods added through +# this API; we just stick it in the method map +sub add_method { + my ($self, $method_name, $method) = @_; + (defined $method_name && $method_name) + || Moose->throw_error("You must define a method name"); + + if (!blessed($method)) { + Moose->throw_error("You must pass a blessed method to add_method"); + } + + $self->get_method_map->{$method_name} = $method; +} + __PACKAGE__->meta->make_immutable; no Moose;