/*
 * This file was generated automatically by ExtUtils::ParseXS version 3.51 from the
 * contents of XS.xs. Do not edit this file, edit XS.xs instead.
 *
 *    ANY CHANGES MADE HERE WILL BE LOST!
 *
 */

#line 1 "XS.xs"
#define PERL_NO_GET_CONTEXT
#include "xshelper.h"

#define IsObject(sv)    (SvROK(sv) && SvOBJECT(SvRV(sv)))
#define IsArrayRef(sv)  (SvROK(sv) && !SvOBJECT(SvRV(sv)) && SvTYPE(SvRV(sv)) == SVt_PVAV)
#define IsHashRef(sv)   (SvROK(sv) && !SvOBJECT(SvRV(sv)) && SvTYPE(SvRV(sv)) == SVt_PVHV)
#define IsCodeRef(sv)   (SvROK(sv) && !SvOBJECT(SvRV(sv)) && SvTYPE(SvRV(sv)) == SVt_PVCV)
#define IsScalarRef(sv) (SvROK(sv) && !SvOBJECT(SvRV(sv)) && SvTYPE(SvRV(sv)) <= SVt_PVMG)

#define WRONG_NUMBER_OF_PARAMETERS "Wrong number of parameters"

#define SV_SAFE_COPY(val)                                 \
    (                                                     \
        (SvROK(val) && SvTYPE(SvRV(val)) == SVt_PVCV)     \
            ? newRV_inc(SvRV(val))                        \
            : newSVsv(val)                                \
    )

// Utility macros, typedefs, etc.
#include "src/Types.c"
#include "src/ShouldReturn.c"
#include "src/Unpacking.c"

// Different types, corresponding to Sub::HandlesVia
#include "src/Array.c"

#define INSTALL_CONST(module, name) newCONSTSUB(module, #name, newSViv(name))
#define UNPACK_SIG(type) const type *sig = (const type *) CvXSUBANY(cv).any_ptr

typedef struct {
#ifdef USE_ITHREADS
    pTHX;
#endif
    CV *callback;
} sort_ctx_t;

static int
sv_cmp_with_optional_callback(const void *a, const void *b, void *ctx_void) {
    sort_ctx_t *ctx = (sort_ctx_t *)ctx_void;
#ifdef USE_ITHREADS
    dTHXa(ctx->aTHX);
#endif

    SV *lhs = *(SV **)a;
    SV *rhs = *(SV **)b;

    /* Fast path: no callback → string cmp */
    if (!ctx->callback) {
        return sv_cmp(lhs, rhs);
    }

    /* Callback-based comparison */
    dSP;
    ENTER;
    SAVETMPS;

    PUSHMARK(SP);
    XPUSHs(lhs);
    XPUSHs(rhs);
    PUTBACK;

    call_sv((SV *)ctx->callback, G_SCALAR);

    SPAGAIN;
    SV *ret = POPs;
    int cmp = SvIV(ret);

    PUTBACK;
    FREETMPS;
    LEAVE;

    return cmp;
}

#line 85 "XS.c"
#ifndef PERL_UNUSED_VAR
#  define PERL_UNUSED_VAR(var) if (0) var = var
#endif

#ifndef dVAR
#  define dVAR		dNOOP
#endif


/* This stuff is not part of the API! You have been warned. */
#ifndef PERL_VERSION_DECIMAL
#  define PERL_VERSION_DECIMAL(r,v,s) (r*1000000 + v*1000 + s)
#endif
#ifndef PERL_DECIMAL_VERSION
#  define PERL_DECIMAL_VERSION \
	  PERL_VERSION_DECIMAL(PERL_REVISION,PERL_VERSION,PERL_SUBVERSION)
#endif
#ifndef PERL_VERSION_GE
#  define PERL_VERSION_GE(r,v,s) \
	  (PERL_DECIMAL_VERSION >= PERL_VERSION_DECIMAL(r,v,s))
#endif
#ifndef PERL_VERSION_LE
#  define PERL_VERSION_LE(r,v,s) \
	  (PERL_DECIMAL_VERSION <= PERL_VERSION_DECIMAL(r,v,s))
#endif

/* XS_INTERNAL is the explicit static-linkage variant of the default
 * XS macro.
 *
 * XS_EXTERNAL is the same as XS_INTERNAL except it does not include
 * "STATIC", ie. it exports XSUB symbols. You probably don't want that
 * for anything but the BOOT XSUB.
 *
 * See XSUB.h in core!
 */


/* TODO: This might be compatible further back than 5.10.0. */
#if PERL_VERSION_GE(5, 10, 0) && PERL_VERSION_LE(5, 15, 1)
#  undef XS_EXTERNAL
#  undef XS_INTERNAL
#  if defined(__CYGWIN__) && defined(USE_DYNAMIC_LOADING)
#    define XS_EXTERNAL(name) __declspec(dllexport) XSPROTO(name)
#    define XS_INTERNAL(name) STATIC XSPROTO(name)
#  endif
#  if defined(__SYMBIAN32__)
#    define XS_EXTERNAL(name) EXPORT_C XSPROTO(name)
#    define XS_INTERNAL(name) EXPORT_C STATIC XSPROTO(name)
#  endif
#  ifndef XS_EXTERNAL
#    if defined(HASATTRIBUTE_UNUSED) && !defined(__cplusplus)
#      define XS_EXTERNAL(name) void name(pTHX_ CV* cv __attribute__unused__)
#      define XS_INTERNAL(name) STATIC void name(pTHX_ CV* cv __attribute__unused__)
#    else
#      ifdef __cplusplus
#        define XS_EXTERNAL(name) extern "C" XSPROTO(name)
#        define XS_INTERNAL(name) static XSPROTO(name)
#      else
#        define XS_EXTERNAL(name) XSPROTO(name)
#        define XS_INTERNAL(name) STATIC XSPROTO(name)
#      endif
#    endif
#  endif
#endif

/* perl >= 5.10.0 && perl <= 5.15.1 */


/* The XS_EXTERNAL macro is used for functions that must not be static
 * like the boot XSUB of a module. If perl didn't have an XS_EXTERNAL
 * macro defined, the best we can do is assume XS is the same.
 * Dito for XS_INTERNAL.
 */
#ifndef XS_EXTERNAL
#  define XS_EXTERNAL(name) XS(name)
#endif
#ifndef XS_INTERNAL
#  define XS_INTERNAL(name) XS(name)
#endif

/* Now, finally, after all this mess, we want an ExtUtils::ParseXS
 * internal macro that we're free to redefine for varying linkage due
 * to the EXPORT_XSUB_SYMBOLS XS keyword. This is internal, use
 * XS_EXTERNAL(name) or XS_INTERNAL(name) in your code if you need to!
 */

#undef XS_EUPXS
#if defined(PERL_EUPXS_ALWAYS_EXPORT)
#  define XS_EUPXS(name) XS_EXTERNAL(name)
#else
   /* default to internal */
#  define XS_EUPXS(name) XS_INTERNAL(name)
#endif

#ifndef PERL_ARGS_ASSERT_CROAK_XS_USAGE
#define PERL_ARGS_ASSERT_CROAK_XS_USAGE assert(cv); assert(params)

/* prototype to pass -Wmissing-prototypes */
STATIC void
S_croak_xs_usage(const CV *const cv, const char *const params);

STATIC void
S_croak_xs_usage(const CV *const cv, const char *const params)
{
    const GV *const gv = CvGV(cv);

    PERL_ARGS_ASSERT_CROAK_XS_USAGE;

    if (gv) {
        const char *const gvname = GvNAME(gv);
        const HV *const stash = GvSTASH(gv);
        const char *const hvname = stash ? HvNAME(stash) : NULL;

        if (hvname)
	    Perl_croak_nocontext("Usage: %s::%s(%s)", hvname, gvname, params);
        else
	    Perl_croak_nocontext("Usage: %s(%s)", gvname, params);
    } else {
        /* Pants. I don't think that it should be possible to get here. */
	Perl_croak_nocontext("Usage: CODE(0x%" UVxf ")(%s)", PTR2UV(cv), params);
    }
}
#undef  PERL_ARGS_ASSERT_CROAK_XS_USAGE

