push @trigger_calls,
'if (exists $params->{\'' . $init_arg . '\'}) {',
- '$attrs->[' . $i . ']->trigger->(',
+ '$triggers->[' . $i . ']->(',
'$instance,',
$attr->_inline_instance_get('$instance') . ',',
');',
use warnings;
use Carp ();
+use List::MoreUtils 'any';
use Scalar::Util 'blessed', 'weaken', 'looks_like_number', 'refaddr';
use Try::Tiny;
my $attrs = $self->_attributes;
my $defaults = [map { $_->default } @$attrs];
+ my $triggers = [
+ map { $_->can('has_trigger') && $_->has_trigger ? $_->trigger : undef }
+ @$attrs
+ ];
# We need to check if the attribute ->can('type_constraint')
# since we may be trying to immutabilize a Moose meta class,
return {
'$meta' => \$self,
- '$attrs' => \$attrs,
+ ((any { defined && $_->has_initializer } @$attrs)
+ ? ('$attrs' => \$attrs)
+ : ()),
'$defaults' => \$defaults,
+ '$triggers' => \$triggers,
'@type_constraints' => \@type_constraints,
'@type_coercions' => \@type_coercions,
'@type_constraint_bodies' => \@type_constraint_bodies,