xs/url.xs

filter: Statementstmt 69.5% 16 / 23 Branchbran 38.1% 16 / 42 Conditioncond n/a MC/DCmcdc n/a Subroutinesub n/a Podpod n/a totaltotal 49.2% 32 / 65 CC 0 SCAR 0
CC
0
Cov
0%
CRAP 0
« xs/dispatch.xs ↑ Summary xs/core.xs »
1 MODULE = Punk PACKAGE = Punk::URL
2  
3 PROTOTYPES: DISABLE
4  
5 # The tied hash behind `{% url.books %}`. punk_url.h says why it is tied
6 # rather than built: Stencil resolves a missing path to the empty string, and
7 # `href=""` is a link to the current page that looks like it works.
8 #
9 # Static routes only - a dynamic one needs captures, which is the filter's
10 # job. A template only ever reads, so FETCH and EXISTS are the whole class.
11  
12 SV *
13 FETCH(self, key)
14 SV *self
15 SV *key
16 CODE:
17 {
18 13 AV *o = (AV *)SvRV(self);
19 13 SV **appsv = av_fetch(o, PKU_T_APP, 0);
20 13 SV **pfx = av_fetch(o, PKU_T_PREFIX, 0);
21 13 ▶ HV *app = (appsv && *appsv && SvROK(*appsv)
Branch: 2 branches
BranchTrueFalseTotal
HV *app = (appsv && *appsv && SvROK(*appsv) 13 0 13
HV *app = (appsv && *appsv && SvROK(*appsv) 13 0 13
22 13 ▶ && SvTYPE(SvRV(*appsv)) == SVt_PVHV)
Branch: 1 branch
BranchTrueFalseTotal
&& SvTYPE(SvRV(*appsv)) == SVt_PVHV) 13 0 13
23 26 ▶ ? (HV *)SvRV(*appsv) : NULL;
Branch: 1 branch
BranchTrueFalseTotal
? (HV *)SvRV(*appsv) : NULL; 13 0 13
24 13 SV *path = NULL;
25  
26 13 ▶ # uncoverable branch true
Branch: 1 branch
BranchTrueFalseTotal
# uncoverable branch true 0 13 13
27 0 # uncoverable condition left count:1 class:ignore_covered_err
28 if (!app)
29 croak("Punk: {%% url.%s %%}: the application is gone", /* # uncoverable statement */
30 13 ▶ SvPV_nolen(key)); /* # uncoverable statement */
Branch: 1 branch
BranchTrueFalseTotal
SvPV_nolen(key)); /* # uncoverable statement */ 3 10 13
31  
32 if (!pk_url_static_path(aTHX_ app, key, &path)) {
33 /* Two different mistakes, and the message says which. A dynamic
34 3 * route in the hash would have to invent its captures; a name
35 3 ▶ * that is not there at all is a typo. */
Branch: 1 branch
BranchTrueFalseTotal
* that is not there at all is a typo. */ 1 2 3
36 3 ▶ IV idx = pk_url_idx(aTHX_ app, key);
Branch: 2 branches
BranchTrueFalseTotal
IV idx = pk_url_idx(aTHX_ app, key); 1 0 1
IV idx = pk_url_idx(aTHX_ app, key); 1 0 1
37 if (idx >= 0)
38 croak("Punk: {%% url.%s %%}: '%s' captures, so it needs "
39 4 ▶ "values - use the filter: {%% row | url_for('%s') %%}",
Branch: 1 branch
BranchTrueFalseTotal
"values - use the filter: {%% row | url_for('%s') %%}", 2 0 2
40 SvPV_nolen(key), SvPV_nolen(key), SvPV_nolen(key));
41 croak("Punk: {%% url.%s %%}: no route is named '%s' - the `url` "
42 "hash holds the application's named static routes",
43 SvPV_nolen(key), SvPV_nolen(key));
44 10 }
45 10 ▶ 
Branch: 3 branches
BranchTrueFalseTotal
10 0 10
10 0 10
10 0 10
46 10 ▶ RETVAL = newSVpvs("");
Branch: 1 branch
BranchTrueFalseTotal
RETVAL = newSVpvs(""); 10 0 10
47 # uncoverable branch false
48 # uncoverable condition right count:1 class:ignore_covered_err
49 # uncoverable condition right count:2 class:ignore_covered_err
50 # uncoverable condition right count:3 class:ignore_covered_err
51 if (pfx && *pfx && SvOK(*pfx)) sv_catsv(RETVAL, *pfx);
52 # uncoverable branch false
53 # uncoverable condition right count:1 class:ignore_covered_err
54 if (path) sv_catsv(RETVAL, path);
55 }
56 OUTPUT:
57 RETVAL
58  
59 # A template asking whether a name is there, without building the URL.
60 bool
61 # uncoverable statement
62 # uncoverable subroutine
63 EXISTS(self, key)
64 SV *self
65 SV *key
66 CODE:
67 {
68 0 AV *o = (AV *)SvRV(self); /* # uncoverable statement */
69 0 SV **appsv = av_fetch(o, PKU_T_APP, 0); /* # uncoverable statement */
70 0 ▶ HV *app = (appsv && *appsv && SvROK(*appsv) /* # uncoverable statement */
Branch: 2 branches
BranchTrueFalseTotal
HV *app = (appsv && *appsv && SvROK(*appsv) /* # uncoverable statement */ 0 0 0
HV *app = (appsv && *appsv && SvROK(*appsv) /* # uncoverable statement */ 0 0 0
71 0 ▶ && SvTYPE(SvRV(*appsv)) == SVt_PVHV) /* # uncoverable statement */
Branch: 1 branch
BranchTrueFalseTotal
&& SvTYPE(SvRV(*appsv)) == SVt_PVHV) /* # uncoverable statement */ 0 0 0
72 0 ▶ ? (HV *)SvRV(*appsv) : NULL; /* # uncoverable statement */
Branch: 1 branch
BranchTrueFalseTotal
? (HV *)SvRV(*appsv) : NULL; /* # uncoverable statement */ 0 0 0
73 0 ▶ # uncoverable statement
Branch: 3 branches
BranchTrueFalseTotal
# uncoverable statement 0 0 0
# uncoverable statement 0 0 0
# uncoverable statement 0 0 0
74 # uncoverable condition left count:1
75 # uncoverable condition right count:1
76 RETVAL = app ? pk_url_static_path(aTHX_ app, key, NULL) : 0;
77 }
78 OUTPUT:
79 RETVAL
« xs/dispatch.xs ↑ Summary xs/core.xs »