From: Shawn M Moore Date: Fri, 10 Jul 2009 06:00:32 +0000 (-0400) Subject: RW X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=253cd18c48452459130a9a23fdc4026b38c73216;p=gitmo%2FMooseX-IsDefaults.git RW --- diff --git a/lib/MooseX/IsDefaults/Meta/IsRW.pm b/lib/MooseX/IsDefaults/Meta/IsRW.pm new file mode 100644 index 0000000..ce692e6 --- /dev/null +++ b/lib/MooseX/IsDefaults/Meta/IsRW.pm @@ -0,0 +1,25 @@ +package MooseX::IsDefaults::Meta::IsRW; +use Moose::Role; + +# This does not actually do anything but lie less in the attribute's metadata. +has '+is' => ( + default => 'rw', +); + +around _process_options => sub { + my $orig = shift; + my (undef, undef, $options) = @_; + + if (!exists($options->{is})) { + $options->{is} = 'rw'; + } + # They want no accessor, but Moose doesn't like "is => undef" + elsif (!defined($options->{is})) { + delete $options->{is}; + } + + $orig->(@_); +}; + +1; + diff --git a/lib/MooseX/IsDefaults/RW.pm b/lib/MooseX/IsDefaults/RW.pm new file mode 100644 index 0000000..515da3c --- /dev/null +++ b/lib/MooseX/IsDefaults/RW.pm @@ -0,0 +1,25 @@ +package MooseX::IsDefaults::RW; +use Moose (); +use Moose::Exporter; +use Moose::Util::MetaRole; + +use MooseX::IsDefaults::Meta::IsRW; + +Moose::Exporter->setup_import_methods(also => 'Moose'); + +sub init_meta { + shift; + my %options = @_; + + Moose->init_meta(%options); + + Moose::Util::MetaRole::apply_metaclass_roles( + for_class => $options{for_class}, + attribute_metaclass_roles => ['MooseX::IsDefaults::Meta::IsRW'], + ); + + return $options{for_class}->meta; +} + +1; +