#define croak_xs_usage        S_croak_xs_usage

#endif

/* NOTE: the prototype of newXSproto() is different in versions of perls,
 * so we define a portable version of newXSproto()
 */
#ifdef newXS_flags
#define newXSproto_portable(name, c_impl, file, proto) newXS_flags(name, c_impl, file, proto, 0)
#else
#define newXSproto_portable(name, c_impl, file, proto) (PL_Sv=(SV*)newXS(name, c_impl, file), sv_setpv(PL_Sv, proto), (CV*)PL_Sv)
#endif /* !defined(newXS_flags) */

#if PERL_VERSION_LE(5, 21, 5)
#  define newXS_deffile(a,b) Perl_newXS(aTHX_ a,b,file)
#else
#  define newXS_deffile(a,b) Perl_newXS_deffile(aTHX_ a,b)
#endif

#line 229 "XS.c"

XS_EUPXS(XS_Sub__HandlesVia__XS_shvxs_array_accessor); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Sub__HandlesVia__XS_shvxs_array_accessor)
{
    dVAR; dXSARGS;
    if (items < 1)
       croak_xs_usage(cv,  "invocant, ...");
    {
	SV *	invocant = ST(0)
;
#line 124 "XS.xs"
{
    dTHX;
    dSP;

    UNPACK_SIG(shvxs_array_SETTER_SIG);
    GET_ARRAY_FROM_SOURCE;
    GET_INDEX_FROM_SOURCE(1);

    I32 len = av_len(array) + 1;
    I32 real_ix = ix;
    if (real_ix < 0)
        real_ix += len;

    //warn("HERE, items=%d, sig.has_curried_sv=%d, sig.index=%d, sig.has_index=%d, ix=%d, real_ix=%d, has_ix=%d", items, sig->has_curried_sv, sig->index, sig->has_index, ix, real_ix, has_ix);
    //Perl_sv_dump(sig->curried_sv);

    if ( items > ( has_ix ? 1 : 2 ) || sig->has_curried_sv ) {

        GET_CURRIED_SV_FROM_SOURCE(has_ix ? 1 : 2);

        I32 expected = 3;
        if (has_ix) expected--;
        if (has_curried_sv) expected--;
        if ( items != expected ) croak(WRONG_NUMBER_OF_PARAMETERS);

        val = SV_SAFE_COPY(curried_sv);

        bool ok;
        CHECK_TYPE(ok, val, sig->element_type, sig->element_type_cv);
        TRY_COERCE_TYPE(ok, val, sig->element_type, sig->element_type_cv, sig->element_coercion_cv);
        if (!ok) {
            if ( has_ix && has_curried_sv ) {
                type_error(val, "$curried", 1, sig->element_type, sig->element_type_tiny);
            }
            else if ( has_curried_sv ) {
                type_error(val, "$curried", 0, sig->element_type, sig->element_type_tiny);
            }
            else if ( has_ix ) {
                type_error(val, "$_", 1, sig->element_type, sig->element_type_tiny);
            }
            else {
                type_error(val, "$_", 2, sig->element_type, sig->element_type_tiny);
            }
        }

        av_store(array, real_ix, val);
    }
    else {
        I32 expected = 2;
        if (has_ix) expected--;
        if ( items != expected ) croak(WRONG_NUMBER_OF_PARAMETERS);

        if (real_ix < 0 || real_ix >= len) {
            val = &PL_sv_undef;
        }
        else {
            SV **svp = av_fetch(array, real_ix, 0);
            val = svp ? *svp : &PL_sv_undef;
        }
    }

    RETURN_ARRAY_EXPECTATION;
}
#line 304 "XS.c"
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Sub__HandlesVia__XS_shvxs_array_all); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Sub__HandlesVia__XS_shvxs_array_all)
{
    dVAR; dXSARGS;
    if (items < 1)
       croak_xs_usage(cv,  "invocant, ...");
    {
	SV *	invocant = ST(0)
;
#line 193 "XS.xs"
{
    dTHX;
    dSP;

    if ( items > 1 ) croak(WRONG_NUMBER_OF_PARAMETERS);

    UNPACK_SIG(shvxs_array_SIMPLE_SIG);
    GET_ARRAY_FROM_SOURCE;

    out = array;

    RETURN_ARRAY_EXPECTATION;
}
#line 333 "XS.c"
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Sub__HandlesVia__XS_shvxs_array_all_true); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Sub__HandlesVia__XS_shvxs_array_all_true)
{
    dVAR; dXSARGS;
    if (items < 1)
       croak_xs_usage(cv,  "invocant, ...");
    {
	SV *	invocant = ST(0)
;
#line 212 "XS.xs"
{
    dTHX;
    dSP;

    UNPACK_SIG(shvxs_array_CALLBACK_SIG);
    GET_ARRAY_FROM_SOURCE;

    GET_CALLBACK_FROM_SOURCE(1);
    if ( items != ( has_callback ? 1 : 2 ) ) croak(WRONG_NUMBER_OF_PARAMETERS);

    val = &PL_sv_yes;

    I32 len = av_len(array) + 1;
    for (I32 i = 0; i < len; i++) {
        SV **svp = av_fetch(array, i, 0);
        if (!svp) continue;

        SV *tmp = sv_2mortal(newSVsv(*svp));
        sv_setsv(get_sv("_", 0), tmp);

        ENTER;
        SAVETMPS;
        PUSHMARK(SP);
        XPUSHs(tmp);
        XPUSHs(sv_2mortal(newSViv(i)));
        PUTBACK;

        I32 count = call_sv((SV *)callback, G_SCALAR);
        SPAGAIN;

        SV *ret;
        if (count > 0)
            ret = POPs;
        else
            ret = &PL_sv_undef;

        if (!SvTRUE(ret)) {
            PUTBACK;
            FREETMPS;
            LEAVE;
            val = &PL_sv_no;
            break;
        }

        PUTBACK;
        FREETMPS;
        LEAVE;
    }

    RETURN_ARRAY_EXPECTATION;
}
#line 400 "XS.c"
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Sub__HandlesVia__XS_shvxs_array_any); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Sub__HandlesVia__XS_shvxs_array_any)
{
    dVAR; dXSARGS;
    if (items < 1)
       croak_xs_usage(cv,  "invocant, ...");
    {
	SV *	invocant = ST(0)
;
#line 269 "XS.xs"
{
    dTHX;
    dSP;

    UNPACK_SIG(shvxs_array_CALLBACK_SIG);
    GET_ARRAY_FROM_SOURCE;

    GET_CALLBACK_FROM_SOURCE(1);
    if ( items != ( has_callback ? 1 : 2 ) ) croak(WRONG_NUMBER_OF_PARAMETERS);

    val = &PL_sv_no;

    I32 len = av_len(array) + 1;
    for (I32 i = 0; i < len; i++) {
        SV **svp = av_fetch(array, i, 0);
        if (!svp) continue;

        SV *tmp = sv_2mortal(newSVsv(*svp));
        sv_setsv(get_sv("_", 0), tmp);

        ENTER;
        SAVETMPS;
        PUSHMARK(SP);
        XPUSHs(tmp);
        XPUSHs(sv_2mortal(newSViv(i)));
        PUTBACK;

        I32 count = call_sv((SV *)callback, G_SCALAR);
        SPAGAIN;

        SV *ret;
        if (count > 0)
            ret = POPs;
        else
            ret = &PL_sv_undef;

        if (SvTRUE(ret)) {
            PUTBACK;
            FREETMPS;
            LEAVE;
            val = &PL_sv_yes;
            break;
        }

        PUTBACK;
        FREETMPS;
        LEAVE;
    }

    RETURN_ARRAY_EXPECTATION;
}
#line 467 "XS.c"
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Sub__HandlesVia__XS_shvxs_array_clear); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Sub__HandlesVia__XS_shvxs_array_clear)
{
    dVAR; dXSARGS;
    if (items < 1)
       croak_xs_usage(cv,  "invocant, ...");
    {
	SV *	invocant = ST(0)
;
#line 326 "XS.xs"
{
    dTHX;
    dSP;

    if ( items > 1 ) croak(WRONG_NUMBER_OF_PARAMETERS);

    UNPACK_SIG(shvxs_array_SIMPLE_SIG);
    GET_ARRAY_FROM_SOURCE;

    av_clear(array);

    RETURN_ARRAY_EXPECTATION;
}
#line 496 "XS.c"
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Sub__HandlesVia__XS_shvxs_array_count); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Sub__HandlesVia__XS_shvxs_array_count)
{
    dVAR; dXSARGS;
    if (items < 1)
       croak_xs_usage(cv,  "invocant, ...");
    {
	SV *	invocant = ST(0)
;
#line 345 "XS.xs"
{
    dTHX;
    dSP;

    if ( items > 1 ) croak(WRONG_NUMBER_OF_PARAMETERS);

    UNPACK_SIG(shvxs_array_SIMPLE_SIG);
    GET_ARRAY_FROM_SOURCE;

    I32 n = av_len(array) + 1;
    val = newSViv(n);

    RETURN_ARRAY_EXPECTATION;
}
#line 526 "XS.c"
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Sub__HandlesVia__XS_shvxs_array_first); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Sub__HandlesVia__XS_shvxs_array_first)
{
    dVAR; dXSARGS;
    if (items < 1)
       croak_xs_usage(cv,  "invocant, ...");
    {
	SV *	invocant = ST(0)
;
#line 365 "XS.xs"
{
    dTHX;
    dSP;

    UNPACK_SIG(shvxs_array_CALLBACK_SIG);
    GET_ARRAY_FROM_SOURCE;

    GET_CALLBACK_FROM_SOURCE(1);
    if ( items != ( has_callback ? 1 : 2 ) ) croak(WRONG_NUMBER_OF_PARAMETERS);

    val = &PL_sv_undef;

    I32 len = av_len(array) + 1;
    for (I32 i = 0; i < len; i++) {
        SV **svp = av_fetch(array, i, 0);
        if (!svp) continue;

        SV *elem = *svp;
        SV *tmp = sv_2mortal(newSVsv(elem));
        sv_setsv(get_sv("_", 0), tmp);

        ENTER;
        SAVETMPS;
        PUSHMARK(SP);
        XPUSHs(tmp);
        XPUSHs(sv_2mortal(newSViv(i)));
        PUTBACK;

        I32 count = call_sv((SV *)callback, G_SCALAR);
        SPAGAIN;

        SV *ret;
        if (count > 0)
            ret = POPs;
        else
            ret = &PL_sv_undef;

        if (SvTRUE(ret)) {
            PUTBACK;
            FREETMPS;
            LEAVE;
            val = newSVsv(elem);
            break;
        }

        PUTBACK;
        FREETMPS;
        LEAVE;
    }

    RETURN_ARRAY_EXPECTATION;
}
#line 594 "XS.c"
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Sub__HandlesVia__XS_shvxs_array_for_each); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Sub__HandlesVia__XS_shvxs_array_for_each)
{
    dVAR; dXSARGS;
    if (items < 1)
       croak_xs_usage(cv,  "invocant, ...");
    {
	SV *	invocant = ST(0)
;
#line 423 "XS.xs"
{
    dTHX;
    dSP;

    UNPACK_SIG(shvxs_array_CALLBACK_SIG);
    GET_ARRAY_FROM_SOURCE;

    GET_CALLBACK_FROM_SOURCE(1);
    if ( items != ( has_callback ? 1 : 2 ) ) croak(WRONG_NUMBER_OF_PARAMETERS);

    I32 len = av_len(array) + 1;
    for (I32 i = 0; i < len; i++) {
        SV **svp = av_fetch(array, i, 0);
        if (!svp) continue;
        SV *elem = *svp;
        SV *tmp = newSVsv(elem);
        sv_2mortal(tmp);
        SV *sv_dollar_underscore = get_sv("_", 0);
        sv_setsv(sv_dollar_underscore, tmp);
        ENTER;
        SAVETMPS;
        PUSHMARK(SP);
        XPUSHs(tmp);
        XPUSHs(sv_2mortal(newSViv(i)));
        PUTBACK;
        call_sv((SV*)callback, G_VOID | G_DISCARD);
        FREETMPS;
        LEAVE;
    }

    RETURN_ARRAY_EXPECTATION;
}
#line 642 "XS.c"
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Sub__HandlesVia__XS_shvxs_array_get); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Sub__HandlesVia__XS_shvxs_array_get)
{
    dVAR; dXSARGS;
    if (items < 1)
       croak_xs_usage(cv,  "invocant, ...");
    {
	SV *	invocant = ST(0)
;
#line 461 "XS.xs"
{
    dTHX;
    dSP;

    UNPACK_SIG(shvxs_array_INDEX_SIG);
    GET_ARRAY_FROM_SOURCE;

    GET_INDEX_FROM_SOURCE(1);
    if ( items != ( has_ix ? 1 : 2 ) ) croak(WRONG_NUMBER_OF_PARAMETERS);

    I32 len = av_len(array) + 1;
    I32 real_ix = ix;
    if (real_ix < 0)
        real_ix += len;

    if (real_ix < 0 || real_ix >= len) {
        val = &PL_sv_undef;
    }
    else {
        SV **svp = av_fetch(array, real_ix, 0);
        val = svp ? *svp : &PL_sv_undef;
    }

    RETURN_ARRAY_EXPECTATION;
}
#line 683 "XS.c"
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Sub__HandlesVia__XS_shvxs_array_grep); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Sub__HandlesVia__XS_shvxs_array_grep)
{
    dVAR; dXSARGS;
    if (items < 1)
       croak_xs_usage(cv,  "invocant, ...");
    {
	SV *	invocant = ST(0)
;
#line 492 "XS.xs"
{
    dTHX;
    dSP;

    UNPACK_SIG(shvxs_array_CALLBACK_SIG);
    GET_ARRAY_FROM_SOURCE;

    GET_CALLBACK_FROM_SOURCE(1);
    if ( items != ( has_callback ? 1 : 2 ) ) croak(WRONG_NUMBER_OF_PARAMETERS);

    out = newAV();

    I32 len = av_len(array) + 1;
    for (I32 i = 0; i < len; i++) {
        SV **svp = av_fetch(array, i, 0);
        if (!svp) continue;

        SV *tmp = sv_2mortal(newSVsv(*svp));
        sv_setsv(get_sv("_", 0), tmp);

        ENTER;
        SAVETMPS;
        PUSHMARK(SP);
        XPUSHs(tmp);
        XPUSHs(sv_2mortal(newSViv(i)));
        PUTBACK;

        I32 count = call_sv((SV *)callback, G_SCALAR);

        SPAGAIN;

        SV *ret = POPs;
        if (count > 0 && SvTRUE(ret))
            av_push(out, SV_SAFE_COPY(*svp));

        PUTBACK;
        FREETMPS;
        LEAVE;
    }

    RETURN_ARRAY_EXPECTATION;
}
#line 741 "XS.c"
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Sub__HandlesVia__XS_shvxs_array_is_empty); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Sub__HandlesVia__XS_shvxs_array_is_empty)
{
    dVAR; dXSARGS;
    if (items < 1)
       croak_xs_usage(cv,  "invocant, ...");
    {
	SV *	invocant = ST(0)
;
#line 540 "XS.xs"
{
    dTHX;
    dSP;

    if ( items > 1 ) croak(WRONG_NUMBER_OF_PARAMETERS);

    UNPACK_SIG(shvxs_array_SIMPLE_SIG);
    GET_ARRAY_FROM_SOURCE;

    val = (av_len(array) < 0) ? &PL_sv_yes : &PL_sv_no;

    RETURN_ARRAY_EXPECTATION;
}
#line 770 "XS.c"
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Sub__HandlesVia__XS_shvxs_array_join); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Sub__HandlesVia__XS_shvxs_array_join)
{
    dVAR; dXSARGS;
    if (items < 1)
       croak_xs_usage(cv,  "invocant, ...");
    {
	SV *	invocant = ST(0)
;
#line 559 "XS.xs"
{
    dTHX;
    dSP;

    UNPACK_SIG(shvxs_array_SV_SIG);
    GET_ARRAY_FROM_SOURCE;

    MAYBE_GET_CURRIED_SV_FROM_SOURCE(1);
    if ( items > ( has_curried_sv ? 1 : 2 ) ) croak(WRONG_NUMBER_OF_PARAMETERS);

    SV* joiner = curried_sv ? curried_sv : sv_2mortal(newSVpv(",", 1));
    if ( !joiner || !SvOK(joiner) || SvROK(joiner) || isGV(joiner) ) {
        if ( has_curried_sv ) type_error(joiner, "$curried", 0, TYPE_BASE_STR, NULL);
        type_error(joiner, "$_", 1, TYPE_BASE_STR, NULL);
    }

    STRLEN sep_len;
    const char *sep = SvPV(joiner, sep_len);

    val = newSVpv("", 0);

    I32 len = av_len(array) + 1;
    for (I32 i = 0; i < len; i++) {
        SV **svp = av_fetch(array, i, 0);

        if (i > 0)
            sv_catpvn(val, sep, sep_len);

        if (svp && SvOK(*svp)) {
            STRLEN l;
            const char *p = SvPV(*svp, l);
            sv_catpvn(val, p, l);
        }
    }

    RETURN_ARRAY_EXPECTATION;
}
#line 823 "XS.c"
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Sub__HandlesVia__XS_shvxs_array_map); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Sub__HandlesVia__XS_shvxs_array_map)
{
    dVAR; dXSARGS;
    if (items < 1)
       croak_xs_usage(cv,  "invocant, ...");
    {
	SV *	invocant = ST(0)
;
#line 602 "XS.xs"
{
    dTHX;
    dSP;

    UNPACK_SIG(shvxs_array_CALLBACK_SIG);
    GET_ARRAY_FROM_SOURCE;

    GET_CALLBACK_FROM_SOURCE(1);
    if ( items != ( has_callback ? 1 : 2 ) ) croak(WRONG_NUMBER_OF_PARAMETERS);

    out = newAV();

    I32 len = av_len(array) + 1;
    for (I32 i = 0; i < len; i++) {
        SV **svp = av_fetch(array, i, 0);
        if (!svp) continue;

        SV *tmp = sv_2mortal(newSVsv(*svp));
        sv_setsv(get_sv("_", 0), tmp);

        ENTER;
        SAVETMPS;
        PUSHMARK(SP);
        XPUSHs(tmp);
        XPUSHs(sv_2mortal(newSViv(i)));
        PUTBACK;

        I32 count = call_sv((SV *)callback, G_ARRAY);
        SPAGAIN;

        /* stack is LIFO; preserve order */
        if (count > 0) {
            SV **results = SP - count + 1;
            for (I32 j = 0; j < count; j++) {
                av_push(out, SV_SAFE_COPY(results[j]));
            }
            SP -= count;
        }

        PUTBACK;
        FREETMPS;
        LEAVE;
    }

    RETURN_ARRAY_EXPECTATION;
}
#line 885 "XS.c"
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Sub__HandlesVia__XS_shvxs_array_pop); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Sub__HandlesVia__XS_shvxs_array_pop)
{
    dVAR; dXSARGS;
    if (items < 1)
       croak_xs_usage(cv,  "invocant, ...");
    {
	SV *	invocant = ST(0)
;
#line 654 "XS.xs"
{
    dTHX;
    dSP;

    if ( items > 1 ) croak(WRONG_NUMBER_OF_PARAMETERS);

    UNPACK_SIG(shvxs_array_SIMPLE_SIG);
    GET_ARRAY_FROM_SOURCE;

    val = (SV*)av_pop(array);
    if (val) {
        SvREFCNT_inc(val);
    }
    else {
        val = newSV(0);
    }

    RETURN_ARRAY_EXPECTATION;
}
#line 920 "XS.c"
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Sub__HandlesVia__XS_shvxs_array_push); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Sub__HandlesVia__XS_shvxs_array_push)
{
    dVAR; dXSARGS;
    if (items < 1)
       croak_xs_usage(cv,  "invocant, ...");
    {
	SV *	invocant = ST(0)
;
#line 679 "XS.xs"
{
    dTHX;
    UNPACK_SIG(shvxs_array_NEW_ELEMS_SIG);
    GET_ARRAY_FROM_SOURCE;

    bool ok;
    for (I32 i = 1; i < items; i++) {
        val = ST(i);
        CHECK_TYPE(ok, newSVsv(val), sig->element_type, sig->element_type_cv);
        TRY_COERCE_TYPE(ok, val, sig->element_type, sig->element_type_cv, sig->element_coercion_cv);
        if (!ok) type_error(val, "$_", i, sig->element_type, sig->element_type_tiny);
        av_push(array, SV_SAFE_COPY(val));
    }

    RETURN_ARRAY_EXPECTATION;
}
#line 952 "XS.c"
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Sub__HandlesVia__XS_shvxs_array_reverse); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Sub__HandlesVia__XS_shvxs_array_reverse)
{
    dVAR; dXSARGS;
    if (items < 1)
       croak_xs_usage(cv,  "invocant, ...");
    {
	SV *	invocant = ST(0)
;
#line 701 "XS.xs"
{
    dTHX;
    dSP;

    if ( items > 1 ) croak(WRONG_NUMBER_OF_PARAMETERS);

    UNPACK_SIG(shvxs_array_SIMPLE_SIG);
    GET_ARRAY_FROM_SOURCE;

    out = newAV();
    I32 len = av_len(array);
    if (len >= 0)
        av_extend(out, len);

    for (I32 i = len; i >= 0; i--) {
        SV **svp = av_fetch(array, i, 0);
        av_push(out, svp ? newSVsv(*svp) : &PL_sv_undef);
    }

    RETURN_ARRAY_EXPECTATION;
}
#line 989 "XS.c"
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Sub__HandlesVia__XS_shvxs_array_set); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Sub__HandlesVia__XS_shvxs_array_set)
{
    dVAR; dXSARGS;
    if (items < 1)
       croak_xs_usage(cv,  "invocant, ...");
    {
	SV *	invocant = ST(0)
;
#line 728 "XS.xs"
{
    dTHX;
    dSP;

    UNPACK_SIG(shvxs_array_SETTER_SIG);
    GET_ARRAY_FROM_SOURCE;
    GET_INDEX_FROM_SOURCE(1);
    GET_CURRIED_SV_FROM_SOURCE(has_ix ? 1 : 2);

    I32 expected = 3;
    if (has_ix) expected--;
    if (has_curried_sv) expected--;
    if ( items != expected ) croak(WRONG_NUMBER_OF_PARAMETERS);

    I32 len = av_len(array) + 1;
    I32 real_ix = ix;
    if (real_ix < 0)
        real_ix += len;

    val = SV_SAFE_COPY(curried_sv);

    bool ok;
    CHECK_TYPE(ok, val, sig->element_type, sig->element_type_cv);
    TRY_COERCE_TYPE(ok, val, sig->element_type, sig->element_type_cv, sig->element_coercion_cv);
    if (!ok) {
        if ( has_ix && has_curried_sv ) {
            type_error(val, "$curried", 1, sig->element_type, sig->element_type_tiny);
        }
        else if ( has_curried_sv ) {
            type_error(val, "$curried", 0, sig->element_type, sig->element_type_tiny);
        }
        else if ( has_ix ) {
            type_error(val, "$_", 1, sig->element_type, sig->element_type_tiny);
        }
        else {
            type_error(val, "$_", 2, sig->element_type, sig->element_type_tiny);
        }
    }

    av_store(array, real_ix, val);

    RETURN_ARRAY_EXPECTATION;
}
#line 1048 "XS.c"
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Sub__HandlesVia__XS_shvxs_array_shift); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Sub__HandlesVia__XS_shvxs_array_shift)
{
    dVAR; dXSARGS;
    if (items < 1)
       croak_xs_usage(cv,  "invocant, ...");
    {
	SV *	invocant = ST(0)
;
#line 777 "XS.xs"
{
    dTHX;
    dSP;

    if ( items > 1 ) croak(WRONG_NUMBER_OF_PARAMETERS);

    UNPACK_SIG(shvxs_array_SIMPLE_SIG);
    GET_ARRAY_FROM_SOURCE;

    val = (SV*)av_shift(array);
    if (val) {
        SvREFCNT_inc(val);
    }
    else {
        val = newSV(0);
    }

    RETURN_ARRAY_EXPECTATION;
}
#line 1083 "XS.c"
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Sub__HandlesVia__XS_shvxs_array_sort); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Sub__HandlesVia__XS_shvxs_array_sort)
{
    dVAR; dXSARGS;
    if (items < 1)
       croak_xs_usage(cv,  "invocant, ...");
    {
	SV *	invocant = ST(0)
;
#line 802 "XS.xs"
{
    dTHX;
    dSP;

    UNPACK_SIG(shvxs_array_CALLBACK_SIG);
    GET_ARRAY_FROM_SOURCE;

    MAYBE_GET_CALLBACK_FROM_SOURCE(1);
    if ( items > ( has_callback ? 1 : 2 ) ) croak(WRONG_NUMBER_OF_PARAMETERS);
    if ( !has_callback && items == 2 && !callback && !IsCodeRef(ST(1)) ) {
        type_error(ST(1), "$_", 1, TYPE_BASE_CODEREF, NULL);
    }

    out = newAV();

    I32 len = av_len(array) + 1;
    if (len > 1) {
        SV **elems = (SV **)malloc(len * sizeof(SV *));
        if (!elems)
            croak("Out of memory");

        for (I32 i = 0; i < len; i++) {
            SV **svp = av_fetch(array, i, 0);
            elems[i] = svp ? *svp : &PL_sv_undef;
        }

        sort_ctx_t ctx;
#ifdef USE_ITHREADS
        ctx.aTHX = aTHX;
#endif
        ctx.callback = callback;

        qsort_r(
            elems,
            len,
            sizeof(SV *),
            sv_cmp_with_optional_callback,
            &ctx
        );

        av_extend(out, len - 1);

        for (I32 i = 0; i < len; i++) {
            av_push(out, newSVsv(elems[i]));
        }

        free(elems);
    }

    RETURN_ARRAY_EXPECTATION;
}
#line 1150 "XS.c"
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Sub__HandlesVia__XS_shvxs_array_unshift); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Sub__HandlesVia__XS_shvxs_array_unshift)
{
    dVAR; dXSARGS;
    if (items < 1)
       croak_xs_usage(cv,  "invocant, ...");
    {
	SV *	invocant = ST(0)
;
#line 859 "XS.xs"
{
    dTHX;
    UNPACK_SIG(shvxs_array_NEW_ELEMS_SIG); // reuse from push
    GET_ARRAY_FROM_SOURCE;

    bool ok;
    for (I32 i = items - 1; i >= 1; i--) {
        val = ST(i);
        CHECK_TYPE(ok, newSVsv(val), sig->element_type, sig->element_type_cv);
        TRY_COERCE_TYPE(ok, val, sig->element_type, sig->element_type_cv, sig->element_coercion_cv);
        if (!ok) type_error(val, "$_", i, sig->element_type, sig->element_type_tiny);
        av_unshift(array, 1);
        av_store(array, 0, SV_SAFE_COPY(val));
    }

    RETURN_ARRAY_EXPECTATION;
}
#line 1183 "XS.c"
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Sub__HandlesVia__XS_INSTALL_shvxs_array_SIMPLE); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Sub__HandlesVia__XS_INSTALL_shvxs_array_SIMPLE)
{
    dVAR; dXSARGS;
    dXSI32;
    if (items != 2)
       croak_xs_usage(cv,  "name, href");
    {
	SV *	name = ST(0)
;
	SV *	href = ST(1)
;
#line 890 "XS.xs"
{
    dTHX;

    XSUBADDR_t op;
    enum ReturnPattern rp;
    switch ( ix ) {
        case 1:
            op = XS_Sub__HandlesVia__XS_shvxs_array_all;
            rp = SHOULD_RETURN_OUT;
            break;
        case 2:
            op = XS_Sub__HandlesVia__XS_shvxs_array_clear;
            rp = SHOULD_RETURN_NOTHING;
            break;
        case 3:
            op = XS_Sub__HandlesVia__XS_shvxs_array_count;
            rp = SHOULD_RETURN_VAL;
            break;
        case 4:
            op = XS_Sub__HandlesVia__XS_shvxs_array_is_empty;
            rp = SHOULD_RETURN_VAL;
            break;
        case 5:
            op = XS_Sub__HandlesVia__XS_shvxs_array_pop;
            rp = SHOULD_RETURN_VAL;
            break;
        case 6:
            op = XS_Sub__HandlesVia__XS_shvxs_array_reverse;
            rp = SHOULD_RETURN_OUT;
            break;
        case 7:
            op = XS_Sub__HandlesVia__XS_shvxs_array_shift;
            rp = SHOULD_RETURN_VAL;
            break;
        default:
            croak("PANIC!");
    }

    shvxs_array_SIMPLE_SIG *sig;
    Newxz(sig, 1, shvxs_array_SIMPLE_SIG);
    UNPACKING_HV_FROM_SV (href, hv);
    UNPACKING_GET_ENUM   (hv, sig, arr_source,            ARRAY_SRC_INVOCANT, ArraySource);
    UNPACKING_GET_STRING (hv, sig, arr_source_string,     NULL);
    UNPACKING_GET_STRING (hv, sig, arr_source_fallback,   NULL);
    UNPACKING_GET_I32    (hv, sig, arr_source_index,      0);
    UNPACKING_GET_ENUM   (hv, sig, method_return_pattern, rp, ReturnPattern);
    UNPACKING_GET_STRING (hv, sig, method_return_class,       NULL);
    UNPACKING_GET_STRING (hv, sig, method_return_constructor, NULL);

    CV *cv = newXS( SvPV_nolen(name), op, (char *)__FILE__ );
    CvXSUBANY(cv).any_ptr = sig;
    XSRETURN_EMPTY;
}
#line 1255 "XS.c"
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Sub__HandlesVia__XS_INSTALL_shvxs_array_CALLBACK); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Sub__HandlesVia__XS_INSTALL_shvxs_array_CALLBACK)
{
    dVAR; dXSARGS;
    dXSI32;
    if (items != 2)
       croak_xs_usage(cv,  "name, href");
    {
	SV *	name = ST(0)
;
	SV *	href = ST(1)
;
#line 957 "XS.xs"
{
    dTHX;

    XSUBADDR_t op;
    enum ReturnPattern rp;
    switch ( ix ) {
        case 1:
            op = XS_Sub__HandlesVia__XS_shvxs_array_for_each;
            rp = SHOULD_RETURN_INVOCANT;
            break;
        case 2:
            op = XS_Sub__HandlesVia__XS_shvxs_array_grep;
            rp = SHOULD_RETURN_OUT;
            break;
        case 3:
            op = XS_Sub__HandlesVia__XS_shvxs_array_map;
            rp = SHOULD_RETURN_OUT;
            break;
        case 4:
            op = XS_Sub__HandlesVia__XS_shvxs_array_first;
            rp = SHOULD_RETURN_VAL;
            break;
        case 5:
            op = XS_Sub__HandlesVia__XS_shvxs_array_any;
            rp = SHOULD_RETURN_VAL;
            break;
        case 6:
            op = XS_Sub__HandlesVia__XS_shvxs_array_all_true;
            rp = SHOULD_RETURN_VAL;
            break;
        case 7:
            op = XS_Sub__HandlesVia__XS_shvxs_array_sort;
            rp = SHOULD_RETURN_OUT;
            break;
        default:
            croak("PANIC!");
    }

    shvxs_array_CALLBACK_SIG *sig;
    Newxz(sig, 1, shvxs_array_CALLBACK_SIG);
    UNPACKING_HV_FROM_SV (href, hv);
    UNPACKING_GET_ENUM   (hv, sig, arr_source,            ARRAY_SRC_INVOCANT, ArraySource);
    UNPACKING_GET_STRING (hv, sig, arr_source_string,     NULL);
    UNPACKING_GET_STRING (hv, sig, arr_source_fallback,   NULL);
    UNPACKING_GET_I32    (hv, sig, arr_source_index,      0);
    UNPACKING_GET_CV     (hv, sig, callback);
    UNPACKING_GET_ENUM   (hv, sig, method_return_pattern, rp, ReturnPattern);
    UNPACKING_GET_STRING (hv, sig, method_return_class,       NULL);
    UNPACKING_GET_STRING (hv, sig, method_return_constructor, NULL);

    CV *cv = newXS( SvPV_nolen(name), op, (char *)__FILE__ );
    CvXSUBANY(cv).any_ptr = sig;
    XSRETURN_EMPTY;
}
#line 1328 "XS.c"
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Sub__HandlesVia__XS_INSTALL_shvxs_array_SV); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Sub__HandlesVia__XS_INSTALL_shvxs_array_SV)
{
    dVAR; dXSARGS;
    dXSI32;
    if (items != 2)
       croak_xs_usage(cv,  "name, href");
    {
	SV *	name = ST(0)
;
	SV *	href = ST(1)
;
#line 1019 "XS.xs"
{
    dTHX;

    XSUBADDR_t op;
    enum ReturnPattern rp;
    switch ( ix ) {
        case 1:
            op = XS_Sub__HandlesVia__XS_shvxs_array_join;
            rp = SHOULD_RETURN_VAL;
            break;
        default:
            croak("PANIC!");
    }

    shvxs_array_SV_SIG *sig;
    Newxz(sig, 1, shvxs_array_SV_SIG);
    UNPACKING_HV_FROM_SV (href, hv);
    UNPACKING_GET_ENUM   (hv, sig, arr_source,            ARRAY_SRC_INVOCANT, ArraySource);
    UNPACKING_GET_STRING (hv, sig, arr_source_string,     NULL);
    UNPACKING_GET_STRING (hv, sig, arr_source_fallback,   NULL);
    UNPACKING_GET_I32    (hv, sig, arr_source_index,      0);
    UNPACKING_MAYBE_SV   (hv, sig, curried_sv,            has_curried_sv);
    UNPACKING_GET_ENUM   (hv, sig, method_return_pattern, rp, ReturnPattern);
    UNPACKING_GET_STRING (hv, sig, method_return_class,       NULL);
    UNPACKING_GET_STRING (hv, sig, method_return_constructor, NULL);

    CV *cv = newXS( SvPV_nolen(name), op, (char *)__FILE__ );
    CvXSUBANY(cv).any_ptr = sig;
    XSRETURN_EMPTY;
}
#line 1377 "XS.c"
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Sub__HandlesVia__XS_INSTALL_shvxs_array_NEW_ELEMS); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Sub__HandlesVia__XS_INSTALL_shvxs_array_NEW_ELEMS)
{
    dVAR; dXSARGS;
    dXSI32;
    if (items != 2)
       croak_xs_usage(cv,  "name, href");
    {
	SV *	name = ST(0)
;
	SV *	href = ST(1)
;
#line 1058 "XS.xs"
{
    dTHX;

    XSUBADDR_t op;
    enum ReturnPattern rp;
    switch ( ix ) {
        case 1:
            op = XS_Sub__HandlesVia__XS_shvxs_array_push;
            rp = SHOULD_RETURN_COUNT;
            break;
        case 2:
            op = XS_Sub__HandlesVia__XS_shvxs_array_unshift;
            rp = SHOULD_RETURN_COUNT;
            break;
        default:
            croak("PANIC!");
    }

    shvxs_array_NEW_ELEMS_SIG *sig;
    Newxz(sig, 1, shvxs_array_NEW_ELEMS_SIG);
    UNPACKING_HV_FROM_SV (href, hv);
    UNPACKING_GET_ENUM   (hv, sig, arr_source,            ARRAY_SRC_INVOCANT, ArraySource);
    UNPACKING_GET_STRING (hv, sig, arr_source_string,     NULL);
    UNPACKING_GET_STRING (hv, sig, arr_source_fallback,   NULL);
    UNPACKING_GET_I32    (hv, sig, arr_source_index,      0);
    UNPACKING_GET_I32    (hv, sig, element_type,          TYPE_BASE_ANY);
    UNPACKING_GET_CV     (hv, sig, element_type_cv);
    UNPACKING_MAYBE_SV   (hv, sig, element_type_tiny,     has_element_type_tiny);
    UNPACKING_GET_CV     (hv, sig, element_coercion_cv);
    UNPACKING_GET_ENUM   (hv, sig, method_return_pattern, rp, ReturnPattern);
    UNPACKING_GET_STRING (hv, sig, method_return_class,       NULL);
    UNPACKING_GET_STRING (hv, sig, method_return_constructor, NULL);

    if (sig->element_type != TYPE_BASE_ANY && sig->element_type_cv == NULL) {
        croak("element_type_cv is required unless element_type is TYPE_BASE_ANY");
    }

    CV *cv = newXS( SvPV_nolen(name), op, (char *)__FILE__ );
    CvXSUBANY(cv).any_ptr = sig;
    XSRETURN_EMPTY;
}
#line 1437 "XS.c"
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Sub__HandlesVia__XS_INSTALL_shvxs_array_INDEX); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Sub__HandlesVia__XS_INSTALL_shvxs_array_INDEX)
{
    dVAR; dXSARGS;
    dXSI32;
    if (items != 2)
       croak_xs_usage(cv,  "name, href");
    {
	SV *	name = ST(0)
;
	SV *	href = ST(1)
;
#line 1109 "XS.xs"
{
    dTHX;

    XSUBADDR_t op;
    enum ReturnPattern rp;
    switch ( ix ) {
        case 1:
        case 2:
        case 3:
            op = XS_Sub__HandlesVia__XS_shvxs_array_get;
            rp = SHOULD_RETURN_VAL;
            break;
        default:
            croak("PANIC!");
    }

    shvxs_array_INDEX_SIG *sig;
    Newxz(sig, 1, shvxs_array_INDEX_SIG);
    UNPACKING_HV_FROM_SV (href, hv);
    UNPACKING_GET_ENUM   (hv, sig, arr_source,            ARRAY_SRC_INVOCANT, ArraySource);
    UNPACKING_GET_STRING (hv, sig, arr_source_string,     NULL);
    UNPACKING_GET_STRING (hv, sig, arr_source_fallback,   NULL);
    UNPACKING_GET_I32    (hv, sig, arr_source_index,      0);
    UNPACKING_MAYBE_I32  (hv, sig, index, has_index);
    UNPACKING_GET_ENUM   (hv, sig, method_return_pattern, rp, ReturnPattern);
    UNPACKING_GET_STRING (hv, sig, method_return_class,       NULL);
    UNPACKING_GET_STRING (hv, sig, method_return_constructor, NULL);

    if ( ix == 2 ) {
        sig->has_index = TRUE;
        sig->index     = 0;
    }
    else if ( ix == 3 ) {
        sig->has_index = TRUE;
        sig->index     = -1;
    }

    CV *cv = newXS( SvPV_nolen(name), op, (char *)__FILE__ );
    CvXSUBANY(cv).any_ptr = sig;
    XSRETURN_EMPTY;
}
#line 1497 "XS.c"
    }
    XSRETURN_EMPTY;
}


