[Templates-cvs] cvs commit: Template2/xs Stash.xs
cvs@template-toolkit.org
cvs@template-toolkit.org
cvs 06/05/14 08:40:42
Modified: xs Stash.xs
Log:
* added looks_private() to encapsulate test for _private or .hidden vars
Revision Changes Path
1.21 +26 -4 Template2/xs/Stash.xs
Index: Stash.xs
===================================================================
RCS file: /template-toolkit/Template2/xs/Stash.xs,v
retrieving revision 1.20
retrieving revision 1.21
diff -u -r1.20 -r1.21
--- Stash.xs 2006/02/10 10:53:54 1.20
+++ Stash.xs 2006/05/14 08:40:42 1.21
@@ -26,7 +26,7 @@
*
*---------------------------------------------------------------------
*
-* $Id: Stash.xs,v 1.20 2006/02/10 10:53:54 abw Exp $
+* $Id: Stash.xs,v 1.21 2006/05/14 08:40:42 abw Exp $
*
*=====================================================================*/
@@ -55,6 +55,7 @@
#define TT_LIST_OPS "Template::Stash::LIST_OPS"
#define TT_HASH_OPS "Template::Stash::HASH_OPS"
#define TT_SCALAR_OPS "Template::Stash::SCALAR_OPS"
+#define TT_PRIVATE "Template::Stash::PRIVATE"
#define TT_LVALUE_FLAG 1
#define TT_DEBUG_FLAG 2
@@ -75,6 +76,7 @@
static AV* convert_dotted_string(pTHX_ const char*, I32);
static int get_debug_flag(pTHX_ SV*);
static int cmp_arg(const void *, const void *);
+static int looks_private(pTHX_ const char*);
static void die_object(pTHX_ SV *);
static struct xs_arg *find_xs_op(char *);
static SV* list_dot_first(pTHX_ AV*, AV*);
@@ -89,7 +91,7 @@
static SV* scalar_dot_defined(pTHX_ SV*, AV*);
static SV* scalar_dot_length(pTHX_ SV*, AV*);
-static char rcsid[] = "$Id: Stash.xs,v 1.20 2006/02/10 10:53:54 abw Exp $";
+static char rcsid[] = "$Id: Stash.xs,v 1.21 2006/05/14 08:40:42 abw Exp $";
#define THROW_SIZE 64
static char throw_fmt[] = "Can't locate object method \"%s\" via package \"%s\"";
@@ -195,7 +197,7 @@
debug("dotop(%s)\n", item);
/* ignore _private or .private members */
- if (!root || *item == '_' || *item == '.')
+ if (!root || looks_private(aTHX_ item))
return &PL_sv_undef;
if (SvROK(root)) {
@@ -465,7 +467,7 @@
debug("assign(%s)\n", key2);
- if (!root || !key_len || *key == '_' || *key == '.') {
+ if (!root || !key_len || looks_private(aTHX_ key)) {
/* ignore _private or .private members */
return &PL_sv_undef;
}
@@ -939,6 +941,26 @@
&& SvTRUE(*debug))
return TT_DEBUG_FLAG;
+ return 0;
+}
+
+
+static int looks_private(pTHX_ const char *name) {
+ SV *priv;
+
+ /* For now we hard-code the regex to match _private or .hidden
+ * variables, but we do check to see if $Template::Stash::PRIVATE
+ * is defined, allowing a user to undef it to defeat the check.
+ * The better solution would be to match the string using the regex
+ * defined in the $PRIVATE package varible, but I've been searching
+ * for well over an hour now and I can't find any documentation or
+ * examples showing me how to match a string against a pre-compiled
+ * regex from XS. The Perl internals docs really suck in places.
+ */
+
+ if (SvTRUE(perl_get_sv(TT_PRIVATE, FALSE))) {
+ return (*name == '_' || *name == '.');
+ }
return 0;
}