Docs, small fixes, find_method_by_name and the get_value/set_value abstraction for...
[gitmo/Class-MOP.git] / t / 010_self_introspection.t
index ae74079..018b7c2 100644 (file)
@@ -3,7 +3,7 @@
 use strict;
 use warnings;
 
-use Test::More tests => 164;
+use Test::More tests => 171;
 use Test::Exception;
 
 BEGIN {
@@ -34,10 +34,13 @@ my @class_mop_package_methods = qw(
 
     name
     
-    add_package_variable get_package_variable has_package_variable remove_package_variable    
+    add_package_symbol get_package_symbol has_package_symbol remove_package_symbol    
 );
 
 my @class_mop_module_methods = qw(
+    meta 
+
+    version
 );
 
 my @class_mop_class_methods = qw(
@@ -52,15 +55,13 @@ my @class_mop_class_methods = qw(
     construct_instance construct_class_instance clone_instance
     check_metaclass_compatability
     
-    version
-    
     attribute_metaclass method_metaclass
     
     superclasses class_precedence_list
     
     has_method get_method add_method remove_method alias_method
     get_method_list compute_all_applicable_methods 
-       find_all_methods_by_name find_next_method_by_name
+       find_method_by_name find_all_methods_by_name find_next_method_by_name
     
        add_before_method_modifier add_after_method_modifier add_around_method_modifier
 
@@ -70,7 +71,7 @@ my @class_mop_class_methods = qw(
     is_mutable is_immutable make_immutable
     
     DESTROY
-    );
+);
     
 # check the class ...    
     
@@ -100,6 +101,21 @@ foreach my $method_name (@class_mop_package_methods) {
     }
 }
 
+## check the module ....
+
+is_deeply([ sort @class_mop_module_methods ], [ sort $class_mop_module_meta->get_method_list ], '... got the correct method list for module');
+
+foreach my $method_name (@class_mop_module_methods) {
+    ok($class_mop_module_meta->has_method($method_name), '... Class::MOP::Module->has_method(' . $method_name . ')');
+    {
+        no strict 'refs';
+        is($class_mop_module_meta->get_method($method_name), 
+           \&{'Class::MOP::Module::' . $method_name},
+           '... Class::MOP::Module->get_method(' . $method_name . ') == &Class::MOP::Module::' . $method_name);        
+    }
+}
+
+
 # check for imported functions which are not methods
 
 foreach my $non_method_name (qw(
@@ -144,7 +160,7 @@ foreach my $attribute_name (@class_mop_class_attributes) {
     isa_ok($class_mop_class_meta->get_attribute($attribute_name), 'Class::MOP::Attribute');            
 }
 
-# check package 
+# check module
 
 is_deeply(
     [ sort @class_mop_package_attributes ],
@@ -161,6 +177,23 @@ foreach my $attribute_name (@class_mop_package_attributes) {
     isa_ok($class_mop_package_meta->get_attribute($attribute_name), 'Class::MOP::Attribute');            
 }
 
+# check package 
+
+is_deeply(
+    [ sort @class_mop_module_attributes ],
+    [ sort $class_mop_module_meta->get_attribute_list ],
+    '... got the right list of attributes');
+    
+is_deeply(
+    [ sort @class_mop_module_attributes ],
+    [ sort keys %{$class_mop_module_meta->get_attribute_map} ],
+    '... got the right list of attributes');    
+
+foreach my $attribute_name (@class_mop_module_attributes) {
+    ok($class_mop_module_meta->has_attribute($attribute_name), '... Class::MOP::Module->has_attribute(' . $attribute_name . ')');        
+    isa_ok($class_mop_module_meta->get_attribute($attribute_name), 'Class::MOP::Attribute');            
+}
+
 ## check the attributes themselves
 
 # ... package
@@ -184,7 +217,7 @@ is($class_mop_class_meta->get_attribute('%:attributes')->init_arg,
   '... Class::MOP::Class %:attributes\'s a init_arg is :attributes');   
   
 ok($class_mop_class_meta->get_attribute('%:attributes')->has_default, '... Class::MOP::Class %:attributes has a default');
-is_deeply($class_mop_class_meta->get_attribute('%:attributes')->default, 
+is_deeply($class_mop_class_meta->get_attribute('%:attributes')->default('Foo'), 
          {}, 
          '... Class::MOP::Class %:attributes\'s a default of {}');  
 
@@ -223,10 +256,10 @@ is($class_mop_class_meta->get_attribute('$:method_metaclass')->default,
 is($class_mop_class_meta->name, 'Class::MOP::Class', '... Class::MOP::Class->name');
 is($class_mop_class_meta->version, $Class::MOP::Class::VERSION, '... Class::MOP::Class->version');
 
-ok($class_mop_class_meta->has_package_variable('$VERSION'), '... Class::MOP::Class->has_package_variable($VERSION)');
-is(${$class_mop_class_meta->get_package_variable('$VERSION')}, 
+ok($class_mop_class_meta->has_package_symbol('$VERSION'), '... Class::MOP::Class->has_package_symbol($VERSION)');
+is(${$class_mop_class_meta->get_package_symbol('$VERSION')}, 
    $Class::MOP::Class::VERSION, 
-   '... Class::MOP::Class->get_package_variable($VERSION)');
+   '... Class::MOP::Class->get_package_symbol($VERSION)');
 
 is_deeply(
     [ $class_mop_class_meta->superclasses ],