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 like
13 # MX::AttributeHelpers::Base.
15 around 'accessor_metaclass' => sub
17 return 'MooseX::ClassAttribute::Meta::Method::Accessor';
20 around '_process_options' => sub
27 confess 'A class attribute cannot be required'
28 if $options->{required};
30 return $class->$orig( $name, $options );
33 around attach_to_class => sub
41 $self->_initialize($meta)
42 unless $self->is_lazy();
45 around 'detach_from_class' => sub
51 $self->clear_value($meta);
59 my $metaclass = shift;
61 if ( $self->has_default() )
63 $self->set_value( undef, $self->default() );
65 elsif ( $self->has_builder() )
67 $self->set_value( undef, $self->_call_builder( $metaclass->name() ) );
71 around 'default' => sub
76 my $default = $self->$orig();
78 if ( $self->is_default_a_coderef() )
80 return $default->( $self->associated_class() );
86 around '_call_builder' => sub
92 my $builder = $self->builder();
94 return $class->$builder()
95 if $class->can( $self->builder );
97 confess( "$class does not support builder method '"
104 around 'set_value' => sub
108 shift; # ignoring instance or class name
111 $self->associated_class()->set_class_attribute_value( $self->name() => $value );
114 around 'get_value' => sub
119 return $self->associated_class()->get_class_attribute_value( $self->name() );
122 around 'has_value' => sub
127 return $self->associated_class()->has_class_attribute_value( $self->name() );
130 around 'clear_value' => sub
135 return $self->associated_class()->clear_class_attribute_value( $self->name() );
148 MooseX::ClassAttribute::Role::Meta::Attribute - An attribute role for classes with class attributes
152 This role modifies the behavior of class attributes in various
153 ways. It really should be a subclass of C<Moose::Meta::Attribute>, but
154 if it were then it couldn't be combined with other attribute
155 metaclasses, like C<MooseX::AttributeHelpers>.
157 There are no new public methods implemented by this role. All it does
158 is change the behavior of a number of existing methods.
162 Dave Rolsky, C<< <autarch@urth.org> >>
166 See L<MooseX::ClassAttribute> for details.
168 =head1 COPYRIGHT & LICENSE
170 Copyright 2007-2008 Dave Rolsky, All Rights Reserved.
172 This program is free software; you can redistribute it and/or modify
173 it under the same terms as Perl itself.