From: Shawn M Moore Date: Sun, 9 Nov 2008 05:11:09 +0000 (+0000) Subject: Let the parameter keyword take an arrayref of names X-Git-Tag: 0.05~99 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=bd3dd853b42e6c81f85dccf242f8f87a0897d24f;p=gitmo%2FMooseX-Role-Parameterized.git Let the parameter keyword take an arrayref of names --- diff --git a/lib/MooseX/Role/Parameterized.pm b/lib/MooseX/Role/Parameterized.pm index f1fc28e..3f23a53 100644 --- a/lib/MooseX/Role/Parameterized.pm +++ b/lib/MooseX/Role/Parameterized.pm @@ -14,7 +14,13 @@ __PACKAGE__->setup_import_methods( sub parameter { my $caller = shift; - $caller->meta->add_parameter(@_); + my $names = shift; + + $names = [$names] if !ref($names); + + for my $name (@$names) { + $caller->meta->add_parameter($name, @_); + } } sub role { diff --git a/t/001-parameters.t b/t/001-parameters.t index a5ca29f..743bc72 100644 --- a/t/001-parameters.t +++ b/t/001-parameters.t @@ -49,16 +49,18 @@ do { package MyRole::LengthParameter; use MooseX::Role::Parameterized; - parameter name => ( + parameter ['first_name', 'last_name'] => ( is => 'rw', isa => 'Str', ); }; $parameter_metaclass = MyRole::LengthParameter->meta->parameter_metaclass; -is($parameter_metaclass->get_all_attributes, 2, "two parameters"); +is($parameter_metaclass->get_all_attributes, 3, "three parameters"); -my $name_param = $parameter_metaclass->get_attribute('name'); -is($name_param->type_constraint, 'Str', 'parameter type constraint'); -ok(!$name_param->is_required, 'name is optional'); +for my $param_name ('first_name', 'last_name') { + my $param = $parameter_metaclass->get_attribute($param_name); + is($param->type_constraint, 'Str', "$param_name type constraint"); + ok(!$param->is_required, "$param_name is optional"); +}