There are several problems with your code. As others have said, you're returning one array-ref instead of two scalars, which accounts for your test failures. But there are also some more subtle problems which could cause core dumps if the caller does something wrong. I would write it as:
MODULE = My::Games::Azure::Unit PACKAGE = My::Games::Azure::Unit
SV **x, **y;
x = hv_fetch( self, "x", 1, 0 );
y = hv_fetch( self, "y", 1, 0 );
PUSHs(x ? *x : &PL_sv_undef);
PUSHs(y ? *y : &PL_sv_undef);
The things to notice are:
- The self parameter is declared as an HV*, which causes the XS wrapper to issue automatic conversion and type checking code, so you'll get an error if someone accidentally calls it as My::Games::Azure::Unit->world_location() or whatever.
- The SV** pointers returned by hv_fetch() are tested to see if they're null (which they will be if the hash entry doesnt exist). In that case we just return undef. Otherwise you risk a core dump again.