Chandra

 view release on metacpan or  search on metacpan

include/chandra/chandra.h  view on Meta::CPAN


    hFind = FindFirstFileA(pattern, &fdata);
    if (hFind == INVALID_HANDLE_VALUE) return;

    do {
        const char *name = fdata.cFileName;
        SV *fullpath_sv;
        const char *fullpv;
        STRLEN fulllen;

        if (name[0] == '.') {
            if (name[1] == '\0') continue;
            if (name[1] == '.' && name[2] == '\0') continue;
        }

        fullpath_sv = newSVpvf("%s/%s", dir, name);
        fullpv = SvPV(fullpath_sv, fulllen);

        if (fdata.dwFileAttributes & FILE_ATTRIBUTE_DIRECTORY) {
            _hotreload_scan_recursive(aTHX_ fullpv, files_hv);
        } else {
            /* Convert FILETIME to Unix epoch seconds */
            ULARGE_INTEGER ull;
            ull.LowPart  = fdata.ftLastWriteTime.dwLowDateTime;
            ull.HighPart = fdata.ftLastWriteTime.dwHighDateTime;
            (void)hv_store(files_hv, fullpv, (I32)fulllen,
                newSVnv((NV)((double)ull.QuadPart / 10000000.0 - 11644473600.0)), 0);
        }

        SvREFCNT_dec(fullpath_sv);
    } while (FindNextFileA(hFind, &fdata));

    FindClose(hFind);
}
#else
#include <dirent.h>
static void
_hotreload_scan_recursive(pTHX_ const char *dir, HV *files_hv)
{
    DIR *dh;
    struct dirent *entry;

    dh = opendir(dir);
    if (!dh) return;

    while ((entry = readdir(dh)) != NULL) {
        const char *name = entry->d_name;
        SV *fullpath_sv;
        const char *fullpv;
        STRLEN fulllen;
        Stat_t st;

        if (name[0] == '.') {
            if (name[1] == '\0') continue;
            if (name[1] == '.' && name[2] == '\0') continue;
        }

        fullpath_sv = newSVpvf("%s/%s", dir, name);
        fullpv = SvPV(fullpath_sv, fulllen);

        if (PerlLIO_stat(fullpv, &st) == 0) {
            if (S_ISREG(st.st_mode)) {
                (void)hv_store(files_hv, fullpv, (I32)fulllen,
                    newSVnv((NV)st.st_mtime), 0);
            } else if (S_ISDIR(st.st_mode)) {
                _hotreload_scan_recursive(aTHX_ fullpv, files_hv);
            }
        }

        SvREFCNT_dec(fullpath_sv);
    }

    closedir(dh);
}
#endif

/* ---- DevTools static XS callbacks ---- */

static XS(xs_devtools_list_bindings)
{
    dXSARGS;
    PERL_UNUSED_VAR(cv);
    PERL_UNUSED_VAR(items);
    {
        dSP;
        int count;
        AV *result_av;
        SV *bind;

        ENTER; SAVETMPS;

        PUSHMARK(SP);
        XPUSHs(sv_2mortal(newSVpvs("Chandra::Bind")));
        PUTBACK;
        count = call_method("new", G_SCALAR);
        SPAGAIN;
        bind = (count > 0) ? POPs : &PL_sv_undef;
        SvREFCNT_inc_simple_void(bind);
        PUTBACK;

        PUSHMARK(SP);
        XPUSHs(bind);
        PUTBACK;
        count = call_method("list", G_ARRAY);
        SPAGAIN;

        result_av = newAV();
        while (count-- > 0) {
            SV *name = POPs;
            const char *n = SvPV_nolen(name);
            if (strncmp(n, "__devtools_", 11) != 0) {
                av_push(result_av, newSVsv(name));
            }
        }
        PUTBACK;

        if (av_len(result_av) >= 1) {
            sortsv(AvARRAY(result_av), (size_t)(av_len(result_av) + 1),
                   Perl_sv_cmp);
        }



( run in 0.918 second using v1.01-cache-2.11-cpan-39bf76dae61 )