fix another edge case with initial values
Jesse Luehrs [Thu, 6 Jan 2011 05:05:37 +0000 (23:05 -0600)]
XS.xs
t/07-edge-cases.t
t/lib/CompileTime.pm [new file with mode: 0644]

diff --git a/XS.xs b/XS.xs
index a32ca45..b0519de 100644 (file)
--- a/XS.xs
+++ b/XS.xs
@@ -213,6 +213,10 @@ int _valid_for_type(SV *value, vartype_t type)
 
     switch (type) {
     case VAR_SCALAR:
+        /* XXX: something weird is going on here - apparently values can
+         * be SVt_NULL but also be SvROK (and also, SVt_NULL isn't SvOK) */
+        if (sv_type == SVt_NULL)
+            return 1;
         return SvROK(value) ? SvOK(SvRV(value)) : SvOK(value);
     case VAR_ARRAY:
         return sv_type == SVt_PVAV;
index 02e281b..4f61ca2 100755 (executable)
@@ -64,4 +64,6 @@ is(exception { $Bar->add_symbol('$foo', \$foo) }, undef,
 is(exception { $Bar->add_symbol('$bar', \$bar) }, undef,
    "can add PVNV values");
 
+use_ok('CompileTime');
+
 done_testing;
diff --git a/t/lib/CompileTime.pm b/t/lib/CompileTime.pm
new file mode 100644 (file)
index 0000000..925bc18
--- /dev/null
@@ -0,0 +1,15 @@
+package CompileTime;
+use strict;
+use warnings;
+
+use Package::Stash;
+
+our $foo = 23;
+
+BEGIN {
+    my $stash = Package::Stash->new(__PACKAGE__);
+    $stash->add_symbol('$bar', $foo);
+    $stash->add_symbol('$baz', $stash->get_symbol('$foo'));
+}
+
+1;