| 1 | package MooseX::Meta::Attribute::Lvalue; | ||
| 2 | |||
| 3 | |||
| 4 | our $VERSION = '0.05'; | ||
| 5 | our $AUTHORITY = 'cpan:CTBROWN'; | ||
| 6 | |||
| 7 | use Moose::Role; | ||
| 8 | |||
| 9 | sub BUILD { } # This is a dummy version to support after. | ||
| 10 | # It gets overwritten if the major class has | ||
| 11 | # a BUILD method | ||
| 12 | |||
| 13 | after BUILD => sub { | ||
| 14 | $_[0]->_install_lvalue_writer; | ||
| 15 | }; | ||
| 16 | |||
| 17 | |||
| 18 | # INSTALLS a _lvalue_writer for the attribute all lvalue attributes | ||
| 19 | # This is done after the build statement | ||
| 20 | sub _install_lvalue_writer { | ||
| 21 | |||
| 22 | my ( $self, @args ) = @_; | ||
| 23 | |||
| 24 | my %attributes = %{ $self->meta->get_attribute_map }; | ||
| 25 | while ( my ($name, $attribute) = each %attributes) { | ||
| 26 | |||
| 27 | if ( | ||
| 28 | $attribute->does( 'MooseX::Meta::Attribute::Trait::Lvalue' ) | ||
| 29 | # removed in version 0.04 | ||
| 30 | # and $attribute->{ lvalue } | ||
| 31 | and $attribute->_is_metadata eq 'rw' | ||
| 32 | ) { | ||
| 33 | |||
| 34 | $self->meta->add_method( | ||
| 35 | $name, | ||
| 36 | sub :lvalue { | ||
| 37 | $_[0]->{ $name } | ||
| 38 | } | ||
| 39 | ); | ||
| 40 | |||
| 41 | } | ||
| 42 | |||
| 43 | } | ||
| 44 | } | ||
| 45 | |||
| 46 | |||
| 47 | |||
| 48 | package MooseX::Meta::Attribute::Trait::Lvalue; | ||
| 49 | |||
| 50 | use Moose::Role; | ||
| 51 | |||
| 52 | has 'lvalue' => ( | ||
| 53 | is => 'rw' , | ||
| 54 | isa => 'Bool' , | ||
| 55 | predicate => 'has_lvalue' , | ||
| 56 | ); | ||
| 57 | |||
| 58 | |||
| 59 | package Moose::Meta::Attribute::Custom::Trait::Lvalue; | ||
| 60 | |||
| 61 | sub register_implementation { | ||
| 62 | 'MooseX::Meta::Attribute::Trait::Lvalue' ; | ||
| 63 | }; | ||
| 64 | |||
| 65 | |||
| 66 | 1; | ||
| 67 | |||
| 68 | __END__ |