X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=gitmo%2FMouse.git;a=blobdiff_plain;f=t%2F100-meta-class.t;h=7a921bb34e034b98c0bc70c8f0e266346151f7c8;hp=264a81ec5c7b5b71174c45123d49d9bf8f80d958;hb=8e64d0fa5da64639074f77d3da9b2f7aa20cce93;hpb=381465145a9d0e9813f7b74a08b590c011ca3de3 diff --git a/t/100-meta-class.t b/t/100-meta-class.t index 264a81e..7a921bb 100644 --- a/t/100-meta-class.t +++ b/t/100-meta-class.t @@ -1,19 +1,38 @@ #!/usr/bin/env perl use strict; use warnings; -use Test::More tests => 15; - -do { +use Test::More tests => 22; +use Test::Exception; +{ package Class; use Mouse; + use Scalar::Util qw(blessed weaken); # import external functions has pawn => ( is => 'rw', predicate => 'has_pawn', ); + use constant MY_CONST => 42; + + sub stub; + sub stub_with_attr :method; + no Mouse; -}; +} +{ + package Child; + use Mouse; + use Carp qw(carp croak); # import extenral functions + + extends 'Class'; + + has bishop => ( + is => 'rw', + ); + + sub child_method{ } +} my $meta = Class->meta; isa_ok($meta, 'Mouse::Meta::Class'); @@ -23,37 +42,44 @@ is_deeply([$meta->superclasses], ['Mouse::Object'], "correctly inherting from Mo my $meta2 = Class->meta; is($meta, $meta2, "same metaclass instance"); -can_ok($meta, 'name', 'get_attribute_map', 'get_attribute_list'); +can_ok($meta, qw( + name meta + has_attribute get_attribute get_attribute_list get_all_attributes + has_method get_method get_method_list get_all_methods +)); ok($meta->has_attribute('pawn')); my $attr = $meta->get_attribute('pawn'); isa_ok($attr, 'Mouse::Meta::Attribute'); is($attr->name, 'pawn', 'got the correct attribute'); -my $map = $meta->get_attribute_map; -is_deeply($map, { pawn => $attr }, "attribute map"); - my $list = [$meta->get_attribute_list]; is_deeply($list, [ 'pawn' ], "attribute list"); ok(!$meta->has_attribute('nonexistent_attribute')); -eval " +ok($meta->has_method('pawn')); +lives_and{ + ok($meta->get_method('pawn')); + is($meta->get_method('pawn')->name, 'pawn'); + is($meta->get_method('pawn')->package_name, 'Class'); +}; + +is( join(' ', sort $meta->get_method_list), + join(' ', sort qw(meta pawn has_pawn MY_CONST stub stub_with_attr)) +); + +eval q{ package Class; use Mouse; no Mouse; -"; +}; my $meta3 = Class->meta; is($meta, $meta3, "same metaclass instance, even if use Mouse is performed again"); is($meta->name, 'Class', "name for the metaclass"); -do { - package Child; - use Mouse; - extends 'Class'; -}; my $child_meta = Child->meta; isa_ok($child_meta, 'Mouse::Meta::Class'); @@ -61,3 +87,12 @@ isa_ok($child_meta, 'Mouse::Meta::Class'); isnt($meta, $child_meta, "different metaclass instances for the two classes"); is_deeply([$child_meta->superclasses], ['Class'], "correct superclasses"); + + +ok($child_meta->has_attribute('bishop')); +ok($child_meta->has_method('child_method')); + + +is( join(' ', sort $child_meta->get_method_list), + join(' ', sort qw(meta bishop child_method)) +);