with 'MooseX::ClassAttribute::Trait::Application';
around apply => sub {
- my $orig = shift;
+ my $orig = shift;
my $self = shift;
my $role = shift;
my $class = shift;
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() ) );
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();
}
sub _attach_class_attribute {
- my ($self, $attribute) = @_;
+ my ( $self, $attribute ) = @_;
$attribute->attach_to_class($self);
}
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() }
return $meta->get_class_attribute($name)
if $meta->can('has_class_attribute')
- && $meta->has_class_attribute($name);
+ && $meta->has_class_attribute($name);
}
return;
'MooseX::AttributeHelpers' => 0.23,
};
-
{
package MyClass;
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 );
$self->ObjectCount( $self->ObjectCount() + 1 );
}
- sub _BuildIt {42}
+ sub _BuildIt { 42 }
sub _CallTrigger {
push @{ $_[0]->TriggerRecord() }, [@_];
'ClassWithRoleHCA (immutable) does RoleHCA'
);
-
# These next tests are aimed at testing to-role application followed by
# to-class application
{
$self->ObjectCount( $self->ObjectCount() + 1 );
}
- sub _BuildIt {42}
+ sub _BuildIt { 42 }
sub _CallTrigger {
push @{ $_[0]->TriggerRecord() }, [@_];
default => 5,
);
- sub _BuildIt {42}
+ sub _BuildIt { 42 }
sub _CallTrigger {
push @{ $_[0]->TriggerRecord() }, [@_];
use MooseX::ClassAttribute ();
Moose::Exporter->setup_import_methods(
- also => [ 'MooseX::ClassAttribute' ],
+ also => ['MooseX::ClassAttribute'],
);
}
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',
);
}
is => 'rw',
isa => 'Int',
lazy => 1,
+
# The side effect is used to test that this was called
# lazily.
default => sub { $Lazy = 1 },
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,
$self->ObjectCount( $self->ObjectCount() + 1 );
}
- sub _BuildIt {42}
+ sub _BuildIt { 42 }
sub _CallTrigger {
push @{ $_[0]->TriggerRecord() }, [@_];
{
$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' );