1
/* Copyright 2001-2004 The Apache Software Foundation
3
* Licensed under the Apache License, Version 2.0 (the "License");
4
* you may not use this file except in compliance with the License.
5
* You may obtain a copy of the License at
7
* http://www.apache.org/licenses/LICENSE-2.0
9
* Unless required by applicable law or agreed to in writing, software
10
* distributed under the License is distributed on an "AS IS" BASIS,
11
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
12
* See the License for the specific language governing permissions and
13
* limitations under the License.
1
16
#include "mod_perl.h"
3
18
modperl_handler_t *modperl_handler_new(apr_pool_t *p, const char *name)
15
30
/* XXX: currently a noop; should disable autoload of given handler
16
31
* if PerlOptions +AutoLoad is configured
32
* see: modperl_hash_handlers in modperl_mgv.c
18
34
MpHandlerAUTOLOAD_Off(handler);
22
39
handler->name = name;
23
40
MP_TRACE_h(MP_FUNC, "[%s] new handler %s\n",
24
41
modperl_pid_tid(p), handler->name);
48
modperl_handler_t *modperl_handler_new_anon(pTHX_ apr_pool_t *p, CV *cv)
50
modperl_handler_t *handler =
51
(modperl_handler_t *)apr_pcalloc(p, sizeof(*handler));
52
MpHandlerPARSED_On(handler);
53
MpHandlerANON_On(handler);
56
/* XXX: perhaps we can optimize this further. At the moment when
57
* perl w/ ithreads is used, we always deparse the anon subs
58
* before storing them and then eval them each time they are
59
* used. This is because we don't know whether the same perl that
60
* compiled the anonymous sub is used to run it.
62
* A possible optimization is to cache the CV and use that cached
63
* value w/ or w/o deparsing at all if:
65
* - the mpm is non-threaded mpm and no +Clone/+Parent is used
66
* (i.e. no perl pools) (no deparsing is needed at all)
68
* - the interpreter that has supplied the anon cv is the same
69
* interpreter that is executing that cv (requires storing aTHX
70
* in the handler's struct) (need to deparse in case the
71
* interpreter gets switched)
76
handler->name = modperl_coderef2text(aTHX_ p, cv);
77
MP_TRACE_h(MP_FUNC, "[%s] new deparsed anon handler:\n%s\n",
78
modperl_pid_tid(p), handler->name);
80
/* it's safe to cache and later use the cv, since the same perl
81
* interpeter is always used */
84
MP_TRACE_h(MP_FUNC, "[%s] new cached cv anon handler\n",
92
const char *modperl_handler_name(modperl_handler_t *handler)
94
/* a handler containing an anonymous sub doesn't have a normal sub
96
return handler->name ? handler->name : "anonymous sub";
29
100
int modperl_handler_resolve(pTHX_ modperl_handler_t **handp,
30
101
apr_pool_t *p, server_rec *s)
393
modperl_handler_t *modperl_handler_new_from_sv(pTHX_ apr_pool_t *p, SV *sv)
402
switch (SvTYPE(sv)) {
405
return modperl_handler_new(p, apr_pstrdup(p, name));
408
if (CvANON((CV*)sv)) {
409
return modperl_handler_new_anon(aTHX_ p, (CV*)sv);
411
if (!(gv = CvGV((CV*)sv))) {
412
Perl_croak(aTHX_ "can't resolve the code reference");
414
name = apr_pstrcat(p, HvNAME(GvSTASH(gv)), "::", GvNAME(gv), NULL);
415
return modperl_handler_new(p, apr_pstrdup(p, name));
322
422
int modperl_handler_push_handlers(pTHX_ apr_pool_t *p,
323
423
MpAV *handlers, SV *sv)
425
modperl_handler_t *handler = modperl_handler_new_from_sv(aTHX_ p, sv);
327
if ((handler_name = modperl_mgv_name_from_sv(aTHX_ p, sv))) {
328
modperl_handler_t *handler =
329
modperl_handler_new(p, apr_pstrdup(p, handler_name));
330
428
modperl_handler_array_push(handlers, handler);