make class attributes work in roles
[gitmo/MooseX-ClassAttribute.git] / lib / MooseX / ClassAttribute / Role / Meta / Attribute.pm
index c109454..be59f19 100644 (file)
@@ -5,19 +5,18 @@ use warnings;
 
 use MooseX::ClassAttribute::Meta::Method::Accessor;
 
+use namespace::autoclean;
 use Moose::Role;
 
 # This is the worst role evar! Really, this should be a subclass,
 # because it overrides a lot of behavior. However, as a subclass it
 # won't cooperate with _other_ subclasses.
 
-around 'accessor_metaclass' => sub
-{
+around 'accessor_metaclass' => sub {
     return 'MooseX::ClassAttribute::Meta::Method::Accessor';
 };
 
-around '_process_options' => sub
-{
+around '_process_options' => sub {
     my $orig    = shift;
     my $class   = shift;
     my $name    = shift;
@@ -29,8 +28,7 @@ around '_process_options' => sub
     return $class->$orig( $name, $options );
 };
 
-around attach_to_class => sub
-{
+around attach_to_class => sub {
     my $orig = shift;
     my $self = shift;
     my $meta = shift;
@@ -41,8 +39,7 @@ around attach_to_class => sub
         unless $self->is_lazy();
 };
 
-around 'detach_from_class' => sub
-{
+around 'detach_from_class' => sub {
     my $orig = shift;
     my $self = shift;
     my $meta = shift;
@@ -52,38 +49,32 @@ around 'detach_from_class' => sub
     $self->$orig($meta);
 };
 
-sub _initialize
-{
+sub _initialize {
     my $self      = shift;
     my $metaclass = shift;
 
-    if ( $self->has_default() )
-    {
+    if ( $self->has_default() ) {
         $self->set_value( undef, $self->default() );
     }
-    elsif ( $self->has_builder() )
-    {
+    elsif ( $self->has_builder() ) {
         $self->set_value( undef, $self->_call_builder( $metaclass->name() ) );
     }
 }
 
-around 'default' => sub
-{
+around 'default' => sub {
     my $orig = shift;
     my $self = shift;
 
     my $default = $self->$orig();
 
-    if ( $self->is_default_a_coderef() )
-    {
+    if ( $self->is_default_a_coderef() ) {
         return $default->( $self->associated_class() );
     }
 
     return $default;
 };
 
-around '_call_builder' => sub
-{
+around '_call_builder' => sub {
     shift;
     my $self  = shift;
     my $class = shift;
@@ -100,42 +91,40 @@ around '_call_builder' => sub
             . "'" );
 };
 
-around 'set_value' => sub
-{
+around 'set_value' => sub {
     shift;
-    my $self     = shift;
-    shift; # ignoring instance or class name
-    my $value    = shift;
+    my $self = shift;
+    shift;    # ignoring instance or class name
+    my $value = shift;
 
-    $self->associated_class()->set_class_attribute_value( $self->name() => $value );
+    $self->associated_class()
+        ->set_class_attribute_value( $self->name() => $value );
 };
 
-around 'get_value' => sub
-{
+around 'get_value' => sub {
     shift;
-    my $self  = shift;
+    my $self = shift;
 
-    return $self->associated_class()->get_class_attribute_value( $self->name() );
+    return $self->associated_class()
+        ->get_class_attribute_value( $self->name() );
 };
 
-around 'has_value' => sub
-{
+around 'has_value' => sub {
     shift;
-    my $self  = shift;
+    my $self = shift;
 
-    return $self->associated_class()->has_class_attribute_value( $self->name() );
+    return $self->associated_class()
+        ->has_class_attribute_value( $self->name() );
 };
 
-around 'clear_value' => sub
-{
+around 'clear_value' => sub {
     shift;
-    my $self  = shift;
+    my $self = shift;
 
-    return $self->associated_class()->clear_class_attribute_value( $self->name() );
+    return $self->associated_class()
+        ->clear_class_attribute_value( $self->name() );
 };
 
-no Moose::Role;
-
 1;
 
 __END__