Class::MOP - lots of knot tying, this should make subclassing more reliable and strai...
[gitmo/Class-MOP.git] / t / 010_self_introspection.t
CommitLineData
a5eca695 1#!/usr/bin/perl
2
3use strict;
4use warnings;
5
6use Test::More no_plan => 1;
7use Test::Exception;
8
9BEGIN {
727919c5 10 use_ok('Class::MOP');
a5eca695 11 use_ok('Class::MOP::Class');
12}
13
2eb717d5 14my $meta = Class::MOP::Class->meta();
a5eca695 15isa_ok($meta, 'Class::MOP::Class');
16
17foreach my $method_name (qw(
2eb717d5 18 meta
19
a5eca695 20 initialize create
552e3d24 21
a5eca695 22 name version
552e3d24 23
a5eca695 24 superclasses class_precedence_list
552e3d24 25
a5eca695 26 has_method get_method add_method remove_method
27 get_method_list compute_all_applicable_methods find_all_methods_by_name
552e3d24 28
29 has_attribute get_attribute add_attribute remove_attribute
2eb717d5 30 get_attribute_list compute_all_applicable_attributes
a5eca695 31 )) {
32 ok($meta->has_method($method_name), '... Class::MOP::Class->has_method(' . $method_name . ')');
33 {
34 no strict 'refs';
35 is($meta->get_method($method_name),
36 \&{'Class::MOP::Class::' . $method_name},
37 '... Class::MOP::Class->get_method(' . $method_name . ') == &Class::MOP::Class::' . $method_name);
38 }
39}
40
2eb717d5 41foreach my $non_method_name (qw(
42 confess
43 blessed reftype
44 subname
45 svref_2object
46 )) {
47 ok(!$meta->has_method($non_method_name), '... NOT Class::MOP::Class->has_method(' . $non_method_name . ')');
48}
49
727919c5 50foreach my $attribute_name (
51 '$:pkg', '%:attrs'
52 ) {
53 ok($meta->has_attribute($attribute_name), '... Class::MOP::Class->has_attribute(' . $attribute_name . ')');
54 isa_ok($meta->get_attribute($attribute_name), 'Class::MOP::Attribute');
55}
56
a5eca695 57is($meta->name, 'Class::MOP::Class', '... Class::MOP::Class->name');
58is($meta->version, $Class::MOP::Class::VERSION, '... Class::MOP::Class->version');
59
60is_deeply(
61 [ $meta->superclasses ],
62 [],
63 '... Class::MOP::Class->superclasses == []');
64
65is_deeply(
66 [ $meta->class_precedence_list ],
67 [ 'Class::MOP::Class' ],
68 '... Class::MOP::Class->class_precedence_list == []');
69