use strictures 1;
use Moo::_Utils;
+use B qw(perlstring);
our %TYPE_MAP;
sub inject_all {
require Class::MOP;
- inject_fake_metaclass_for($_) for grep $_ ne 'Moo::Object', keys %Moo::MAKERS;
+ inject_fake_metaclass_for($_)
+ for grep $_ ne 'Moo::Object', do { no warnings 'once'; keys %Moo::MAKERS };
inject_fake_metaclass_for($_) for keys %Moo::Role::INFO;
require Moose::Meta::Method::Constructor;
@Moo::HandleMoose::FakeConstructor::ISA = 'Moose::Meta::Method::Constructor';
);
}
};
+ die "Aaaargh" if $spec{coerce};
+ } elsif (my $coerce = $spec{coerce}) {
+ my $attr = perlstring($name);
+ my $tc = Moose::Meta::TypeConstraint->new(
+ constraint => sub { die "This is not going to work" },
+ inlined => sub { 'my $res = $_[42]{'.$attr.'}; $_[42]{'.$attr.'} = 1; $res' },
+ #coercion => Moose::Meta::TypeCoercion->new(
+ # type_coercion_map => [
+ # 'Item', $coerce
+ # ]
+ #)
+ );
+ $tc->coercion(Moose::Meta::TypeCoercion->new)
+ ->_compiled_type_coercion($coerce);
+ $spec{isa} = $tc;
+ $spec{coerce} = 1;
}
push @attrs, $meta->add_attribute($name => %spec);
}
);
}
$meta->add_role(Class::MOP::class_of($_))
- for keys %{$Role::Tiny::APPLIED_TO{$name}};
+ for do { no warnings 'once'; keys %{$Role::Tiny::APPLIED_TO{$name}} };
$DID_INJECT{$name} = 1;
$meta;
}
package Bar;
use Moose;
with 'FrewWithIsa';
+
+ package OffByOne;
+ use Moo::Role;
+
+ has off_by_one => (is => 'rw', coerce => sub { $_[0] + 1 });
+
+ package Baz;
+ use Moo;
+
+ with 'OffByOne';
+
+ package Quux;
+ use Moose;
+
+ with 'OffByOne';
+
+ __PACKAGE__->meta->make_immutable;
}
lives_ok {
Bar->new(frooh => 1, frew => 'goose');
} 'creation of invalid Bar validated by quoted sub';
+sub test_off_by_one {
+ my ($class, $type) = @_;
+
+ my $obo = $class->new(off_by_one => 1);
+
+ is($obo->off_by_one, 2, "Off by one (new) ($type)");
+
+ $obo->off_by_one(41);
+
+ is($obo->off_by_one, 42, "Off by one (set) ($type)");
+}
+
+test_off_by_one('Baz', 'Moo');
+test_off_by_one('Quux', 'Moose');
+
done_testing;