From: Jesse Luehrs Date: Fri, 12 Nov 2010 05:08:45 +0000 (-0600) Subject: accessors X-Git-Tag: 0.14~64 X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?a=commitdiff_plain;h=194acf4760e6124a8787c2f1c6b7b76015ad5e33;p=gitmo%2FPackage-Stash-XS.git accessors --- diff --git a/Stash.xs b/Stash.xs index 879d7ac..9e4fdcd 100644 --- a/Stash.xs +++ b/Stash.xs @@ -24,3 +24,29 @@ new(class, package_name) RETVAL = sv_bless(newRV((SV*)instance), gv_stashpv(class, 0)); OUTPUT: RETVAL + +SV* +name(self) + SV *self + INIT: + SV **slot; + CODE: + if (!sv_isobject(self)) + croak("Can't call name as a class method"); + slot = hv_fetch((HV*)SvRV(self), "name", 4, 0); + RETVAL = slot ? SvREFCNT_inc(*slot) : &PL_sv_undef; + OUTPUT: + RETVAL + +SV* +namespace(self) + SV *self + INIT: + SV **slot; + CODE: + if (!sv_isobject(self)) + croak("Can't call namespace as a class method"); + slot = hv_fetch((HV*)SvRV(self), "namespace", 9, 0); + RETVAL = slot ? SvREFCNT_inc(*slot) : &PL_sv_undef; + OUTPUT: + RETVAL diff --git a/lib/Package/Stash.pm b/lib/Package/Stash.pm index 871889a..8e76abf 100644 --- a/lib/Package/Stash.pm +++ b/lib/Package/Stash.pm @@ -45,28 +45,16 @@ a sigil. If this sigil is absent, it is assumed to represent the IO slot. Creates a new C object, for the package given as the only argument. -=cut - =method name Returns the name of the package that this object represents. -=cut - -sub name { - return $_[0]->{name}; -} - =method namespace Returns the raw stash itself. =cut -sub namespace { - return $_[0]->{namespace}; -} - { my %SIGIL_MAP = ( '$' => 'SCALAR',