Basic-Coercion-XS

 view release on metacpan or  search on metacpan

lib/Basic/Coercion/XS.xs  view on Meta::CPAN

#include "XSUB.h"

static SV * new_coerce (SV * type, CV * coerce) {
	dTHX;
	HV * hash = newHV();
	hv_store(hash, "name", 4, type, 0);
	hv_store(hash, "coerce", 6, (SV*)coerce, 0);
	return sv_bless(newRV_noinc((SV*)hash), gv_stashsv(newSVpv("Basic::Coercion::XS", 19), 0));
}

char *get_caller(void) {
	dTHX;
	char *callr = HvNAME((HV*)CopSTASH(PL_curcop));
	return callr;
}

AV* split_by_regex(char *input, SV **pattern_sv) {
	dTHX;
	REGEXP *rx;
	AV *result = newAV();
	if (!pattern_sv || !SvROK(*pattern_sv)) {

lib/Basic/Coercion/XS.xs  view on Meta::CPAN

			croak("first argument must be a Basic::Coercion::XS object");
		}
		SV * cb = *hv_fetch((HV*)SvRV(self), "coerce", 6, 0);
		RETVAL = (CV*)SvRV(cb);
	OUTPUT:
		RETVAL

void
import( ...)
	CODE:
		char *pkg = get_caller();
		STRLEN retlen;
		int i = 1;
		for (i = 1; i < items; i++) {
			char * ex = SvPV(ST(i), retlen);
			int name_len = strlen(pkg) + retlen + 3;
			char *name = (char *)malloc(name_len);
			if (!name) croak("Out of memory");
			snprintf(name, name_len, "%s::%s", pkg, ex);
			if (strcmp(ex, "StrToArray") == 0) {
				newXS(name, XS_Basic__Coercion__XS__Definition_StrToArray, __FILE__);



( run in 0.348 second using v1.01-cache-2.11-cpan-a9ef4e587e4 )