1 package MooseX::ClassAttribute::Role::Meta::Attribute;
6 use MooseX::ClassAttribute::Meta::Method::Accessor;
10 # This is the worst role evar! Really, this should be a subclass,
11 # because it overrides a lot of behavior. However, as a subclass it
12 # won't cooperate with _other_ subclasses.
14 around 'accessor_metaclass' => sub
16 return 'MooseX::ClassAttribute::Meta::Method::Accessor';
19 around '_process_options' => sub
26 confess 'A class attribute cannot be required'
27 if $options->{required};
29 return $class->$orig( $name, $options );
32 around attach_to_class => sub
40 $self->_initialize($meta)
41 unless $self->is_lazy();
44 around 'detach_from_class' => sub
50 $self->clear_value($meta);
58 my $metaclass = shift;
60 if ( $self->has_default() )
62 $self->set_value( undef, $self->default() );
64 elsif ( $self->has_builder() )
66 $self->set_value( undef, $self->_call_builder( $metaclass->name() ) );
70 around 'default' => sub
75 my $default = $self->$orig();
77 if ( $self->is_default_a_coderef() )
79 return $default->( $self->associated_class() );
85 around '_call_builder' => sub
91 my $builder = $self->builder();
93 return $class->$builder()
94 if $class->can( $self->builder );
96 confess( "$class does not support builder method '"
103 around 'set_value' => sub
107 shift; # ignoring instance or class name
110 $self->associated_class()->set_class_attribute_value( $self->name() => $value );
113 around 'get_value' => sub
118 return $self->associated_class()->get_class_attribute_value( $self->name() );
121 around 'has_value' => sub
126 return $self->associated_class()->has_class_attribute_value( $self->name() );
129 around 'clear_value' => sub
134 return $self->associated_class()->clear_class_attribute_value( $self->name() );
147 MooseX::ClassAttribute::Role::Meta::Attribute - An attribute role for classes with class attributes
151 This role modifies the behavior of class attributes in various
152 ways. It really should be a subclass of C<Moose::Meta::Attribute>, but
153 if it were then it couldn't be combined with other attribute
154 metaclasses, like C<MooseX::AttributeHelpers>.
156 There are no new public methods implemented by this role. All it does
157 is change the behavior of a number of existing methods.
161 Dave Rolsky, C<< <autarch@urth.org> >>
165 See L<MooseX::ClassAttribute> for details.
167 =head1 COPYRIGHT & LICENSE
169 Copyright 2007-2008 Dave Rolsky, All Rights Reserved.
171 This program is free software; you can redistribute it and/or modify
172 it under the same terms as Perl itself.