est::Fatal;
use Class::MOP;
{
isnt( exception {
Class::MOP::Class->initialize();
}, undef, '... initialize requires a name parameter' );
isnt( exception {
Class::MOP::Cl
lid parameter' );
isnt( exception {
Class::MOP::Class->initialize(bless {} => 'Foo');
}, undef, '... initialize requires an unblessed parameter' );
}
{
isnt( exception {
isnt( exception {
Class::MOP::Class->_construct_class_instance(':package' => undef);
}, undef, '... _construct_class_instance requires a defined :package parameter' );
isnt( exc
;
isnt( exception { $meta->add_method() }, undef, '... exception thrown as expected' );
isnt( exception { $meta->alias_method() }, undef, '... exception thrown as expected' );
isnt( excep
isnt( exception { $meta->add_attribute() }, undef, '... exception thrown as expected' );
isnt( exception { $meta->remove_attribute() }, undef, '... exception thrown as expected' );
isnt( e
xception { $meta->add_package_symbol() }, undef, '... exception thrown as expected' );
isnt( exception { $meta->remove_package_symbol() }, undef, '... exception thrown as expected' );
is( exc
e static
{
isnt( exception {
Class::MOP::Attribute->new('$test' => (
default => qr/hello (.*)/
));
}, undef, '... no refs for defaults' );
isnt( exception {
or defaults' );
isnt( exception {
Class::MOP::Attribute->new('$test' => (
default => {}
));
}, undef, '... no refs for defaults' );
isnt( exception {
ts' );
isnt( exception {
Class::MOP::Attribute->new('$test' => (
default => bless {} => 'Foo'
));
}, undef, '... no refs for defaults' );
}
{
isnt( exception
tch');
is( exception { $meta->remove_package_symbol('$ref') }, undef, '... removed it' );
isnt($meta->get_package_symbol('$ref'), $reef, '... values match');
ok( my @supers = $meta->su
, '... changed Baz to be immutable' );
isnt( exception { $meta->add_method('xyz', sub{'xxx'}) }, undef, '... exception thrown as expected' );
isnt( exception {
$meta->add_attribute('f
ption thrown as expected' );
isnt( exception { $meta->remove_attribute('fickle') }, undef, '... exception thrown as expected' );
my $reef = \ 'reef';
isnt( exception { $meta->add_package_
ed_name is the same as fully_qualified_name'
);
isnt( exception { Class::MOP::Method->wrap }, undef, q{... can't call wrap() without some code} );
isnt( exception { Class::MOP::Method->wrap( [] ) },
't call wrap() without some code} );
isnt( exception { Class::MOP::Method->wrap( bless {} => 'Fail' ) }, undef, q{... can't call wrap() without some code} );
isnt( exception { Class::MOP::Method->nam
f, q{... can't call name() as a class method} );
isnt( exception { Class::MOP::Method->body }, undef, q{... can't call body() as a class method} );
isnt( exception { Class::MOP::Method->package_name }
est::More;
use Test::Fatal;
use Class::MOP;
use Class::MOP::Attribute;
use Class::MOP::Method;
isnt( exception { Class::MOP::Attribute->name }, undef, q{... can't call name() as a class method} );
}
my $attr_clone = $attr->clone();
isa_ok($attr_clone, 'Class::MOP::Attribute');
isnt($attr, $attr_clone, '... but they are different instances');
is($attr->associated_class, $at
}
my $attr_clone = $attr->clone();
isa_ok($attr_clone, 'Class::MOP::Attribute');
isnt($attr, $attr_clone, '... but they are different instances');
is($attr->associated_class, $at
;
my $bar_attr2 = Foo->meta->get_attribute('bar');
::isnt($bar_attr, $bar_attr2, '... this is a new bar attribute');
::isnt($bar_attr->associated_class, Foo->meta, '... and the old bar a
ribute *is* associated with Foo->meta');
::isnt($bar_attr2->reader, 'get_bar', '... the bar attribute no longer has the reader get_bar');
::isnt($bar_attr2->reader, 'set_bar', '... the bar at
one_object($foo);
isa_ok($cloned_foo, 'Foo');
isnt($cloned_foo, $foo, '... $cloned_foo is a new object different from $foo');
# check some errors
isnt( exception {
$foo_meta->clone_object($meta
OP::Attribute');
my $attr_clone = $attr->clone();
isa_ok($attr_clone, 'Class::MOP::Attribute');
isnt($attr, $attr_clone, '... we successfully cloned our attributes');
is($attr->associated_class,
Bar');
isnt($bar_meta, $foo_meta, '... Bar->meta != Foo->meta');
my $baz_meta = Baz->meta;
isa_ok($baz_meta, 'Class::MOP::Class');
is($baz_meta->name, 'Baz', '... baz_meta->name == Baz');
isnt($baz_
meta, $bar_meta, '... Baz->meta != Bar->meta');
isnt($baz_meta, $foo_meta, '... Baz->meta != Foo->meta');
done_testing;
;
{
my $clone = $foo->meta->clone_object($foo, foo => 'BAZ');
isa_ok($clone, 'Foo');
isnt($clone, $foo, '... and it is a clone');
is($clone->get_foo, 'BAZ', '... got the right cloned
}
{
my $clone = $foo->meta->clone_object($foo, foo => undef);
isa_ok($clone, 'Foo');
isnt($clone, $foo, '... and it is a clone');
ok(!defined($clone->get_foo), '... got the right clo
for Foo');
my $mi_bar = Bar->meta->get_meta_instance;
isa_ok($mi_bar, "Class::MOP::Instance");
isnt($mi_foo, $mi_bar, '... they are not the same instance');
is_deeply(
[ sort $mi_bar->get_all_
k($i_foo, "Foo");
{
my $i_foo_2 = $mi_foo->create_instance;
isa_ok($i_foo_2, "Foo");
isnt($i_foo_2, $i_foo, '... not the same instance');
is_deeply($i_foo, $i_foo_2, '... but the same
rent", 'Parent->whoami gives parent');
is($foo->parent, "parent", 'Parent->parent gives parent');
isnt( exception { $foo->child }, undef, "Parent->child method doesn't exist" );
Child->meta->rebless_
rent", 'Parent->whoami gives parent');
is($foo->parent, "parent", 'Parent->parent gives parent');
isnt( exception { $foo->child }, undef, "Parent->child method doesn't exist" );
like( exception { Lef
oo method' );
ok( !$Foo->has_method('foo'),
'... !Foo->has_method(foo) we just removed it' );
isnt( exception { Foo->foo }, undef, '... cannot call Foo->foo because it is not there' );
is_deeply(
>meta->add_method( $method->name, $method );
my $new_method = Bar->meta->get_method('objecty');
isnt( $method, $new_method,
'add_method clones method objects as they are added' );
is( $new_metho
;
use Class::MOP::Package;
isnt( exception { Class::MOP::Package->get_all_package_symbols }, undef, q{... can't call get_all_package_symbols() as a class method} );
isnt( exception { Class::MOP::Pac
use strict;
use warnings;
use Test::More;
use Test::Fatal;
require Class::MOP;
use lib 't/lib';
isnt( exception {
Class::MOP::is_class_loaded()
}, undef, "is_class_loaded with no argument dies"
or');
is($point->x, 2, '... the x attribute was initialized correctly through the metaobject');
isnt( exception {
$point->x(42);
}, undef, '... cannot write to a read-only accessor' );
is($point
;
is( $savings_account->balance, 200,
'... got the right savings balance after withdrawal' );
isnt( exception {
$savings_account->withdraw(250);
}, undef, '... could not withdraw from savings
);
},
q{},
'no warning when replace_destructor is true'
);
::isnt(
$meta->find_method_by_name('new')->body,
HasConstructor2->can('new'),
'H
ok( $meta->can('mymetaclass_attributes'),
'... meta can do method after immutable' );
isnt( Scalar::Util::blessed( Baz->meta ),
Scalar::Util::blessed( Bar->meta ),
'Baz and
or');
is($point->x, 2, '... the x attribute was initialized correctly through the metaobject');
isnt( exception {
$point->x(42);
}, undef, '... cannot write to a read-only accessor' );
is($point