my $meta = Mouse::Meta::Class->initialize(scalar caller);
my $name = shift;
+ $meta->throw_error(q{Usage: has 'name' => ( key => value, ... )})\r
+ if @_ % 2; # odd number of arguments
+
$meta->add_attribute($_ => @_) for ref($name) ? @{$name} : $name;
}
$impl = sub {
my ( $self, $type, $name, $code ) = @_;
my $into = $self->name;
- $install_modifier->(
- $into,
- $type,
- $name,
- $code
- );
+ $install_modifier->($into, $type, $name, $code);
+
$self->add_method($name => do{
no strict 'refs';
\&{ $into . '::' . $name };
|| $self->throw_error("You must supply a role name to look for");
for my $class ($self->linearized_isa) {
- my $meta = Mouse::Util::get_metaclass_by_name($class);
- next unless $meta && $meta->can('roles');
+ my $meta = Mouse::Util::get_metaclass_by_name($class)
+ or next;
for my $role (@{ $meta->roles }) {
}
1;
-
__END__
=head1 NAME
$value = '$default';
}
+ $accessor .= "if(!exists $slot){\n";
if($should_coerce){
- $value = "\$constraint->coerce($value)";
+ $accessor .= "$slot = \$constraint->coerce($value)";
}
-
- $accessor .= "$slot = $value if !exists $slot;\n";
+ elsif(defined $constraint){
+ $accessor .= "my \$tmp = $value;\n";
+ $accessor .= "\$compiled_type_constraint->(\$tmp)";
+ $accessor .= "or \$attribute->verify_type_constraint_error(\$name, \$tmp, \$constraint);\n";
+ $accessor .= "$slot = \$tmp;\n";
+ }
+ else{
+ $accessor .= "$slot = $value;\n";
+ }
+ $accessor .= "}\n";
}
if ($should_deref) {