From: Dave Rolsky Date: Thu, 28 Mar 2013 16:07:44 +0000 (-0500) Subject: Tidy all code X-Git-Tag: v0.27~5 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMooseX-ClassAttribute.git;a=commitdiff_plain;h=3e9e5aef1aa4a05b64d7beddc49121775bec5320 Tidy all code --- diff --git a/lib/MooseX/ClassAttribute/Trait/Application/ToClass.pm b/lib/MooseX/ClassAttribute/Trait/Application/ToClass.pm index 12a9f29..365813d 100644 --- a/lib/MooseX/ClassAttribute/Trait/Application/ToClass.pm +++ b/lib/MooseX/ClassAttribute/Trait/Application/ToClass.pm @@ -9,7 +9,7 @@ use Moose::Role; with 'MooseX::ClassAttribute::Trait::Application'; around apply => sub { - my $orig = shift; + my $orig = shift; my $self = shift; my $role = shift; my $class = shift; diff --git a/lib/MooseX/ClassAttribute/Trait/Attribute.pm b/lib/MooseX/ClassAttribute/Trait/Attribute.pm index 5519c54..efd923c 100644 --- a/lib/MooseX/ClassAttribute/Trait/Attribute.pm +++ b/lib/MooseX/ClassAttribute/Trait/Attribute.pm @@ -42,8 +42,10 @@ sub _initialize { my $metaclass = shift; if ( $self->has_default() ) { - $self->set_value( undef, - $self->default( $self->associated_class() ) ); + $self->set_value( + undef, + $self->default( $self->associated_class() ) + ); } elsif ( $self->has_builder() ) { $self->set_value( undef, $self->_call_builder( $metaclass->name() ) ); @@ -134,8 +136,10 @@ if ( $Moose::VERSION < 1.99 ) { my $code = $meta->_inline_set_class_slot_value( $self->slots(), $value ) . ";"; - $code - .= $meta->_inline_weaken_class_slot_value( $self->slots(), $value ) + $code .= $meta->_inline_weaken_class_slot_value( + $self->slots(), + $value + ) . " if ref $value;" if $self->is_weak_ref(); diff --git a/lib/MooseX/ClassAttribute/Trait/Class.pm b/lib/MooseX/ClassAttribute/Trait/Class.pm index daa2ccb..2a48b09 100644 --- a/lib/MooseX/ClassAttribute/Trait/Class.pm +++ b/lib/MooseX/ClassAttribute/Trait/Class.pm @@ -59,7 +59,7 @@ sub _post_add_class_attribute { } sub _attach_class_attribute { - my ($self, $attribute) = @_; + my ( $self, $attribute ) = @_; $attribute->attach_to_class($self); } @@ -126,8 +126,7 @@ around remove_class_attribute => sub { sub get_all_class_attributes { my $self = shift; - my %attrs - = map { + my %attrs = map { my $meta = Class::MOP::class_of($_); $meta && $meta->can('_class_attribute_map') ? %{ $meta->_class_attribute_map() } @@ -156,7 +155,7 @@ sub find_class_attribute_by_name { return $meta->get_class_attribute($name) if $meta->can('has_class_attribute') - && $meta->has_class_attribute($name); + && $meta->has_class_attribute($name); } return; diff --git a/t/05-with-attribute-helpers-backcompat.t b/t/05-with-attribute-helpers-backcompat.t index 5cea4fe..3712c7c 100644 --- a/t/05-with-attribute-helpers-backcompat.t +++ b/t/05-with-attribute-helpers-backcompat.t @@ -7,7 +7,6 @@ use Test::Requires { 'MooseX::AttributeHelpers' => 0.23, }; - { package MyClass; @@ -15,12 +14,13 @@ use Test::Requires { use MooseX::ClassAttribute; use MooseX::AttributeHelpers; - class_has counter => - ( metaclass => 'Counter', - is => 'ro', - provides => { inc => 'inc_counter', - }, - ); + class_has counter => ( + metaclass => 'Counter', + is => 'ro', + provides => { + inc => 'inc_counter', + }, + ); } is( MyClass->counter(), 0 ); diff --git a/t/06-role.t b/t/06-role.t index 43ca560..e99c6bf 100644 --- a/t/06-role.t +++ b/t/06-role.t @@ -38,7 +38,7 @@ use Moose::Util qw( apply_all_roles ); $self->ObjectCount( $self->ObjectCount() + 1 ); } - sub _BuildIt {42} + sub _BuildIt { 42 } sub _CallTrigger { push @{ $_[0]->TriggerRecord() }, [@_]; @@ -59,7 +59,6 @@ ok( 'ClassWithRoleHCA (immutable) does RoleHCA' ); - # These next tests are aimed at testing to-role application followed by # to-class application { @@ -95,7 +94,7 @@ ok( $self->ObjectCount( $self->ObjectCount() + 1 ); } - sub _BuildIt {42} + sub _BuildIt { 42 } sub _CallTrigger { push @{ $_[0]->TriggerRecord() }, [@_]; @@ -127,7 +126,7 @@ ok( default => 5, ); - sub _BuildIt {42} + sub _BuildIt { 42 } sub _CallTrigger { push @{ $_[0]->TriggerRecord() }, [@_]; diff --git a/t/11-moose-exporter.t b/t/11-moose-exporter.t index 07b2f16..a7ccf19 100644 --- a/t/11-moose-exporter.t +++ b/t/11-moose-exporter.t @@ -15,7 +15,7 @@ BEGIN { plan skip_all => 'This test fails with a syntax error' } use MooseX::ClassAttribute (); Moose::Exporter->setup_import_methods( - also => [ 'MooseX::ClassAttribute' ], + also => ['MooseX::ClassAttribute'], ); } @@ -23,13 +23,14 @@ BEGIN { plan skip_all => 'This test fails with a syntax error' } package MyClass; use Moose; + # use MooseX::Foo; # normal use MooseX::Foo->import; # Now theoretically, this should work -- the 'class_has' method # should have been imported via the MooseX package above. class_has attr => ( - is => 'ro', isa => 'Str', + is => 'ro', isa => 'Str', default => 'foo', ); } diff --git a/t/lib/SharedTests.pm b/t/lib/SharedTests.pm index aa4a72c..8683db2 100644 --- a/t/lib/SharedTests.pm +++ b/t/lib/SharedTests.pm @@ -23,6 +23,7 @@ our %Attrs = ( is => 'rw', isa => 'Int', lazy => 1, + # The side effect is used to test that this was called # lazily. default => sub { $Lazy = 1 }, @@ -44,6 +45,7 @@ our %Attrs = ( is => 'rw', isa => 'Delegatee', handles => [ 'units', 'color' ], + # if it's not lazy it makes a new object before we define # Delegatee's attributes. lazy => 1, @@ -104,7 +106,7 @@ our %Attrs = ( $self->ObjectCount( $self->ObjectCount() + 1 ); } - sub _BuildIt {42} + sub _BuildIt { 42 } sub _CallTrigger { push @{ $_[0]->TriggerRecord() }, [@_]; @@ -329,8 +331,8 @@ sub run_tests { { $thing->Triggerish(42); - is( scalar @{ $thing->TriggerRecord() }, 1, 'trigger was called' ); - is( $thing->Triggerish(), 42, 'Triggerish is now 42' ); + is( scalar @{ $thing->TriggerRecord() }, 1, 'trigger was called' ); + is( $thing->Triggerish(), 42, 'Triggerish is now 42' ); $thing->Triggerish(84); is( $thing->Triggerish(), 84, 'Triggerish is now 84' );