Nginx-Perl
view release on metacpan or search on metacpan
src/http/modules/perl/ngx_http_perl_module.c view on Meta::CPAN
if (n++) {
m = pmcf->modules->elts;
for (i = 0; i < pmcf->modules->nelts; i++) {
embedding[2 * i + 1] = "-I";
embedding[2 * i + 2] = (char *) m[i].data;
}
}
embedding[n++] = "-MNginx";
embedding[n++] = "-e";
embedding[n++] = "0";
embedding[n] = NULL;
n = perl_parse(my_perl, ngx_http_perl_xs_init, n, embedding, NULL);
if (n != 0) {
ngx_log_error(NGX_LOG_ALERT, cf->log, 0, "perl_parse() failed: %d", n);
goto fail;
}
sv = get_sv("Nginx::VERSION", FALSE);
ver = SvPV(sv, len);
if (ngx_strcmp(ver, NGINX_VERSION) != 0) {
ngx_log_error(NGX_LOG_ALERT, cf->log, 0,
"version " NGINX_VERSION " of Nginx.pm is required, "
"but %s was found", ver);
goto fail;
}
if (ngx_http_perl_run_requires(aTHX_ pmcf->requires, cf->log) != NGX_OK) {
goto fail;
}
}
return my_perl;
fail:
(void) perl_destruct(my_perl);
perl_free(my_perl);
return NULL;
}
static ngx_int_t
ngx_http_perl_run_requires(pTHX_ ngx_array_t *requires, ngx_log_t *log)
{
u_char *err;
STRLEN len;
ngx_str_t *script;
ngx_uint_t i;
if (requires == NGX_CONF_UNSET_PTR) {
return NGX_OK;
}
script = requires->elts;
for (i = 0; i < requires->nelts; i++) {
require_pv((char *) script[i].data);
if (SvTRUE(ERRSV)) {
err = (u_char *) SvPV(ERRSV, len);
while (--len && (err[len] == CR || err[len] == LF)) { /* void */ }
ngx_log_error(NGX_LOG_EMERG, log, 0,
"require_pv(\"%s\") failed: \"%*s\"",
script[i].data, len + 1, err);
return NGX_ERROR;
}
}
return NGX_OK;
}
static ngx_int_t
ngx_http_perl_call_handler(pTHX_ ngx_http_request_t *r, SV *sub,
SV **args, ngx_str_t *handler, ngx_str_t *rv)
{
int n, status;
char *line;
u_char *err;
STRLEN len, n_a;
ngx_uint_t i;
ngx_connection_t *c;
ngx_http_perl_ctx_t *ctx;
dSP;
ctx = ngx_http_get_module_ctx(r, ngx_http_perl_module);
status = 0;
ENTER;
SAVETMPS;
PUSHMARK(sp);
XPUSHs(ctx->r);
if (args) {
EXTEND(sp, (intptr_t) args[0]);
for (i = 1; i <= (uintptr_t) args[0]; i++) {
PUSHs(sv_2mortal(args[i]));
}
}
PUTBACK;
c = r->connection;
n = call_sv(sub, G_EVAL);
( run in 2.124 seconds using v1.01-cache-2.11-cpan-39bf76dae61 )