From: gfx Date: Sat, 24 Oct 2009 08:16:46 +0000 (+0900) Subject: Move ::Meta::Module::namespace into XS X-Git-Tag: 0.40_01~28 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=2591e962421f07deae90d93875aa129c57d841af;p=gitmo%2FMouse.git Move ::Meta::Module::namespace into XS --- diff --git a/lib/Mouse/Meta/Module.pm b/lib/Mouse/Meta/Module.pm index 9f2c7f8..383f51d 100755 --- a/lib/Mouse/Meta/Module.pm +++ b/lib/Mouse/Meta/Module.pm @@ -38,9 +38,10 @@ sub get_metaclass_by_name { $METAS{$_[0]} } #sub does_metaclass_exist { defined $METAS{$_[0]} } #sub remove_metaclass_by_name { delete $METAS{$_[0]} } - sub name; +sub namespace; + # The followings are Class::MOP specific methods #sub version { no strict 'refs'; ${shift->name.'::VERSION'} } @@ -66,12 +67,6 @@ sub get_attribute { $_[0]->{attributes}->{$_[1]} } sub get_attribute_list{ keys %{$_[0]->{attributes}} } sub remove_attribute { delete $_[0]->{attributes}->{$_[1]} } -sub namespace{ - my $name = $_[0]->{package}; - no strict 'refs'; - return \%{ $name . '::' }; -} - sub add_method { my($self, $name, $code) = @_; diff --git a/lib/Mouse/PurePerl.pm b/lib/Mouse/PurePerl.pm index 23f7520..ea59be6 100644 --- a/lib/Mouse/PurePerl.pm +++ b/lib/Mouse/PurePerl.pm @@ -71,6 +71,12 @@ package sub name { $_[0]->{package} } +sub namespace{ + my $name = $_[0]->{package}; + no strict 'refs'; + return \%{ $name . '::' }; +} + package Mouse::Meta::Class; diff --git a/xs-src/Mouse.xs b/xs-src/Mouse.xs index d5e7842..4a00765 100644 --- a/xs-src/Mouse.xs +++ b/xs-src/Mouse.xs @@ -40,6 +40,19 @@ BOOT: INSTALL_SIMPLE_READER_WITH_KEY(Module, _method_map, methods); INSTALL_SIMPLE_READER_WITH_KEY(Module, _attribute_map, attributes); +HV* +namespace(HV* self) +CODE: +{ + SV** svp = hv_fetchs(self, "package", FALSE); + if(!(svp && SvOK(*svp))){ + croak("No package name"); + } + RETVAL = gv_stashsv(*svp, GV_ADDMULTI); +} +OUTPUT: + RETVAL + MODULE = Mouse PACKAGE = Mouse::Meta::Class BOOT: