Include method name in immutable methods (fixes #49680)
[gitmo/Class-MOP.git] / t / 010_self_introspection.t
index 748500d..0c45fd2 100644 (file)
@@ -1,9 +1,7 @@
-#!/usr/bin/perl
-
 use strict;
 use warnings;
 
-use Test::More tests => 232;
+use Test::More tests => 302;
 use Test::Exception;
 
 use Class::MOP;
@@ -36,13 +34,22 @@ my @class_mop_package_methods = qw(
     add_package_symbol get_package_symbol has_package_symbol remove_package_symbol
     list_all_package_symbols get_all_package_symbols remove_package_glob
 
+    method_metaclass wrapped_method_metaclass
+
+    _method_map
+    _code_is_mine
+    has_method get_method add_method remove_method wrap_method_body
+    get_method_list get_method_map
+
     _deconstruct_variable_name
 );
 
 my @class_mop_module_methods = qw(
     _new
 
-    version authority identifier
+    _instantiate_module
+
+    version authority identifier create
 );
 
 my @class_mop_class_methods = qw(
@@ -57,23 +64,25 @@ my @class_mop_class_methods = qw(
 
     create_anon_class is_anon_class
 
-    instance_metaclass get_meta_instance create_meta_instance
+    instance_metaclass get_meta_instance
+    create_meta_instance _create_meta_instance
     new_object clone_object
-    construct_instance construct_class_instance clone_instance
-    rebless_instance
-    check_metaclass_compatibility
-    check_metaclass_compatability
+    construct_instance _construct_instance
+    construct_class_instance _construct_class_instance
+    clone_instance _clone_instance
+    rebless_instance rebless_instance_away
+    check_metaclass_compatibility _check_metaclass_compatibility
 
-    add_meta_instance_dependencies remove_meta_instance_depdendencies update_meta_instance_dependencies
+    add_meta_instance_dependencies remove_meta_instance_dependencies update_meta_instance_dependencies
     add_dependent_meta_instance remove_dependent_meta_instance
     invalidate_meta_instances invalidate_meta_instance
 
-    attribute_metaclass method_metaclass
+    attribute_metaclass
 
-    superclasses subclasses class_precedence_list linearized_isa
+    superclasses subclasses direct_subclasses class_precedence_list
+    linearized_isa _superclasses_updated
 
-    has_method get_method add_method remove_method alias_method wrap_method_body
-    get_method_list get_method_map get_all_methods compute_all_applicable_methods
+    alias_method get_all_method_names get_all_methods compute_all_applicable_methods
         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
@@ -81,17 +90,24 @@ my @class_mop_class_methods = qw(
     has_attribute get_attribute add_attribute remove_attribute
     get_attribute_list get_attribute_map get_all_attributes compute_all_applicable_attributes find_attribute_by_name
 
-    is_mutable is_immutable make_mutable make_immutable create_immutable_transformer
-    get_immutable_options get_immutable_transformer
+    is_mutable is_immutable make_mutable make_immutable
+    _initialize_immutable _install_inlined_code _inlined_methods
+    _add_inlined_method _inline_accessors _inline_constructor
+    _inline_destructor _immutable_options _rebless_as_immutable
+    _rebless_as_mutable _remove_inlined_code
+
+    _immutable_metaclass
+    immutable_trait immutable_options
+    constructor_name constructor_class destructor_class
 
     DESTROY
 );
 
 # check the class ...
 
-is_deeply([ sort @class_mop_class_methods ], [ sort $class_mop_class_meta->get_method_list ], '... got the correct method list for class');
+is_deeply([ sort $class_mop_class_meta->get_method_list ], [ sort @class_mop_class_methods ], '... got the correct method list for class');
 
-foreach my $method_name (@class_mop_class_methods) {
+foreach my $method_name (sort @class_mop_class_methods) {
     ok($class_mop_class_meta->has_method($method_name), '... Class::MOP::Class->has_method(' . $method_name . ')');
     {
         no strict 'refs';
@@ -103,9 +119,9 @@ foreach my $method_name (@class_mop_class_methods) {
 
 ## check the package ....
 
-is_deeply([ sort @class_mop_package_methods ], [ sort $class_mop_package_meta->get_method_list ], '... got the correct method list for package');
+is_deeply([ sort $class_mop_package_meta->get_method_list ], [ sort @class_mop_package_methods ], '... got the correct method list for package');
 
-foreach my $method_name (@class_mop_package_methods) {
+foreach my $method_name (sort @class_mop_package_methods) {
     ok($class_mop_package_meta->has_method($method_name), '... Class::MOP::Package->has_method(' . $method_name . ')');
     {
         no strict 'refs';
@@ -117,9 +133,9 @@ 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');
+is_deeply([ sort $class_mop_module_meta->get_method_list ], [ sort @class_mop_module_methods ], '... got the correct method list for module');
 
-foreach my $method_name (@class_mop_module_methods) {
+foreach my $method_name (sort @class_mop_module_methods) {
     ok($class_mop_module_meta->has_method($method_name), '... Class::MOP::Module->has_method(' . $method_name . ')');
     {
         no strict 'refs';
@@ -146,6 +162,9 @@ foreach my $non_method_name (qw(
 my @class_mop_package_attributes = (
     'package',
     'namespace',
+    'methods',
+    'method_metaclass',
+    'wrapped_method_metaclass',
 );
 
 my @class_mop_module_attributes = (
@@ -155,26 +174,29 @@ my @class_mop_module_attributes = (
 
 my @class_mop_class_attributes = (
     'superclasses',
-    'methods',
     'attributes',
     'attribute_metaclass',
-    'method_metaclass',
-    'instance_metaclass'
+    'instance_metaclass',
+    'immutable_trait',
+    'constructor_name',
+    'constructor_class',
+    'destructor_class',
 );
 
 # check class
 
 is_deeply(
-    [ sort @class_mop_class_attributes ],
     [ sort $class_mop_class_meta->get_attribute_list ],
-    '... got the right list of attributes');
+    [ sort @class_mop_class_attributes ],
+    '... got the right list of attributes'
+);
 
 is_deeply(
-    [ sort @class_mop_class_attributes ],
     [ sort keys %{$class_mop_class_meta->get_attribute_map} ],
+    [ sort @class_mop_class_attributes ],
     '... got the right list of attributes');
 
-foreach my $attribute_name (@class_mop_class_attributes) {
+foreach my $attribute_name (sort @class_mop_class_attributes) {
     ok($class_mop_class_meta->has_attribute($attribute_name), '... Class::MOP::Class->has_attribute(' . $attribute_name . ')');
     isa_ok($class_mop_class_meta->get_attribute($attribute_name), 'Class::MOP::Attribute');
 }
@@ -182,16 +204,16 @@ foreach my $attribute_name (@class_mop_class_attributes) {
 # check module
 
 is_deeply(
-    [ sort @class_mop_package_attributes ],
     [ sort $class_mop_package_meta->get_attribute_list ],
+    [ sort @class_mop_package_attributes ],
     '... got the right list of attributes');
 
 is_deeply(
-    [ sort @class_mop_package_attributes ],
     [ sort keys %{$class_mop_package_meta->get_attribute_map} ],
+    [ sort @class_mop_package_attributes ],
     '... got the right list of attributes');
 
-foreach my $attribute_name (@class_mop_package_attributes) {
+foreach my $attribute_name (sort @class_mop_package_attributes) {
     ok($class_mop_package_meta->has_attribute($attribute_name), '... Class::MOP::Package->has_attribute(' . $attribute_name . ')');
     isa_ok($class_mop_package_meta->get_attribute($attribute_name), 'Class::MOP::Attribute');
 }
@@ -199,16 +221,16 @@ foreach my $attribute_name (@class_mop_package_attributes) {
 # check package
 
 is_deeply(
-    [ sort @class_mop_module_attributes ],
     [ sort $class_mop_module_meta->get_attribute_list ],
+    [ sort @class_mop_module_attributes ],
     '... got the right list of attributes');
 
 is_deeply(
-    [ sort @class_mop_module_attributes ],
     [ sort keys %{$class_mop_module_meta->get_attribute_map} ],
+    [ sort @class_mop_module_attributes ],
     '... got the right list of attributes');
 
-foreach my $attribute_name (@class_mop_module_attributes) {
+foreach my $attribute_name (sort @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');
 }
@@ -223,6 +245,37 @@ is(ref($class_mop_package_meta->get_attribute('package')->reader), 'HASH', '...
 ok($class_mop_package_meta->get_attribute('package')->has_init_arg, '... Class::MOP::Class package has a init_arg');
 is($class_mop_package_meta->get_attribute('package')->init_arg, 'package', '... Class::MOP::Class package\'s a init_arg is package');
 
+ok($class_mop_package_meta->get_attribute('method_metaclass')->has_reader, '... Class::MOP::Package method_metaclass has a reader');
+is_deeply($class_mop_package_meta->get_attribute('method_metaclass')->reader,
+   { 'method_metaclass' => \&Class::MOP::Package::method_metaclass },
+   '... Class::MOP::Package method_metaclass\'s a reader is &method_metaclass');
+
+ok($class_mop_package_meta->get_attribute('method_metaclass')->has_init_arg, '... Class::MOP::Package method_metaclass has a init_arg');
+is($class_mop_package_meta->get_attribute('method_metaclass')->init_arg,
+  'method_metaclass',
+  '... Class::MOP::Package method_metaclass\'s init_arg is method_metaclass');
+
+ok($class_mop_package_meta->get_attribute('method_metaclass')->has_default, '... Class::MOP::Package method_metaclass has a default');
+is($class_mop_package_meta->get_attribute('method_metaclass')->default,
+   'Class::MOP::Method',
+  '... Class::MOP::Package method_metaclass\'s a default is Class::MOP:::Method');
+
+ok($class_mop_package_meta->get_attribute('wrapped_method_metaclass')->has_reader, '... Class::MOP::Package wrapped_method_metaclass has a reader');
+is_deeply($class_mop_package_meta->get_attribute('wrapped_method_metaclass')->reader,
+   { 'wrapped_method_metaclass' => \&Class::MOP::Package::wrapped_method_metaclass },
+   '... Class::MOP::Package wrapped_method_metaclass\'s a reader is &wrapped_method_metaclass');
+
+ok($class_mop_package_meta->get_attribute('wrapped_method_metaclass')->has_init_arg, '... Class::MOP::Package wrapped_method_metaclass has a init_arg');
+is($class_mop_package_meta->get_attribute('wrapped_method_metaclass')->init_arg,
+  'wrapped_method_metaclass',
+  '... Class::MOP::Package wrapped_method_metaclass\'s init_arg is wrapped_method_metaclass');
+
+ok($class_mop_package_meta->get_attribute('method_metaclass')->has_default, '... Class::MOP::Package method_metaclass has a default');
+is($class_mop_package_meta->get_attribute('method_metaclass')->default,
+   'Class::MOP::Method',
+  '... Class::MOP::Package method_metaclass\'s a default is Class::MOP:::Method');
+
+
 # ... class
 
 ok($class_mop_class_meta->get_attribute('attributes')->has_reader, '... Class::MOP::Class attributes has a reader');
@@ -255,21 +308,6 @@ is($class_mop_class_meta->get_attribute('attribute_metaclass')->default,
   'Class::MOP::Attribute',
   '... Class::MOP::Class attribute_metaclass\'s a default is Class::MOP:::Attribute');
 
-ok($class_mop_class_meta->get_attribute('method_metaclass')->has_reader, '... Class::MOP::Class method_metaclass has a reader');
-is_deeply($class_mop_class_meta->get_attribute('method_metaclass')->reader,
-   { 'method_metaclass' => \&Class::MOP::Class::method_metaclass },
-   '... Class::MOP::Class method_metaclass\'s a reader is &method_metaclass');
-
-ok($class_mop_class_meta->get_attribute('method_metaclass')->has_init_arg, '... Class::MOP::Class method_metaclass has a init_arg');
-is($class_mop_class_meta->get_attribute('method_metaclass')->init_arg,
-  'method_metaclass',
-  '... Class::MOP::Class method_metaclass\'s init_arg is method_metaclass');
-
-ok($class_mop_class_meta->get_attribute('method_metaclass')->has_default, '... Class::MOP::Class method_metaclass has a default');
-is($class_mop_class_meta->get_attribute('method_metaclass')->default,
-   'Class::MOP::Method',
-  '... Class::MOP::Class method_metaclass\'s a default is Class::MOP:::Method');
-
 # check the values of some of the methods
 
 is($class_mop_class_meta->name, 'Class::MOP::Class', '... Class::MOP::Class->name');