From: Stevan Little Date: Fri, 30 Jun 2006 00:29:21 +0000 (+0000) Subject: foo X-Git-Tag: 0_33~27 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=7f436b8c244d791e254b49668ac2b6d5218314e4;p=gitmo%2FClass-MOP.git foo --- diff --git a/lib/Class/MOP/Class.pm b/lib/Class/MOP/Class.pm index 7fe62f1..b6fd7f1 100644 --- a/lib/Class/MOP/Class.pm +++ b/lib/Class/MOP/Class.pm @@ -275,16 +275,6 @@ sub clone_instance { return $clone; } -# Informational - -# &name should be here too, but it is above -# because it gets bootstrapped away - -sub version { - my $self = shift; - ${$self->get_package_variable('$VERSION')}; -} - # Inheritance sub superclasses { diff --git a/lib/Class/MOP/Module.pm b/lib/Class/MOP/Module.pm index 1776d13..8bf93b0 100644 --- a/lib/Class/MOP/Module.pm +++ b/lib/Class/MOP/Module.pm @@ -17,6 +17,11 @@ sub meta { Class::MOP::Class->initialize(blessed($_[0]) || $_[0]); } +sub version { + my $self = shift; + ${$self->get_package_variable('$VERSION')}; +} + 1; __END__ @@ -37,6 +42,8 @@ Class::MOP::Module - Module Meta Object =item B +=item B + =back =head1 AUTHOR diff --git a/lib/Class/MOP/Package.pm b/lib/Class/MOP/Package.pm index 18c1d14..fb37c78 100644 --- a/lib/Class/MOP/Package.pm +++ b/lib/Class/MOP/Package.pm @@ -109,22 +109,22 @@ sub remove_package_variable { (exists $SIGIL_MAP{$sigil}) || confess "I do not recognize that sigil '$sigil'"; - no strict 'refs'; - if ($SIGIL_MAP{$sigil} eq 'SCALAR') { - undef ${$self->name . '::' . $name}; - } - elsif ($SIGIL_MAP{$sigil} eq 'ARRAY') { - undef @{$self->name . '::' . $name}; - } - elsif ($SIGIL_MAP{$sigil} eq 'HASH') { - undef %{$self->name . '::' . $name}; - } - elsif ($SIGIL_MAP{$sigil} eq 'CODE') { - undef &{$self->name . '::' . $name}; - } - else { - confess "This should never ever ever happen"; - } + no strict 'refs'; + if ($SIGIL_MAP{$sigil} eq 'SCALAR') { + undef ${$self->name . '::' . $name}; + } + elsif ($SIGIL_MAP{$sigil} eq 'ARRAY') { + undef @{$self->name . '::' . $name}; + } + elsif ($SIGIL_MAP{$sigil} eq 'HASH') { + undef %{$self->name . '::' . $name}; + } + elsif ($SIGIL_MAP{$sigil} eq 'CODE') { + undef &{$self->name . '::' . $name}; + } + else { + confess "This should never ever ever happen"; + } } diff --git a/t/010_self_introspection.t b/t/010_self_introspection.t index ae74079..222db9f 100644 --- a/t/010_self_introspection.t +++ b/t/010_self_introspection.t @@ -3,7 +3,7 @@ use strict; use warnings; -use Test::More tests => 164; +use Test::More tests => 169; use Test::Exception; BEGIN { @@ -38,6 +38,9 @@ my @class_mop_package_methods = qw( ); my @class_mop_module_methods = qw( + meta + + version ); my @class_mop_class_methods = qw( @@ -52,8 +55,6 @@ 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 @@ -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