include/punk/punk_names.h

filter: Statementstmt 100% 12 / 12 Branchbran 71.4% 10 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 84.6% 22 / 26 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« xs/metrics.xs ↑ Summary include/punk/punk_static.h »
1 /* punk_names.h - the fixed strings the registrar and compiler use, named once.
2 *
3 * These are string-literal macros (not const char[]) on purpose: hv_fetchs,
4 * hv_stores and newSVpvs bake the length from a literal at compile time, and a
5 * macro that expands to a literal keeps that. So `hv_fetchs(h, K_PREFIX, 0)`
6 * and `newSVpvs(K_PREFIX)` still see a literal, and a require of a fixed module
7 * is a single compile-time-concatenated string ("require " PK_CONFIG ";") with
8 * nothing built at run time.
9 */
10  
11 #ifndef PUNK_NAMES_H
12 #define PUNK_NAMES_H
13  
14 /* ---- modules and classes -------------------------------------------------- */
15 #define PK_ROUTER "Punk::Router"
16 #define PK_SCOPE "Punk::Router::Scope"
17 #define PK_CONTEXT "Punk::Context"
18 #define PK_STATIC "Punk::Static"
19 #define PK_CONFIG "Punk::Config"
20 #define PK_MODEL "Punk::Model"
21 #define PK_VIEWS "Punk::Views"
22 #define PK_WEBSOCKET "Punk::WebSocket"
23 #define PK_MOUNT_OA "Punk::Mount::OpenAPI"
24 #define PK_MOUNT_MD "Punk::Mount::Markdown"
25 #define PK_OA_UI "Open::API::UI"
26  
27 /* the require of a fixed module, as one compile-time literal */
28 #define PK_REQUIRE(mod) ("require " mod ";")
29  
30 /* Require a module from C, at most one eval per module per process.
31 *
32 * Every require in the C layer goes through here rather than a bare
33 * eval_pv, because Perl_eval_sv on perls through 5.20 spends immortal
34 * references on every call - whatever is evaluated, error or not - and
35 * before 5.20 the immortals' refcounts are small and unprotected, so a
36 * path that re-requires per app build (the markdown mount did) drains
37 * PL_sv_undef toward a segfault under `punk dev`'s rebuild loop. A CPAN
38 * smoker on 5.20.0 caught it via t/0012-immortal-refcount.t.
39 *
40 * The %INC check makes the already-loaded case - every call after the
41 * first - eval-free. The one genuine first load still uses eval_pv so
42 * each caller keeps its own error handling (probe-and-fall-back sites
43 * pass fatal=0 and read ERRSV; boot-or-die sites pass fatal=1): a
44 * bounded handful of spends per process, which is what it always cost
45 * to load the module.
46 *
47 * Returns 1 when the module is loaded, 0 when the require failed and
48 * fatal was 0 (ERRSV holds why). */
49 981 static int pk_require_once(pTHX_ const char *mod, int fatal) {
50 981 SV *file = sv_newmortal();
51 const char *p;
52 HV *inc;
53 981 sv_setpvs(file, "");
54 12469 ▶ for (p = mod; *p; p++) {
Branch: 1 branch
BranchTrueFalseTotal
for (p = mod; *p; p++) { 11488 981 12469
55 11488 ▶ if (p[0] == ':' && p[1] == ':') { sv_catpvs(file, "/"); p++; }
Branch: 2 branches
BranchTrueFalseTotal
if (p[0] == ':' && p[1] == ':') { sv_catpvs(file, "/"); p++; } 932 10556 11488
if (p[0] == ':' && p[1] == ':') { sv_catpvs(file, "/"); p++; } 932 0 932
56 10556 else sv_catpvn(file, p, 1);
57 }
58 981 sv_catpvs(file, ".pm");
59 981 ▶ inc = GvHVn(PL_incgv);
Branch: 1 branch
BranchTrueFalseTotal
inc = GvHVn(PL_incgv); 981 0 981
60 981 ▶ if (inc && hv_exists_ent(inc, file, 0)) return 1;
Branch: 2 branches
BranchTrueFalseTotal
if (inc && hv_exists_ent(inc, file, 0)) return 1; 981 0 981
if (inc && hv_exists_ent(inc, file, 0)) return 1; 604 377 981
61 /* The name goes into Perl source. A `database backend` from punk.yml
62 * reaches here, so it is checked the way the keyword-named classes are
63 * (pk_require_src croaks on anything that is not a class name). */
64 377 (void)pk_require_src(aTHX_ mod);
65 376 eval_pv(form("require %s;", mod), fatal);
66 376 ▶ return SvTRUE(ERRSV) ? 0 : 1;
Branch: 1 branch
BranchTrueFalseTotal
return SvTRUE(ERRSV) ? 0 : 1; 376 0 376
67 }
68  
69 /* ---- caller-relative namespace pieces ------------------------------------- */
70 #define PK_NS_CONTROLLER "::Controller::"
71 #define PK_NS_MODEL "::Model::"
72 #define PK_SFX_CONTEXT "::_Context"
73  
74 /* ---- app-object slots ----------------------------------------------------- */
75 #define K_CALLER "caller"
76 #define K_ROUTER "router"
77 #define K_MOUNTS "mounts"
78 #define K_VIEWS "views"
79 #define K_DATABASES "databases"
80 #define K_ON_COMPILE "on_compile" /* [ [code, owner], ... ] run at to_app */
81 #define K_MODELS "models"
82 #define K_HOOKS "hooks"
83 #define K_BEFORE_R "before_request"
84 #define K_BEFORE_D "before_dispatch"
85 #define K_AFTER_D "after_dispatch"
86 #define K_BEFORE_RN "before_render"
87 #define K_AFTER_RES "after_response"
88 #define K_AFTER_RES_C "after_response_c" /* compiled chain, on the app */
89 #define K_MIDDLEWARE "middleware"
90 #define K_HELPERS "helpers"
91 #define K_KEYWORDS "keywords" /* plugin-installed DSL keywords */
92 #define K_ON_ERROR "on_error"
93 #define K_ON_NOT_FOUND "on_not_found"
94 #define K_COMPILED "compiled"
95 #define K_CONFIG "config"
96 #define K_API_MOUNTS "api_mounts"
97 #define K_WS_ROUTES "ws_routes"
98 #define K_SSE_ROUTES "sse_routes"
99 #define K_VALIDATE "validate"
100 #define K_VALIDATE_ROUTES "validate_routes"
101 #define K_SSE "sse"
102 #define K_DOCS "docs"
103 #define K_MODEL_AUTO "model_auto"
104 #define K_MODELS_C "models_compiled"
105 #define K_MODEL_CACHE "model_cache"
106 #define K_VIEWS_C "views_compiled"
107 #define K_MOUNTS_C "mounts_compiled"
108 #define K_CTX_DEFINED "ctx_defined"
109 #define K_UA "ua" /* the `ua` keyword's frozen config */
110 #define K_UA_AGENT "ua_agent" /* { agent => $fetch, pid => $$ } */
111  
112 /* ---- record / state / option keys ----------------------------------------- */
113 #define K_PREFIX "prefix"
114 #define K_LEN "len"
115 #define K_MOUNT "mount"
116 #define K_DIR "dir"
117 #define K_MD_DIR "md_dir"
118 #define K_MD_MOUNT "md_mount" /* compiled: this mount is a markdown site */
119 #define K_APP "app"
120 #define K_PATH "path"
121 #define K_METHOD "method"
122 #define K_TARGET "target"
123 #define K_GUARDS "guards"
124 #define K_OPTS "opts"
125 #define K_API "api"
126 #define K_OPS "ops"
127 #define K_MAX_BODY "max_body"
128 #define K_RECS "recs"
129 #define K_CTX "ctx"
130 #define K_BEFORE_REQ "before_req" /* compiled before_request chain */
131 #define K_BEFORE "before"
132 #define K_AFTER "after"
133 #define K_BEFORE_RENDER_C "before_render_c" /* compiled before_render chain */
134 #define K_CODE "code"
135 #define K_OWNER "owner"
136 #define K_WS "ws"
137 #define K_PID "pid"
138 #define K_DEFAULT "default"
139 #define K_AUTO "auto"
140 #define K_ONLY "only"
141 #define K_BLOCKING "blocking"
142 #define K_RESPONSE "response"
143 #define K_CSRF "csrf"
144 #define K_CORS "cors"
145 #define K_HEADERS "headers"
146 #define K_HEADERS_SCOPED "headers_scoped"
147 #define K_AUTH "auth"
148 #define K_PROXY "proxy"
149 #define K_COMPRESS "compress"
150 #define K_NOCOMPRESS_ROUTES "nocompress_routes"
151 #define K_MAXBODY_ROUTES "maxbody_routes"
152 #define K_SITEMAP "sitemap"
153 #define K_SITEMAP_ROUTES "sitemap_routes"
154 #define K_ETAG "etag"
155 #define K_ETAG_ROUTES "etag_routes"
156 #define K_LAST_MODIFIED "last_modified"
157 #define K_LM_ROUTES "last_modified_routes"
158 #define K_CGET "conditional_get" /* the plugin's on-switch */
159 #define K_IDEMPOTENT "idempotent"
160 #define K_IDEM_ROUTES "idempotent_routes"
161 #define K_RATE_LIMIT "rate_limit" /* the route option and the keyword */
162 #define K_RL_ROUTES "rate_limit_routes"
163 #define K_IDEM "idempotency" /* the plugin's config */
164 #define K_NAME "name" /* the route option and the record key */
165 #define K_NAMED_ROUTES "named_routes" /* accumulated { method, path, name } */
166 #define K_NAMES_C "names_c" /* compiled: name -> record index */
167 #define K_HOST_PATH_C "host_path_c" /* compiled: the path on `host` */
168 #define K_URL_PREFIX_C "url_prefix_c" /* the SV the url_for filter reads */
169 #define K_CSP "csp" /* Punk::Plugin::CSP config */
170 #define K_I18N "i18n" /* Punk::Plugin::I18n config */
171  
172 #endif /* PUNK_NAMES_H */
« xs/metrics.xs ↑ Summary include/punk/punk_static.h »