use Carp 'confess';
use Scalar::Util 'weaken', 'blessed', 'reftype';
-our $VERSION = '0.17';
+our $VERSION = '0.20';
our $AUTHORITY = 'cpan:STEVAN';
use Moose::Meta::Method::Overriden;
my ($class, %params) = @_;
my $self = $class->SUPER::new_object(%params);
foreach my $attr ($class->compute_all_applicable_attributes()) {
- # FIXME:
- # this does not accept undefined
- # values, nor does it accept false
- # values to be passed into the init-arg
- next unless $params{$attr->init_arg} && $attr->can('has_trigger') && $attr->has_trigger;
- $attr->trigger->($self, $params{$attr->init_arg}, $attr);
+ if ( defined( my $init_arg = $attr->init_arg ) ) {
+ if ( exists($params{$init_arg}) && $attr->can('has_trigger') && $attr->has_trigger ) {
+ $attr->trigger->($self, $params{$init_arg}, $attr);
+ }
+ }
}
return $self;
}
sub add_attribute {
my $self = shift;
- $self->SUPER::add_attribute($self->_process_attribute(@_));
+ $self->SUPER::add_attribute(
+ (blessed $_[0] && $_[0]->isa('Class::MOP::Attribute')
+ ? $_[0]
+ : $self->_process_attribute(@_))
+ );
}
sub add_override_method_modifier {
# this was crap anyway, see
# Moose::Util::apply_all_roles
# instead
-sub _apply_all_roles { die "DEPRECATED" }
+sub _apply_all_roles {
+ die 'DEPRECATED: use Moose::Util::apply_all_roles($meta, @roles) instead'
+}
my %ANON_CLASSES;
superclasses => [ $attr_metaclass_name ]
);
$ANON_CLASSES{$anon_role_key} = $class;
- Moose::Util::apply_all_roles($class, @{$options{traits}});
+
+ my @traits;
+ foreach my $trait (@{$options{traits}}) {
+ eval {
+ my $possible_full_name = 'Moose::Meta::Attribute::Custom::Trait::' . $trait;
+ Class::MOP::load_class($possible_full_name);
+ push @traits => $possible_full_name->can('register_implementation')
+ ? $possible_full_name->register_implementation
+ : $possible_full_name;
+ };
+ if ($@) {
+ push @traits => $trait;
+ }
+ }
+
+ Moose::Util::apply_all_roles($class, @traits);
}
$attr_metaclass_name = $class->name;