xs/reqid.xs

filter: Statementstmt 100% 15 / 15 Branchbran 66.6% 12 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 81.8% 27 / 33 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« include/punk/punk_import.h ↑ Summary include/punk/punk_i18n.h »
1 MODULE = Punk PACKAGE = Punk::Plugin::RequestId
2  
3 PROTOTYPES: DISABLE
4  
5 # The whole plugin's request path lives in include/punk/punk_reqid.h. What is
6 # exposed here is registration and one mint, which is all lib/Punk/Plugin/
7 # RequestId.pm needs.
8  
9 # _enable($app, $header_name_or_undef)
10 #
11 # Registers the process-wide observers once, and freezes THIS app's header
12 # name onto its app hash - beside where the `session` and `csrf` keywords keep
13 # theirs. Per-app, because two Punk apps can share a process under
14 # Plack::Builder and a header name held in a static made the last one to
15 # register name the header for both.
16 #
17 # An undefined header stores a false value rather than nothing: "the plugin is
18 # loaded and the header is off" has to stay distinguishable from "this app
19 # never loaded the plugin", or an app without the plugin would still mint ids.
20 # (Starting that sentence with the word `undef` made the line read as a cpp
21 # #undef directive - the xsubpp trap this workspace has met before.)
22 IV
23 _enable(class, app, header = &PL_sv_undef, envkey = &PL_sv_undef)
24 SV *class
25 SV *app
26 SV *header
27 SV *envkey
28 CODE:
29 {
30 15 HV *h = app_hv(aTHX_ app);
31 15 AV *cfg = newAV();
32 15 ▶ av_push(cfg, (SvOK(header) && SvTRUE(header))
Branch: 2 branches
BranchTrueFalseTotal
av_push(cfg, (SvOK(header) && SvTRUE(header)) 14 1 15
av_push(cfg, (SvOK(header) && SvTRUE(header)) 14 0 14
33 ? newSVsv(header) : newSViv(0));
34 15 ▶ av_push(cfg, (SvOK(envkey) && SvTRUE(envkey))
Branch: 2 branches
BranchTrueFalseTotal
av_push(cfg, (SvOK(envkey) && SvTRUE(envkey)) 3 12 15
av_push(cfg, (SvOK(envkey) && SvTRUE(envkey)) 3 0 3
35 ? newSVsv(envkey) : newSV(0));
36 15 (void)hv_stores(h, PR_APP_KEY, newRV_noinc((SV *)cfg));
37 PERL_UNUSED_VAR(class);
38 15 ▶ RETVAL = pr_enable(aTHX);
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = pr_enable(aTHX); 10 5 15
39 }
40 OUTPUT:
41 RETVAL
42  
43 # One id, for a caller that wants one outside a request - and for the tests
44 # that assert uniqueness and format without standing a server up.
45 SV *
46 _mint(class = &PL_sv_undef)
47 SV *class
48 CODE:
49 PERL_UNUSED_VAR(class);
50 10007 RETVAL = pr_mint(aTHX);
51 OUTPUT:
52 RETVAL
53  
54 # $c->request_id - installed as the helper itself, so the accessor is an XSUB
55 # rather than a Perl closure wrapping one.
56 SV *
57 _id(c)
58 SV *c
59 CODE:
60 {
61 46 AV *av = pcx_av(aTHX_ c);
62 46 ▶ SV *id = av ? pcx_get(aTHX_ av, PCX_REQID) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
SV *id = av ? pcx_get(aTHX_ av, PCX_REQID) : NULL; 46 0 46
63 46 ▶ RETVAL = (id && SvOK(id)) ? newSVsv(id) : newSV(0);
Branch: 2 branches
BranchTrueFalseTotal
RETVAL = (id && SvOK(id)) ? newSVsv(id) : newSV(0); 46 0 46
RETVAL = (id && SvOK(id)) ? newSVsv(id) : newSV(0); 46 0 46
64 }
65 OUTPUT:
66 RETVAL
67  
68 # What the plugin has done, process-wide. `adopted` and `rejected` are only
69 # ever non-zero where trust_header is on, and a rising `rejected` is somebody
70 # sending ids that are not ids - which is worth being able to see rather than
71 # discarding silently.
72 void
73 stats(class = &PL_sv_undef)
74 SV *class
75 PPCODE:
76 {
77 PERL_UNUSED_VAR(class);
78 4 ▶ EXTEND(SP, 6);
Branch: 1 branch
BranchTrueFalseTotal
EXTEND(SP, 6); 0 4 4
79 4 mPUSHs(newSVpvs("minted")); mPUSHu(pr_n_minted);
80 4 mPUSHs(newSVpvs("adopted")); mPUSHu(pr_n_adopted);
81 4 mPUSHs(newSVpvs("rejected")); mPUSHu(pr_n_rejected);
82 4 XSRETURN(6);
83 }
« include/punk/punk_import.h ↑ Summary include/punk/punk_i18n.h »