From: Shawn M Moore Date: Sun, 9 Nov 2008 03:07:58 +0000 (+0000) Subject: API for constructing a parameter object X-Git-Tag: 0.05~107 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=f74750fb5280e1750e3226f7e31c92a7063993d1;p=gitmo%2FMooseX-Role-Parameterized.git API for constructing a parameter object --- diff --git a/lib/MooseX/Role/Parameterized/Meta/Role.pm b/lib/MooseX/Role/Parameterized/Meta/Role.pm index 0ff6186..620b843 100644 --- a/lib/MooseX/Role/Parameterized/Meta/Role.pm +++ b/lib/MooseX/Role/Parameterized/Meta/Role.pm @@ -21,6 +21,11 @@ sub add_parameter { $self->parameter_metaclass->add_attribute(@_); } +sub construct_parameters { + my $self = shift; + $self->parameter_metaclass->construct_instance(@_); +} + __PACKAGE__->meta->make_immutable; no Moose; diff --git a/t/001-parameters.t b/t/001-parameters.t index 33ce86a..4d21551 100644 --- a/t/001-parameters.t +++ b/t/001-parameters.t @@ -1,7 +1,7 @@ #!/usr/bin/env perl use strict; use warnings; -use Test::More tests => 5; +use Test::More tests => 7; use Test::Exception; use MooseX::Role::Parameterized::Parameters; @@ -35,3 +35,12 @@ my $parameter = ($parameter_metaclass->get_all_attributes)[0]; is($parameter->name, 'length', "parameter name"); ok($parameter->is_required, "parameter is required"); +throws_ok { + MyRole::LengthParameter->meta->construct_parameters; +} qr/^Attribute \(length\) is required/; + +$p = MyRole::LengthParameter->meta->construct_parameters( + length => 5, +); + +is($p->length, 5, "correct length");