Require latest Moose as well.
my $builder = Module::Build->new
( module_name => 'MooseX::ClassAttribute',
license => 'perl',
- requires => { 'Moose' => '0.74',
+ requires => { 'Moose' => '0.89',
'MooseX::AttributeHelpers' => '0.13',
},
build_requires => { 'Scalar::Util' => '0',
+0.10 2009-08-26
+
+- Fixed to make triggers work with Moose 0.89+, and made triggers pass the old
+ attribute value when appropriate just like non-class attributes.
+
+
0.09 2009-07-09
- An attribute with a builder that wasn't also lazy caused an
use strict;
use warnings;
-our $VERSION = '0.09';
+our $VERSION = '0.10';
our $AUTHORITY = 'cpan:DROLSKY';
-use Moose 0.74 ();
+use Moose 0.89 ();
use Moose::Exporter;
use MooseX::ClassAttribute::Role::Meta::Class;
( q{'} . $self->associated_attribute()->associated_class()->name() . q{'} );
}
+sub _inline_get_old_value_for_trigger
+{
+ my $self = shift;
+
+ my $attr = $self->associated_attribute();
+ return '' unless $attr->has_trigger();
+
+ my $pred =
+ $attr->associated_class()->inline_is_class_slot_initialized( $attr->name() );
+
+ return
+ 'my @old = '
+ . $pred . q{ ? }
+ . $self->_inline_get() . q{ : ()} . ";\n";
+
+}
+
no Moose;
1;
->meta()->does_role('MooseX::ClassAttribute::Role::Meta::Attribute'),
'get_class_attribute_list returns an object which does the MooseX::ClassAttribute::Role::Meta::Attribute role' );
-my @ca = qw( Delegatee LazyAttribute ManyNames Mapping ObjectCount ReadOnlyAttribute WeakAttribute Built LazyBuilt );
+my @ca = qw( Delegatee
+ LazyAttribute
+ ManyNames
+ Mapping
+ ObjectCount
+ ReadOnlyAttribute
+ WeakAttribute
+ Built
+ LazyBuilt
+ Triggerish
+ );
is_deeply( [ sort HasClassAttribute->meta()->get_class_attribute_list() ],
[ sort @ca ],
builder => '_BuildIt',
);
+ class_has 'Triggerish' =>
+ ( is => 'rw',
+ trigger => sub { shift->_CallTrigger(@_) },
+ );
+
has 'size' =>
( is => 'rw',
isa => 'Int',
sub _BuildIt { 42 }
+ our @Triggered;
+ sub _CallTrigger
+ {
+ push @Triggered, [@_];
+ }
+
sub make_immutable
{
my $class = shift;
sub run_tests
{
- plan tests => 26;
+ plan tests => 30;
local $Test::Builder::Level = $Test::Builder::Level + 1;
is( HasClassAttribute->LazyBuilt(), 42,
'attribute with lazy builder works' );
}
+
+ {
+ HasClassAttribute->Triggerish(42);
+ is( scalar @HasClassAttribute::Triggered, 1, 'trigger was called' );
+ is( HasClassAttribute->Triggerish(), 42, 'Triggerish is now 42' );
+
+ HasClassAttribute->Triggerish(84);
+ is( HasClassAttribute->Triggerish(), 84, 'Triggerish is now 84' );
+
+ is_deeply( \@HasClassAttribute::Triggered,
+ [ [ qw( HasClassAttribute 42 ) ],
+ [ qw( HasClassAttribute 84 42 ) ],
+ ],
+ 'trigger passes old value correctly' );
+ }
}