* Class::MOP::Class
- adding in &mixin method to do Scala style mixins
+
+ * examples/
+ - fixing the AttributesWithHistory example, it was broken
0.06 Thurs Feb. 9, 2006
* metaclass
use strict;
use warnings;
-our $VERSION = '0.02';
+our $VERSION = '0.03';
use base 'Class::MOP::Attribute';
__PACKAGE__->meta->add_attribute(
Class::MOP::Attribute->new('_history' => (
accessor => '_history',
- default => sub { [] },
+ default => sub { {} },
))
);
sub generate_history_accessor_method {
my ($self, $attr_name) = @_;
eval qq{sub {
- \@\{\$_[0]->meta->get_attribute('$attr_name')->_history()\};
+ unless (ref \$_[0]->meta->get_attribute('$attr_name')->_history()->\{\$_[0]\}) \{
+ \$_[0]->meta->get_attribute('$attr_name')->_history()->\{\$_[0]\} = [];
+ \}
+ \@\{\$_[0]->meta->get_attribute('$attr_name')->_history()->\{\$_[0]\}\};
}};
}
my ($self, $attr_name) = @_;
eval qq{sub {
if (scalar(\@_) == 2) {
- push \@\{\$_[0]->meta->get_attribute('$attr_name')->_history()\} => \$_[1];
+ unless (ref \$_[0]->meta->get_attribute('$attr_name')->_history()->\{\$_[0]\}) \{
+ \$_[0]->meta->get_attribute('$attr_name')->_history()->\{\$_[0]\} = [];
+ \}
+ push \@\{\$_[0]->meta->get_attribute('$attr_name')->_history()->\{\$_[0]\}\} => \$_[1];
\$_[0]->{'$attr_name'} = \$_[1];
}
\$_[0]->{'$attr_name'};
sub generate_writer_method {
my ($self, $attr_name) = @_;
eval qq{sub {
- push \@\{\$_[0]->meta->get_attribute('$attr_name')->_history()\} => \$_[1];
+ unless (ref \$_[0]->meta->get_attribute('$attr_name')->_history()->\{\$_[0]\}) \{
+ \$_[0]->meta->get_attribute('$attr_name')->_history()->\{\$_[0]\} = [];
+ \}
+ push \@\{\$_[0]->meta->get_attribute('$attr_name')->_history()->\{\$_[0]\}\} => \$_[1];
\$_[0]->{'$attr_name'} = \$_[1];
}};
}
use B 'svref_2object';
use Clone ();
-our $VERSION = '0.03';
+our $VERSION = '0.04';
# Self-introspection
shift @class_list; # shift off $self->name
foreach my $class_name (@class_list) {
- next unless $METAS{$class_name};
my $meta = $METAS{$class_name};
($self->isa(blessed($meta)))
|| confess $self->name . "->meta => (" . (blessed($self)) . ")" .
use strict;
use warnings;
-use Test::More tests => 19;
+use Test::More tests => 28;
use File::Spec;
BEGIN {
can_ok($foo, 'get_bar');
can_ok($foo, 'get_bar_history');
+my $foo2 = Foo->new();
+isa_ok($foo2, 'Foo');
+
is($foo->foo, undef, '... foo is not yet defined');
is_deeply(
[ $foo->get_foo_history() ],
[ ],
'... got correct empty history for foo');
+
+is($foo2->foo, undef, '... foo2 is not yet defined');
+is_deeply(
+ [ $foo2->get_foo_history() ],
+ [ ],
+ '... got correct empty history for foo2');
$foo->foo(42);
is($foo->foo, 42, '... foo == 42');
[ 42 ],
'... got correct history for foo');
+is($foo2->foo, undef, '... foo2 is still not yet defined');
+is_deeply(
+ [ $foo2->get_foo_history() ],
+ [ ],
+ '... still got correct empty history for foo2');
+
+$foo2->foo(100);
+is($foo->foo, 42, '... foo is still == 42');
+is_deeply(
+ [ $foo->get_foo_history() ],
+ [ 42 ],
+ '... still got correct history for foo');
+
+is($foo2->foo, 100, '... foo2 == 100');
+is_deeply(
+ [ $foo2->get_foo_history() ],
+ [ 100 ],
+ '... got correct empty history for foo2');
+
$foo->foo(43);
$foo->foo(44);
$foo->foo(45);