From: Shawn M Moore Date: Sun, 18 Jan 2009 02:51:24 +0000 (+0000) Subject: Default parameters to read-only X-Git-Tag: 0.05~16 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=96bc1fffc9f715f21d4189b45f8461bb26a6e2cd;p=gitmo%2FMooseX-Role-Parameterized.git Default parameters to read-only --- diff --git a/lib/MooseX/Role/Parameterized/Meta/Parameter.pm b/lib/MooseX/Role/Parameterized/Meta/Parameter.pm index 1ae50b7..a37f643 100644 --- a/lib/MooseX/Role/Parameterized/Meta/Parameter.pm +++ b/lib/MooseX/Role/Parameterized/Meta/Parameter.pm @@ -2,6 +2,20 @@ package MooseX::Role::Parameterized::Meta::Parameter; use Moose; extends 'Moose::Meta::Attribute'; +# This doesn't actually do anything because _process_options does not consult +# the default value of "is". hrm. +has '+is' => ( + default => 'ro', +); + +around _process_options => sub { + my $orig = shift; + my ($class, $name, $options) = @_; + + $options->{is} ||= 'ro'; + + $orig->(@_); +}; __PACKAGE__->meta->make_immutable( inline_constructor => 1, diff --git a/t/001-parameters.t b/t/001-parameters.t index 85d9ae4..6d208f1 100644 --- a/t/001-parameters.t +++ b/t/001-parameters.t @@ -22,7 +22,6 @@ do { use MooseX::Role::Parameterized; parameter length => ( - is => 'ro', isa => 'Int', required => 1, ); diff --git a/t/002-role-block.t b/t/002-role-block.t index fab2425..b30f256 100644 --- a/t/002-role-block.t +++ b/t/002-role-block.t @@ -20,7 +20,6 @@ do { ($parameters, %args) = @_; has age => ( - is => 'ro', default => $parameters->default_age, ); diff --git a/t/003-apply.t b/t/003-apply.t index 925dc2b..43ae9a9 100644 --- a/t/003-apply.t +++ b/t/003-apply.t @@ -10,20 +10,17 @@ do { use Moose::Util::TypeConstraints; parameter format => ( - is => 'ro', isa => (enum ['Dumper', 'Storable']), required => 1, ); parameter freeze_method => ( - is => 'ro', isa => 'Str', lazy => 1, default => sub { "freeze_" . shift->format }, ); parameter thaw_method => ( - is => 'ro', isa => 'Str', lazy => 1, default => sub { "thaw_" . shift->format }, diff --git a/t/004-with.t b/t/004-with.t index 9bb650b..7980e49 100644 --- a/t/004-with.t +++ b/t/004-with.t @@ -22,7 +22,6 @@ do { use MooseX::Role::Parameterized; parameter slot => ( - is => 'ro', isa => 'Str', required => 1, ); diff --git a/t/005-with-parameterized.t b/t/005-with-parameterized.t index 415cd8f..5d5e34c 100644 --- a/t/005-with-parameterized.t +++ b/t/005-with-parameterized.t @@ -31,7 +31,6 @@ do { use MooseX::Role::Parameterized; parameter slot => ( - is => 'ro', isa => 'Str', required => 1, ); diff --git a/t/008-method-modifers.t b/t/008-method-modifers.t index 2380db4..2c1d515 100644 --- a/t/008-method-modifers.t +++ b/t/008-method-modifers.t @@ -10,7 +10,6 @@ do { use MooseX::Role::Parameterized; parameter method => ( - is => 'ro', isa => 'Str', required => 1, ); diff --git a/t/014-compose-parameterizable.t b/t/014-compose-parameterizable.t index 4423fe4..24cccf1 100644 --- a/t/014-compose-parameterizable.t +++ b/t/014-compose-parameterizable.t @@ -8,7 +8,6 @@ do { use MooseX::Role::Parameterized; parameter attribute => ( - is => 'ro', isa => 'Str', );