Sereal-Path
view release on metacpan or search on metacpan
Iterator/Iterator.xs view on Meta::CPAN
void
info(iter)
srl_iterator_t *iter;
PREINIT:
UV type;
UV length;
int blessed;
const char *classname;
STRLEN classname_length;
PPCODE:
type = srl_iterator_info(aTHX_ iter, &length, &classname, &classname_length);
blessed = (type & SRL_ITERATOR_INFO_BLESSED) == SRL_ITERATOR_INFO_BLESSED;
EXTEND(SP, blessed ? 3 : 2);
PUSHs(sv_2mortal(newSVuv(type)));
PUSHs(sv_2mortal(newSVuv(length)));
if (blessed) PUSHs(sv_2mortal(newSVpvn(classname, classname_length)));
IV
stack_depth(iter)
void
set(path, src)
srl_path_t *path;
SV *src;
CODE:
srl_path_set(aTHX_ path, src);
SV *
results(path)
srl_path_t *path;
PPCODE:
ST(0) = srl_path_results(aTHX_ path);
XSRETURN(1);
void
_traverse(path, expr, route)
srl_path_t *path;
SV *expr;
SV *route;
CODE:
if (SvTYPE(expr) != SVt_RV) croak("query mush be arrayref");
MODULE = Sereal::Path PACKAGE = Sereal::Path::_tests
SV *
is_range(src)
SV *src;
PREINIT:
AV *av;
STRLEN len;
int values[3];
const char *str;
PPCODE:
av = newAV();
ST(0) = newRV_noinc((SV*) av);
str = SvPV(src, len);
if (_is_range(str, len, (int*) &values)) {
av_push(av, newSViv(values[0]));
av_push(av, newSViv(values[1]));
av_push(av, newSViv(values[2]));
}
MODULE = Sereal::Path::Tie PACKAGE = Sereal::Path::Tie
PROTOTYPES: DISABLE
SV *
new(CLASS, src)
const char *CLASS;
SV *src
PREINIT:
srl_iterator_t *iter;
PPCODE:
if ( !sv_isobject(src)
|| !sv_isa(src, "Sereal::Path::Iterator")
|| SvTYPE(SvRV(src)) != SVt_PVMG)
{
warn("Sereal::Path::Iterator::new() -- src is not "
"a blessed 'Sereal::Path::Iterator' SV reference");
XSRETURN_UNDEF;
}
iter = INT2PTR(srl_iterator_t*, SvIV((SV*) SvRV(src)));
CODE:
if (this->store != NULL)
SvREFCNT_dec(this->store);
if (this->iter != NULL)
srl_destroy_iterator(aTHX_ this->iter);
Safefree(this);
void
FETCH(this)
sereal_iterator_tied_scalar_t *this;
PPCODE:
if (this->store == NULL) {
ST(0) = srl_tie_new_tied_sv(aTHX_ this->iter);
} else {
ST(0) = sv_2mortal(SvREFCNT_inc(this->store));
}
XSRETURN(1);
void
STORE(this, value)
srl_destroy_iterator(aTHX_ this->iter);
Safefree(this);
void
FETCH(this, key)
sereal_iterator_tied_array_t *this;
I32 key;
PREINIT:
IV idx;
SV **svptr;
PPCODE:
if (this->store != NULL && (svptr = av_fetch(this->store, key, 0)) != NULL) {
ST(0) = sv_2mortal(SvREFCNT_inc(*svptr));
XSRETURN(1);
}
idx = srl_iterator_array_exists(aTHX_ this->iter, key);
if (idx == SRL_ITER_NOT_FOUND) {
ST(0) = &PL_sv_undef;
} else {
srl_iterator_array_goto(aTHX_ this->iter, key);
}
XSRETURN(1);
void
FETCHSIZE(this)
sereal_iterator_tied_array_t *this;
PREINIT:
U32 len;
U32 avlen;
PPCODE:
avlen = (U32) (this->store != NULL ? av_len(this->store) + 1 : 0);
len = (avlen > this->count ? avlen : this->count);
ST(0) = sv_2mortal(newSVuv(len));
XSRETURN(1);
void
EXISTS(this, key)
sereal_iterator_tied_array_t *this;
I32 key;
PREINIT:
IV result;
PPCODE:
if (this->store != NULL && av_exists(this->store, (SSize_t) key) != 0) {
ST(0) = &PL_sv_yes;
XSRETURN(1);
}
result = srl_iterator_array_exists(aTHX_ this->iter, key);
ST(0) = (result == SRL_ITER_NOT_FOUND ? &PL_sv_undef : &PL_sv_yes);
XSRETURN(1);
void
Safefree(this);
void
FETCH(this, key)
sereal_iterator_tied_hash_t *this;
SV *key;
PREINIT:
HE *he;
const char *keyname;
STRLEN keyname_length;
PPCODE:
if (this->store != NULL) {
if ((he = hv_fetch_ent(this->store, key, 0, 0)) != NULL) {
ST(0) = sv_2mortal(SvREFCNT_inc(HeVAL(he)));
XSRETURN(1);
}
}
keyname = SvPV(key, keyname_length);
if (srl_iterator_hash_exists(aTHX_ this->iter, keyname, keyname_length) == SRL_ITER_NOT_FOUND) {
ST(0) = &PL_sv_undef;
XSRETURN(1);
void
EXISTS(this, key)
sereal_iterator_tied_hash_t *this;
SV *key;
PREINIT:
const char *keyname;
STRLEN keyname_length;
PPCODE:
if (this->store != NULL && hv_exists_ent(this->store, key, 0)) {
ST(0) = &PL_sv_yes;
XSRETURN(1);
}
keyname = SvPV(key, keyname_length);
ST(0) = srl_iterator_hash_exists(aTHX_ this->iter, keyname, keyname_length) == SRL_ITER_NOT_FOUND
? &PL_sv_undef
: &PL_sv_yes;
XSRETURN(1);
void
FIRSTKEY(this)
sereal_iterator_tied_hash_t *this;
PREINIT:
const char *keyname;
STRLEN keyname_length;
PPCODE:
if (this->store != NULL && HvUSEDKEYS(this->store) > 0) {
this->cur_idx = -1; //indication that we should try to fetch next key from the store
(void) hv_iterinit(this->store);
ST(0) = hv_iterkeysv(hv_iternext(this->store));
XSRETURN(1);
}
if (this->count > 0) {
srl_iterator_rewind(aTHX_ this->iter, 0);
void
NEXTKEY(this, last)
sereal_iterator_tied_hash_t *this;
SV *last;
PREINIT:
HE *he;
U32 stack_idx;
const char *keyname;
STRLEN keyname_length;
PPCODE:
if (this->cur_idx < 0 && (he = hv_iternext(this->store)) != NULL) {
ST(0) = hv_iterkeysv(he);
XSRETURN(1);
}
assert(this->depth == srl_iterator_stack_depth(aTHX_ this->iter));
for (this->cur_idx += 1; this->cur_idx < (I32) this->count; this->cur_idx += 1) {
stack_idx = srl_iterator_stack_index(aTHX_ this->iter);
if (this->cur_idx < (I32) stack_idx) {
srl_iterator_rewind(aTHX_ this->iter, 0);
XSRETURN(1);
}
}
ST(0) = &PL_sv_undef;
XSRETURN(1);
void
SCALAR(this)
sereal_iterator_tied_hash_t *this;
PPCODE:
if (this->count > 0) {
ST(0) = sv_2mortal(newSVuv(1));
} else if (this->store == NULL) {
ST(0) = sv_2mortal(newSVuv(0));
} else {
ST(0) = hv_scalar(this->store);
}
XSRETURN(1);
void
( run in 0.883 second using v1.01-cache-2.11-cpan-5511b514fd6 )