# get symbol table reference
my $stash = do { no strict 'refs'; \%{"${target}::"} };
_install_tracked $target => has => sub {
- my ($name, %spec) = @_;
- ($INFO{$target}{accessor_maker} ||= do {
- require Method::Generate::Accessor;
- Method::Generate::Accessor->new
- })->generate_method($target, $name, \%spec);
- push @{$INFO{$target}{attributes}||=[]}, $name, \%spec;
- $me->_maybe_reset_handlemoose($target);
+ my ($name_proto, %spec) = @_;
+ my $name_isref = ref $name_proto eq 'ARRAY';
+ foreach my $name ($name_isref ? @$name_proto : $name_proto) {
+ my $spec_ref = $name_isref ? +{%spec} : \%spec;
+ ($INFO{$target}{accessor_maker} ||= do {
+ require Method::Generate::Accessor;
+ Method::Generate::Accessor->new
+ })->generate_method($target, $name, $spec_ref);
+ push @{$INFO{$target}{attributes}||=[]}, $name, $spec_ref;
+ $me->_maybe_reset_handlemoose($target);
+ }
};
# install before/after/around subs
foreach my $type (qw(before after around)) {
};
$INFO{$role}{requires} = [ $meta->get_required_method_list ];
$INFO{$role}{attributes} = [
- map +($_ => $meta->get_attribute($_)), $meta->get_attribute_list
+ map +($_ => do {
+ my $spec = { %{$meta->get_attribute($_)} };
+
+ if ($spec->{isa}) {
+
+ my $get_constraint = do {
+ my $pkg = $meta->isa('Mouse::Meta::Role')
+ ? 'Mouse::Util::TypeConstraints'
+ : 'Moose::Util::TypeConstraints';
+ _load_module($pkg);
+ $pkg->can('find_or_create_isa_type_constraint');
+ };
+
+ my $tc = $get_constraint->($spec->{isa});
+ my $check = $tc->_compiled_type_constraint;
+
+ $spec->{isa} = sub {
+ &$check or die "Type constraint failed for $_[0]"
+ };
+
+ if ($spec->{coerce}) {
+
+ # Mouse has _compiled_type_coercion straight on the TC object
+ $spec->{coerce} = $tc->${\(
+ $tc->can('coercion')||sub { $_[0] }
+ )}->_compiled_type_coercion;
+ }
+ }
+ $spec;
+ }), $meta->get_attribute_list
];
my $mods = $INFO{$role}{modifiers} = [];
foreach my $type (qw(before after around)) {
sub apply_roles_to_package {
my ($me, $to, @roles) = @_;
- $me->_inhale_if_moose($_) for @roles;
+ foreach my $role (@roles) {
+ $me->_inhale_if_moose($role);
+ }
$me->SUPER::apply_roles_to_package($to, @roles);
}
return $new_name if $Role::Tiny::COMPOSED{class}{$new_name};
- $me->_inhale_if_moose($_) for @roles;
+ foreach my $role (@roles) {
+ $me->_inhale_if_moose($role);
+ }
my $m;
if ($INC{"Moo.pm"}
1;
-else where
+And elsewhere:
package Some::Class;