From: gfx Date: Thu, 13 Aug 2009 02:02:32 +0000 (+0900) Subject: Fix tests and others X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=defca36264614322a19aaa7a337ee89bd6de4ee8;p=gitmo%2FClass-MOP.git Fix tests and others --- diff --git a/lib/Class/MOP.pm b/lib/Class/MOP.pm index 5a16bff..cc2419c 100644 --- a/lib/Class/MOP.pm +++ b/lib/Class/MOP.pm @@ -219,42 +219,6 @@ Class::MOP::Package->meta->add_attribute( )) ); -Class::MOP::Package->meta->add_attribute( - Class::MOP::Attribute->new('methods' => ( - reader => { - # NOTE: - # we just alias the original method - # rather than re-produce it here - 'get_method_map' => \&Class::MOP::Package::get_method_map - }, - default => sub { {} } - )) -); - -Class::MOP::Package->meta->add_attribute( - Class::MOP::Attribute->new('method_metaclass' => ( - reader => { - # NOTE: - # we just alias the original method - # rather than re-produce it here - 'method_metaclass' => \&Class::MOP::Package::method_metaclass - }, - default => 'Class::MOP::Method', - )) -); - -Class::MOP::Package->meta->add_attribute( - Class::MOP::Attribute->new('wrapped_method_metaclass' => ( - reader => { - # NOTE: - # we just alias the original method - # rather than re-produce it here - 'wrapped_method_metaclass' => \&Class::MOP::Package::wrapped_method_metaclass - }, - default => 'Class::MOP::Method::Wrapped', - )) -); - ## -------------------------------------------------------- ## Class::MOP::Module @@ -300,6 +264,42 @@ Class::MOP::Module->meta->add_attribute( )) ); +Class::MOP::Module->meta->add_attribute( + Class::MOP::Attribute->new('methods' => ( + reader => { + # NOTE: + # we just alias the original method + # rather than re-produce it here + 'get_method_map' => \&Class::MOP::Module::get_method_map + }, + default => sub { {} } + )) +); + +Class::MOP::Module->meta->add_attribute( + Class::MOP::Attribute->new('method_metaclass' => ( + reader => { + # NOTE: + # we just alias the original method + # rather than re-produce it here + 'method_metaclass' => \&Class::MOP::Module::method_metaclass + }, + default => 'Class::MOP::Method', + )) +); + +Class::MOP::Module->meta->add_attribute( + Class::MOP::Attribute->new('wrapped_method_metaclass' => ( + reader => { + # NOTE: + # we just alias the original method + # rather than re-produce it here + 'wrapped_method_metaclass' => \&Class::MOP::Module::wrapped_method_metaclass + }, + default => 'Class::MOP::Method::Wrapped', + )) +); + ## -------------------------------------------------------- ## Class::MOP::Class diff --git a/t/010_self_introspection.t b/t/010_self_introspection.t index e810852..b1bf7b6 100644 --- a/t/010_self_introspection.t +++ b/t/010_self_introspection.t @@ -161,14 +161,15 @@ foreach my $non_method_name (qw( my @class_mop_package_attributes = ( 'package', 'namespace', - 'methods', - 'method_metaclass', - 'wrapped_method_metaclass', ); my @class_mop_module_attributes = ( 'version', - 'authority' + 'authority', + + 'methods', + 'method_metaclass', + 'wrapped_method_metaclass', ); my @class_mop_class_attributes = ( @@ -244,35 +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'); +# ... module + +ok($class_mop_module_meta->get_attribute('method_metaclass')->has_reader, '... Class::MOP::Module method_metaclass has a reader'); +is_deeply($class_mop_module_meta->get_attribute('method_metaclass')->reader, + { 'method_metaclass' => \&Class::MOP::Module::method_metaclass }, + '... Class::MOP::Module 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, +ok($class_mop_module_meta->get_attribute('method_metaclass')->has_init_arg, '... Class::MOP::Module method_metaclass has a init_arg'); +is($class_mop_module_meta->get_attribute('method_metaclass')->init_arg, 'method_metaclass', - '... Class::MOP::Package method_metaclass\'s init_arg is method_metaclass'); + '... Class::MOP::Module 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, +ok($class_mop_module_meta->get_attribute('method_metaclass')->has_default, '... Class::MOP::Module method_metaclass has a default'); +is($class_mop_module_meta->get_attribute('method_metaclass')->default, 'Class::MOP::Method', - '... Class::MOP::Package method_metaclass\'s a default is Class::MOP:::Method'); + '... Class::MOP::Module 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_module_meta->get_attribute('wrapped_method_metaclass')->has_reader, '... Class::MOP::Module wrapped_method_metaclass has a reader'); +is_deeply($class_mop_module_meta->get_attribute('wrapped_method_metaclass')->reader, + { 'wrapped_method_metaclass' => \&Class::MOP::Module::wrapped_method_metaclass }, + '... Class::MOP::Module 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, +ok($class_mop_module_meta->get_attribute('wrapped_method_metaclass')->has_init_arg, '... Class::MOP::Module wrapped_method_metaclass has a init_arg'); +is($class_mop_module_meta->get_attribute('wrapped_method_metaclass')->init_arg, 'wrapped_method_metaclass', - '... Class::MOP::Package wrapped_method_metaclass\'s init_arg is wrapped_method_metaclass'); + '... Class::MOP::Module 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, +ok($class_mop_module_meta->get_attribute('method_metaclass')->has_default, '... Class::MOP::Module method_metaclass has a default'); +is($class_mop_module_meta->get_attribute('method_metaclass')->default, 'Class::MOP::Method', - '... Class::MOP::Package method_metaclass\'s a default is Class::MOP:::Method'); + '... Class::MOP::Module method_metaclass\'s a default is Class::MOP:::Method'); # ... class diff --git a/xs/Module.xs b/xs/Module.xs index 6908087..30168bb 100755 --- a/xs/Module.xs +++ b/xs/Module.xs @@ -82,37 +82,6 @@ MODULE = Class::MOP::Module PACKAGE = Class::MOP::Module PROTOTYPES: DISABLE void -get_all_package_symbols(self, filter=TYPE_FILTER_NONE) - SV *self - type_filter_t filter - PREINIT: - HV *stash = NULL; - HV *symbols = NULL; - register HE *he; - PPCODE: - if ( ! SvROK(self) ) { - die("Cannot call get_all_package_symbols as a class method"); - } - - if (GIMME_V == G_VOID) { - XSRETURN_EMPTY; - } - - PUTBACK; - - if ( (he = hv_fetch_ent((HV *)SvRV(self), KEY_FOR(package), 0, HASH_FOR(package))) ) { - stash = gv_stashsv(HeVAL(he), 0); - } - - - if (!stash) { - XSRETURN_UNDEF; - } - - symbols = mop_get_all_package_symbols(stash, filter); - PUSHs(sv_2mortal(newRV_noinc((SV *)symbols))); - -void get_method_map(self) SV *self PREINIT: diff --git a/xs/Package.xs b/xs/Package.xs index 6c47099..5ee9c6b 100644 --- a/xs/Package.xs +++ b/xs/Package.xs @@ -6,3 +6,35 @@ PROTOTYPES: DISABLE BOOT: INSTALL_SIMPLE_READER_WITH_KEY(Package, name, package); + + +void +get_all_package_symbols(self, filter=TYPE_FILTER_NONE) + SV *self + type_filter_t filter + PREINIT: + HV *stash = NULL; + HV *symbols = NULL; + register HE *he; + PPCODE: + if ( ! SvROK(self) ) { + die("Cannot call get_all_package_symbols as a class method"); + } + + if (GIMME_V == G_VOID) { + XSRETURN_EMPTY; + } + + PUTBACK; + + if ( (he = hv_fetch_ent((HV *)SvRV(self), KEY_FOR(package), 0, HASH_FOR(package))) ) { + stash = gv_stashsv(HeVAL(he), 0); + } + + + if (!stash) { + XSRETURN_UNDEF; + } + + symbols = mop_get_all_package_symbols(stash, filter); + PUSHs(sv_2mortal(newRV_noinc((SV *)symbols)));