XS_EUPXS(XS_Sub__HandlesVia__XS_INSTALL_shvxs_array_SETTER); /* prototype to pass -Wmissing-prototypes */
XS_EUPXS(XS_Sub__HandlesVia__XS_INSTALL_shvxs_array_SETTER)
{
    dVAR; dXSARGS;
    dXSI32;
    if (items != 2)
       croak_xs_usage(cv,  "name, href");
    {
	SV *	name = ST(0)
;
	SV *	href = ST(1)
;
#line 1159 "XS.xs"
{
    dTHX;

    XSUBADDR_t op;
    enum ReturnPattern rp;
    switch ( ix ) {
        case 1:
            op = XS_Sub__HandlesVia__XS_shvxs_array_set;
            rp = SHOULD_RETURN_VAL;
            break;
        case 2:
            op = XS_Sub__HandlesVia__XS_shvxs_array_accessor;
            rp = SHOULD_RETURN_VAL;
            break;
        default:
            croak("PANIC!");
    }

    shvxs_array_SETTER_SIG *sig;
    Newxz(sig, 1, shvxs_array_SETTER_SIG);
    UNPACKING_HV_FROM_SV (href, hv);
    UNPACKING_GET_ENUM   (hv, sig, arr_source,            ARRAY_SRC_INVOCANT, ArraySource);
    UNPACKING_GET_STRING (hv, sig, arr_source_string,     NULL);
    UNPACKING_GET_STRING (hv, sig, arr_source_fallback,   NULL);
    UNPACKING_GET_I32    (hv, sig, arr_source_index,      0);
    UNPACKING_MAYBE_I32  (hv, sig, index, has_index);
    UNPACKING_MAYBE_SV   (hv, sig, curried_sv, has_curried_sv);
    UNPACKING_GET_I32    (hv, sig, element_type,          TYPE_BASE_ANY);
    UNPACKING_GET_CV     (hv, sig, element_type_cv);
    UNPACKING_MAYBE_SV   (hv, sig, element_type_tiny,     has_element_type_tiny);
    UNPACKING_GET_CV     (hv, sig, element_coercion_cv);
    UNPACKING_GET_ENUM   (hv, sig, method_return_pattern, rp, ReturnPattern);
    UNPACKING_GET_STRING (hv, sig, method_return_class,       NULL);
    UNPACKING_GET_STRING (hv, sig, method_return_constructor, NULL);

    if (sig->element_type != TYPE_BASE_ANY && sig->element_type_cv == NULL) {
        croak("element_type_cv is required unless element_type is TYPE_BASE_ANY");
    }

    CV *cv = newXS( SvPV_nolen(name), op, (char *)__FILE__ );
    CvXSUBANY(cv).any_ptr = sig;
    XSRETURN_EMPTY;
}
#line 1559 "XS.c"
    }
    XSRETURN_EMPTY;
}

