From: Shawn M Moore Date: Fri, 10 Jul 2009 05:47:24 +0000 (-0400) Subject: IsRO trait X-Git-Tag: 0.01~14 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=0413c7e1d98a6cfc672992b1a44a9dc2b2cbda35;p=gitmo%2FMooseX-HasDefaults.git IsRO trait --- 0413c7e1d98a6cfc672992b1a44a9dc2b2cbda35 diff --git a/lib/MooseX/IsDefaults/Meta/IsRO.pm b/lib/MooseX/IsDefaults/Meta/IsRO.pm new file mode 100644 index 0000000..da40491 --- /dev/null +++ b/lib/MooseX/IsDefaults/Meta/IsRO.pm @@ -0,0 +1,25 @@ +package MooseX::IsDefaults::Meta::IsRO; +use Moose::Role; + +# This does not actually do anything but lie less in the attribute's metadata. +has '+is' => ( + default => 'ro', +); + +around _process_options => sub { + my $orig = shift; + my (undef, undef, $options) = @_; + + if (!exists($options->{is})) { + $options->{is} = 'ro'; + } + # They want no accessor, but Moose doesn't like "is => undef" + elsif (!defined($options->{is})) { + delete $options->{is}; + } + + $orig->(@_); +}; + +1; +