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
if exists $args{coerce};
if (exists $args{isa}) {
- confess "Got isa => $args{isa}, but Mouse does not yet support parameterized types for containers other than ArrayRef and HashRef (rt.cpan.org #39795)"
- if $args{isa} =~ /^([^\[]+)\[.+\]$/ &&
- $1 ne 'ArrayRef' &&
- $1 ne 'HashRef' &&
- $1 ne 'Maybe'
- ;
-
my $type_constraint = delete $args{isa};
$args{type_constraint}= Mouse::Util::TypeConstraints::find_or_create_isa_type_constraint($type_constraint);
}
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} = Mouse::Meta::Attribute->new($name, %$spec);
+ $self->{attributes}->{$name} = $spec;
}
sub has_attribute { exists $_[0]->{attributes}->{$_[1]} }
package Mouse::Meta::TypeConstraint;
use strict;
use warnings;
+use Carp ();
+
use overload '""' => sub { shift->{name} }, # stringify to tc name
fallback => 1;
$self->{_compiled_type_constraint}->(@_);
}
+sub validate {
+ my ($self, $value) = @_;\r
+ if ($self->{_compiled_type_constraint}->($value)) {\r
+ return undef;\r
+ }\r
+ else {\r
+ $self->get_message($value);\r
+ }\r
+}
+
+sub assert_valid {\r
+ my ($self, $value) = @_;\r
+\r
+ my $error = $self->validate($value);\r
+ return 1 if ! defined $error;\r
+
+ Carp::confess($error);\r
+}\r
+
+
sub message {
return $_[0]->{message};
}
sub find_or_create_isa_type_constraint {
my $type_constraint = shift;
+ Carp::confess("Got isa => type_constraints, but Mouse does not yet support parameterized types for containers other than ArrayRef and HashRef and Maybe (rt.cpan.org #39795)")
+ if $type_constraint =~ /\A ( [^\[]+ ) \[\.+\] \z/xms &&
+ $1 ne 'ArrayRef' &&
+ $1 ne 'HashRef' &&
+ $1 ne 'Maybe'
+ ;
+
my $code;
$type_constraint =~ s/\s+//g;
ok($foo_role->has_attribute('bar'), '... FooRole does have the bar attribute');
-is $foo_role->get_attribute('bar')->name, 'bar', '... got the correct description of the bar attribute';
+is $foo_role->get_attribute('bar')->{is}, 'rw', '... got the correct description of the bar attribute';
ok($foo_role->has_attribute('baz'), '... FooRole does have the baz attribute');
is(
- $foo_role->get_attribute('baz')->name,
- 'baz',
+ $foo_role->get_attribute('baz')->{is},
+ 'ro',
'... got the correct description of the baz attribute');
# method modifiers
no Mouse::Role;
};
-is(Role->meta->get_attribute('attr')->default, 'Role');
+is(Role->meta->get_attribute('attr')->{default}, 'Role');
do {
package Class;