From 194acf4760e6124a8787c2f1c6b7b76015ad5e33 Mon Sep 17 00:00:00 2001 From: Jesse Luehrs Date: Thu, 11 Nov 2010 23:08:45 -0600 Subject: accessors --- Stash.xs | 26 ++++++++++++++++++++++++++ lib/Package/Stash.pm | 12 ------------ 2 files changed, 26 insertions(+), 12 deletions(-) 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', -- cgit v1.2.3-54-g00ecf