Revision history for Mouse
0.29
+ * Support is => 'bare', and you must pass the 'is' option (gfx)
+ * Make generator methods private (gfx)
0.28 Wed Sep 8 20:00:06 2009
* Alter Makefile.PL so in author mode we generate lib/Mouse/Tiny.pm on
package Mouse::Meta::Attribute;
use strict;
use warnings;
-require overload;
use Carp 'confess';
use Scalar::Util ();
$class->add_attribute($attribute);
+ my $associated_methods = 0;
+
+ my $is_metadata = $attribute->_is_metadata || '';
+
# install an accessor
- if ($attribute->_is_metadata eq 'rw' || $attribute->_is_metadata eq 'ro') {
+ if ($is_metadata eq 'rw' || $is_metadata eq 'ro') {
my $code = $attribute->_generate_accessor();
$class->add_method($name => $code);
+ $associated_methods++;
}
for my $method (qw/predicate clearer/) {
my $generator = "_generate_$method";
my $coderef = $attribute->$generator;
$class->add_method($attribute->$method => $coderef);
+ $associated_methods++;
}
}
my $method_map = $attribute->_generate_handles;
for my $method_name (keys %$method_map) {
$class->add_method($method_name => $method_map->{$method_name});
+ $associated_methods++;
}
}
+ if($associated_methods == 0 && $is_metadata ne 'bare'){
+ confess(qq{Attribute ($name) of class }.$class->name.qq{ has no associated methods (did you mean to provide an "is" argument?)});
+ }
+
return $attribute;
}
use strict;
use warnings;
use Carp 'confess';
+
+use Mouse::Meta::Attribute;
use Mouse::Util qw(version authority identifier);
do {
my $self = shift;
my $name = shift;
my $spec = shift;
- $self->{attributes}->{$name} = $spec;
+ $self->{attributes}->{$name} = Mouse::Meta::Attribute->new($name, %$spec);
}
sub has_attribute { exists $_[0]->{attributes}->{$_[1]} }
extends 'Point';
- has 'z' => (isa => 'Int');
+ has 'z' => (isa => 'Int', is => 'bare');
after 'clear' => sub {
my $self = shift;
package Class;
use Mouse;
- has 'x';
+ has 'x' => (
+ is => 'bare',
+ );
has 'y' => (
is => 'ro',
use Mouse;
has foo => (
+ is => 'bare',
required => 1,
);
has bar => (
+ is => 'bare',
required => 1,
default => 50,
);
has baz => (
+ is => 'bare',
required => 1,
default => sub { 10 },
);
use Mouse;
has oops => (
+ is => 'bare',
isa => 'Int',
default => "yikes",
);
package Class;
use Mouse;
- has 'x';
+ has x => (
+ is => 'bare',
+ );
has y => (
is => 'ro',
ok($foo_role->has_attribute('bar'), '... FooRole does have the bar attribute');
-is_deeply(
- $foo_role->get_attribute('bar'),
- { is => 'rw', isa => 'Foo' },
- '... got the correct description of the bar attribute');
+is $foo_role->get_attribute('bar')->name, 'bar', '... got the correct description of the bar attribute';
ok($foo_role->has_attribute('baz'), '... FooRole does have the baz attribute');
-is_deeply(
- $foo_role->get_attribute('baz'),
- { is => 'ro' },
+is(
+ $foo_role->get_attribute('baz')->name,
+ 'baz',
'... got the correct description of the baz attribute');
# method modifiers
use Mouse::Role;
has 'attr' => (
+ is => 'bare',
default => 'Role',
);
no Mouse::Role;
};
-is_deeply(Role->meta->get_attribute('attr'), {default => 'Role'});
+is(Role->meta->get_attribute('attr')->default, 'Role');
do {
package Class;
use Mouse::Role;
has 'attr' => (
+ is => 'bare',
default => 'Role2',
);
with 'Role';
has attr => (
+ is => 'bare',
default => 'Class3',
);
};
use Mouse;
has attr => (
+ is => 'bare',
default => 'Class::Parent',
);
};