# My::Meta::Instance would be in a separate file from MyApp::User,
# and this would be a non-issue.
BEGIN { extends 'Moose::Meta::Instance' }
+
+ # unimport again to prevent the subsequent "use Moose" from warning.
+ no Moose;
}
=end testing-SETUP
# receive the old value
{
- package Foo;
+ package FooBar;
use Moose;
our @calls;
has foo => (is => 'rw', trigger => sub { push @calls, [@_] });
}
{
- my $attr = Foo->meta->get_attribute('foo');
+ my $attr = FooBar->meta->get_attribute('foo');
- my $foo = Foo->new;
+ my $foo = FooBar->new;
$attr->set_value( $foo, 2 );
is_deeply(
- \@Foo::calls,
+ \@FooBar::calls,
[ [ $foo, 2 ] ],
'trigger called correctly on initial set via meta-API',
);
- @Foo::calls = ();
+ @FooBar::calls = ();
$attr->set_value( $foo, 3 );
is_deeply(
- \@Foo::calls,
+ \@FooBar::calls,
[ [ $foo, 3, 2 ] ],
'trigger called correctly on second set via meta-API',
);
- @Foo::calls = ();
+ @FooBar::calls = ();
$attr->set_raw_value( $foo, 4 );
is_deeply(
- \@Foo::calls,
+ \@FooBar::calls,
[ ],
'trigger not called using set_raw_value method',
);
- @Foo::calls = ();
+ @FooBar::calls = ();
}
{
- my $foo = Foo->new(foo => 2);
+ my $foo = FooBar->new(foo => 2);
is_deeply(
- \@Foo::calls,
+ \@FooBar::calls,
[ [ $foo, 2 ] ],
'trigger called correctly on construction',
);
- @Foo::calls = ();
+ @FooBar::calls = ();
$foo->foo(3);
is_deeply(
- \@Foo::calls,
+ \@FooBar::calls,
[ [ $foo, 3, 2 ] ],
'trigger called correctly on set (with old value)',
);
- @Foo::calls = ();
- Foo->meta->make_immutable, redo if Foo->meta->is_mutable;
+ @FooBar::calls = ();
+ FooBar->meta->make_immutable, redo if FooBar->meta->is_mutable;
}
done_testing;
}
{
- package Bar;
+ package FooBar;
use Moose -traits => [ 'My::SimpleTrait2' ];
}
-can_ok( Bar->meta(), 'simple' );
-is( Bar->meta()->simple(), 5,
- 'Bar->meta()->simple() returns expected value' );
-can_ok( Bar->meta(), 'attr' );
-is( Bar->meta()->attr(), 'something',
- 'Bar->meta()->attr() returns expected value' );
+can_ok( FooBar->meta(), 'simple' );
+is( FooBar->meta()->simple(), 5,
+ 'FooBar->meta()->simple() returns expected value' );
+can_ok( FooBar->meta(), 'attr' );
+is( FooBar->meta()->attr(), 'something',
+ 'FooBar->meta()->attr() returns expected value' );
{
package My::SimpleTrait3;
package TestBaz;
use Moose;
has 'foo' => (is => 'ro', isa => 'Int');
+no Moose;
1;
|;
use Moose;
extends 'Foo';
has 'foo' => (is => 'rw', isa => 'Int');
+no Moose;
1;
|;
subtype Bling => as Baz => where { 1 };
-1;
\ No newline at end of file
+no Moose;
+no Moose::Util::TypeConstraints;
+
+1;
has 'bar' => (is => 'rw');
-1;
\ No newline at end of file
+no Moose;
+
+1;
has 'b' => (is => 'rw', isa => 'MyMooseB');
-1;
\ No newline at end of file
+no Moose;
+
+1;
use Moose;
-1;
\ No newline at end of file
+no Moose;
+
+1;