Use Moose's new create_anon_role API
[gitmo/MooseX-Role-Parameterized.git] / lib / MooseX / Role / Parameterized / Meta / Role / Parameterized.pm
CommitLineData
8f9a5c92 1#!/usr/bin/env perl
2package MooseX::Role::Parameterized::Meta::Role::Parameterized;
3use Moose;
4extends 'Moose::Meta::Role';
5
6has parameters => (
7 is => 'rw',
8 isa => 'MooseX::Role::Parameterized::Parameters',
9 required => 1,
10);
11
caada7de 12# we override get_method_map because this is an anonymous role, there's no
13# package to check
14sub get_method_map {
15 my $self = shift;
16
17 return $self->{'methods'} ||= {};
18}
19
20# we override add_method because we don't want to install methods added through
21# this API; we just stick it in the method map
22sub add_method {
23 my ($self, $method_name, $method) = @_;
24 (defined $method_name && $method_name)
25 || Moose->throw_error("You must define a method name");
26
27 if (!blessed($method)) {
28 Moose->throw_error("You must pass a blessed method to add_method");
29 }
30
31 $self->get_method_map->{$method_name} = $method;
32}
33
8f9a5c92 34__PACKAGE__->meta->make_immutable;
00258a2d 35no Moose;
8f9a5c92 36
371;
38