#ifdef __cplusplus
extern "C" {
#endif
XS_EXTERNAL(boot_Sub__HandlesVia__XS); /* prototype to pass -Wmissing-prototypes */
XS_EXTERNAL(boot_Sub__HandlesVia__XS)
{
#if PERL_VERSION_LE(5, 21, 5)
    dVAR; dXSARGS;
#else
    dVAR; dXSBOOTARGSXSAPIVERCHK;
#endif
#if PERL_VERSION_LE(5, 8, 999) /* PERL_VERSION_LT is 5.33+ */
    char* file = __FILE__;
#else
    const char* file = __FILE__;
#endif

    PERL_UNUSED_VAR(file);

    PERL_UNUSED_VAR(cv); /* -W */
    PERL_UNUSED_VAR(items); /* -W */
#if PERL_VERSION_LE(5, 21, 5)
    XS_VERSION_BOOTCHECK;
#  ifdef XS_APIVERSION_BOOTCHECK
    XS_APIVERSION_BOOTCHECK;
#  endif
#endif

    {
        CV * cv;

        newXS_deffile("Sub::HandlesVia::XS::shvxs_array_accessor", XS_Sub__HandlesVia__XS_shvxs_array_accessor);
        newXS_deffile("Sub::HandlesVia::XS::shvxs_array_all", XS_Sub__HandlesVia__XS_shvxs_array_all);
        newXS_deffile("Sub::HandlesVia::XS::shvxs_array_all_true", XS_Sub__HandlesVia__XS_shvxs_array_all_true);
        newXS_deffile("Sub::HandlesVia::XS::shvxs_array_any", XS_Sub__HandlesVia__XS_shvxs_array_any);
        newXS_deffile("Sub::HandlesVia::XS::shvxs_array_clear", XS_Sub__HandlesVia__XS_shvxs_array_clear);
        newXS_deffile("Sub::HandlesVia::XS::shvxs_array_count", XS_Sub__HandlesVia__XS_shvxs_array_count);
        newXS_deffile("Sub::HandlesVia::XS::shvxs_array_first", XS_Sub__HandlesVia__XS_shvxs_array_first);
        newXS_deffile("Sub::HandlesVia::XS::shvxs_array_for_each", XS_Sub__HandlesVia__XS_shvxs_array_for_each);
        newXS_deffile("Sub::HandlesVia::XS::shvxs_array_get", XS_Sub__HandlesVia__XS_shvxs_array_get);
        newXS_deffile("Sub::HandlesVia::XS::shvxs_array_grep", XS_Sub__HandlesVia__XS_shvxs_array_grep);
        newXS_deffile("Sub::HandlesVia::XS::shvxs_array_is_empty", XS_Sub__HandlesVia__XS_shvxs_array_is_empty);
        newXS_deffile("Sub::HandlesVia::XS::shvxs_array_join", XS_Sub__HandlesVia__XS_shvxs_array_join);
        newXS_deffile("Sub::HandlesVia::XS::shvxs_array_map", XS_Sub__HandlesVia__XS_shvxs_array_map);
        newXS_deffile("Sub::HandlesVia::XS::shvxs_array_pop", XS_Sub__HandlesVia__XS_shvxs_array_pop);
        newXS_deffile("Sub::HandlesVia::XS::shvxs_array_push", XS_Sub__HandlesVia__XS_shvxs_array_push);
        newXS_deffile("Sub::HandlesVia::XS::shvxs_array_reverse", XS_Sub__HandlesVia__XS_shvxs_array_reverse);
        newXS_deffile("Sub::HandlesVia::XS::shvxs_array_set", XS_Sub__HandlesVia__XS_shvxs_array_set);
        newXS_deffile("Sub::HandlesVia::XS::shvxs_array_shift", XS_Sub__HandlesVia__XS_shvxs_array_shift);
        newXS_deffile("Sub::HandlesVia::XS::shvxs_array_sort", XS_Sub__HandlesVia__XS_shvxs_array_sort);
        newXS_deffile("Sub::HandlesVia::XS::shvxs_array_unshift", XS_Sub__HandlesVia__XS_shvxs_array_unshift);
        cv = newXS_deffile("Sub::HandlesVia::XS::INSTALL_shvxs_array_SIMPLE", XS_Sub__HandlesVia__XS_INSTALL_shvxs_array_SIMPLE);
        XSANY.any_i32 = 0;
        cv = newXS_deffile("Sub::HandlesVia::XS::INSTALL_shvxs_array_all", XS_Sub__HandlesVia__XS_INSTALL_shvxs_array_SIMPLE);
        XSANY.any_i32 = 1;
        cv = newXS_deffile("Sub::HandlesVia::XS::INSTALL_shvxs_array_clear", XS_Sub__HandlesVia__XS_INSTALL_shvxs_array_SIMPLE);
        XSANY.any_i32 = 2;
        cv = newXS_deffile("Sub::HandlesVia::XS::INSTALL_shvxs_array_count", XS_Sub__HandlesVia__XS_INSTALL_shvxs_array_SIMPLE);
        XSANY.any_i32 = 3;
        cv = newXS_deffile("Sub::HandlesVia::XS::INSTALL_shvxs_array_is_empty", XS_Sub__HandlesVia__XS_INSTALL_shvxs_array_SIMPLE);
        XSANY.any_i32 = 4;
        cv = newXS_deffile("Sub::HandlesVia::XS::INSTALL_shvxs_array_pop", XS_Sub__HandlesVia__XS_INSTALL_shvxs_array_SIMPLE);
        XSANY.any_i32 = 5;
        cv = newXS_deffile("Sub::HandlesVia::XS::INSTALL_shvxs_array_reverse", XS_Sub__HandlesVia__XS_INSTALL_shvxs_array_SIMPLE);
        XSANY.any_i32 = 6;
        cv = newXS_deffile("Sub::HandlesVia::XS::INSTALL_shvxs_array_shift", XS_Sub__HandlesVia__XS_INSTALL_shvxs_array_SIMPLE);
        XSANY.any_i32 = 7;
        cv = newXS_deffile("Sub::HandlesVia::XS::INSTALL_shvxs_array_CALLBACK", XS_Sub__HandlesVia__XS_INSTALL_shvxs_array_CALLBACK);
        XSANY.any_i32 = 0;
        cv = newXS_deffile("Sub::HandlesVia::XS::INSTALL_shvxs_array_all_true", XS_Sub__HandlesVia__XS_INSTALL_shvxs_array_CALLBACK);
        XSANY.any_i32 = 6;
        cv = newXS_deffile("Sub::HandlesVia::XS::INSTALL_shvxs_array_any", XS_Sub__HandlesVia__XS_INSTALL_shvxs_array_CALLBACK);
        XSANY.any_i32 = 5;
        cv = newXS_deffile("Sub::HandlesVia::XS::INSTALL_shvxs_array_first", XS_Sub__HandlesVia__XS_INSTALL_shvxs_array_CALLBACK);
        XSANY.any_i32 = 4;
        cv = newXS_deffile("Sub::HandlesVia::XS::INSTALL_shvxs_array_for_each", XS_Sub__HandlesVia__XS_INSTALL_shvxs_array_CALLBACK);
        XSANY.any_i32 = 1;
        cv = newXS_deffile("Sub::HandlesVia::XS::INSTALL_shvxs_array_grep", XS_Sub__HandlesVia__XS_INSTALL_shvxs_array_CALLBACK);
        XSANY.any_i32 = 2;
        cv = newXS_deffile("Sub::HandlesVia::XS::INSTALL_shvxs_array_map", XS_Sub__HandlesVia__XS_INSTALL_shvxs_array_CALLBACK);
        XSANY.any_i32 = 3;
        cv = newXS_deffile("Sub::HandlesVia::XS::INSTALL_shvxs_array_sort", XS_Sub__HandlesVia__XS_INSTALL_shvxs_array_CALLBACK);
        XSANY.any_i32 = 7;
        cv = newXS_deffile("Sub::HandlesVia::XS::INSTALL_shvxs_array_SV", XS_Sub__HandlesVia__XS_INSTALL_shvxs_array_SV);
        XSANY.any_i32 = 0;
        cv = newXS_deffile("Sub::HandlesVia::XS::INSTALL_shvxs_array_join", XS_Sub__HandlesVia__XS_INSTALL_shvxs_array_SV);
        XSANY.any_i32 = 1;
        cv = newXS_deffile("Sub::HandlesVia::XS::INSTALL_shvxs_array_NEW_ELEMS", XS_Sub__HandlesVia__XS_INSTALL_shvxs_array_NEW_ELEMS);
        XSANY.any_i32 = 0;
        cv = newXS_deffile("Sub::HandlesVia::XS::INSTALL_shvxs_array_push", XS_Sub__HandlesVia__XS_INSTALL_shvxs_array_NEW_ELEMS);
        XSANY.any_i32 = 1;
        cv = newXS_deffile("Sub::HandlesVia::XS::INSTALL_shvxs_array_unshift", XS_Sub__HandlesVia__XS_INSTALL_shvxs_array_NEW_ELEMS);
        XSANY.any_i32 = 2;
        cv = newXS_deffile("Sub::HandlesVia::XS::INSTALL_shvxs_array_INDEX", XS_Sub__HandlesVia__XS_INSTALL_shvxs_array_INDEX);
        XSANY.any_i32 = 0;
        cv = newXS_deffile("Sub::HandlesVia::XS::INSTALL_shvxs_array_get", XS_Sub__HandlesVia__XS_INSTALL_shvxs_array_INDEX);
        XSANY.any_i32 = 1;
        cv = newXS_deffile("Sub::HandlesVia::XS::INSTALL_shvxs_array_peek", XS_Sub__HandlesVia__XS_INSTALL_shvxs_array_INDEX);
        XSANY.any_i32 = 2;
        cv = newXS_deffile("Sub::HandlesVia::XS::INSTALL_shvxs_array_peekend", XS_Sub__HandlesVia__XS_INSTALL_shvxs_array_INDEX);
        XSANY.any_i32 = 3;
        cv = newXS_deffile("Sub::HandlesVia::XS::INSTALL_shvxs_array_SETTER", XS_Sub__HandlesVia__XS_INSTALL_shvxs_array_SETTER);
        XSANY.any_i32 = 0;
        cv = newXS_deffile("Sub::HandlesVia::XS::INSTALL_shvxs_array_accessor", XS_Sub__HandlesVia__XS_INSTALL_shvxs_array_SETTER);
        XSANY.any_i32 = 2;
        cv = newXS_deffile("Sub::HandlesVia::XS::INSTALL_shvxs_array_set", XS_Sub__HandlesVia__XS_INSTALL_shvxs_array_SETTER);
        XSANY.any_i32 = 1;
    }

    /* Initialisation Section */

#line 78 "XS.xs"
{
    HV *stash = gv_stashpv("Sub::HandlesVia::XS", GV_ADD);

    INSTALL_CONST(stash, TYPE_BASE_ANY);
    INSTALL_CONST(stash, TYPE_BASE_DEFINED);
    INSTALL_CONST(stash, TYPE_BASE_REF);
    INSTALL_CONST(stash, TYPE_BASE_BOOL);
    INSTALL_CONST(stash, TYPE_BASE_INT);
    INSTALL_CONST(stash, TYPE_BASE_PZINT);
    INSTALL_CONST(stash, TYPE_BASE_NUM);
    INSTALL_CONST(stash, TYPE_BASE_PZNUM);
    INSTALL_CONST(stash, TYPE_BASE_STR);
    INSTALL_CONST(stash, TYPE_BASE_NESTR);
    INSTALL_CONST(stash, TYPE_BASE_CLASSNAME);
    INSTALL_CONST(stash, TYPE_BASE_OBJECT);
    INSTALL_CONST(stash, TYPE_BASE_SCALARREF);
    INSTALL_CONST(stash, TYPE_BASE_CODEREF);
    INSTALL_CONST(stash, TYPE_OTHER);
    INSTALL_CONST(stash, TYPE_ARRAYREF);
    INSTALL_CONST(stash, TYPE_HASHREF);

    INSTALL_CONST(stash, ARRAY_SRC_INVOCANT);
    INSTALL_CONST(stash, ARRAY_SRC_DEREF_SCALAR);
    INSTALL_CONST(stash, ARRAY_SRC_DEREF_ARRAY);
    INSTALL_CONST(stash, ARRAY_SRC_DEREF_HASH);
    INSTALL_CONST(stash, ARRAY_SRC_CALL_METHOD);

    INSTALL_CONST(stash, SHOULD_RETURN_NOTHING);
    INSTALL_CONST(stash, SHOULD_RETURN_UNDEF);
    INSTALL_CONST(stash, SHOULD_RETURN_FALSE);
    INSTALL_CONST(stash, SHOULD_RETURN_TRUE);
    INSTALL_CONST(stash, SHOULD_RETURN_INVOCANT);
    INSTALL_CONST(stash, SHOULD_RETURN_OTHER);
    INSTALL_CONST(stash, SHOULD_RETURN_ARRAY);
    INSTALL_CONST(stash, SHOULD_RETURN_ARRAYBLESS);
    INSTALL_CONST(stash, SHOULD_RETURN_OUT);
    INSTALL_CONST(stash, SHOULD_RETURN_OUTBLESS);
    INSTALL_CONST(stash, SHOULD_RETURN_VAL);
    INSTALL_CONST(stash, SHOULD_RETURN_COUNT);
}

#line 1717 "XS.c"

    /* End of Initialisation Section */

#if PERL_VERSION_LE(5, 21, 5)
#  if PERL_VERSION_GE(5, 9, 0)
    if (PL_unitcheckav)
        call_list(PL_scopestack_ix, PL_unitcheckav);
#  endif
    XSRETURN_YES;
#else
    Perl_xs_boot_epilog(aTHX_ ax);
#endif
}

#ifdef __cplusplus
}
#endif
