| 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
| Branch | True | False | Total |
| 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
| Branch | True | False | Total |
| && SvTYPE(SvRV(*appsv)) == SVt_PVHV) |
13 |
0 |
13 |
|
| 23 |
26 |
▶ | ? (HV *)SvRV(*appsv) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| ? (HV *)SvRV(*appsv) : NULL; |
13 |
0 |
13 |
|
| 24 |
13 |
| SV *path = NULL; |
| 25 |
|
| |
| 26 |
13 |
▶ | if (!app) |
Branch: 1 branch
| Branch | True | False | Total |
| if (!app) |
0 |
13 |
13 |
|
| 27 |
0 |
| croak("Punk: {%% url.%s %%}: the application is gone", |
| 28 |
|
| SvPV_nolen(key)); |
| 29 |
|
| |
| 30 |
13 |
▶ | if (!pk_url_static_path(aTHX_ app, key, &path)) { |
Branch: 1 branch
| Branch | True | False | Total |
| if (!pk_url_static_path(aTHX_ app, key, &path)) { |
3 |
10 |
13 |
|
| 31 |
|
| /* Two different mistakes, and the message says which. A dynamic |
| 32 |
|
| * route in the hash would have to invent its captures; a name |
| 33 |
|
| * that is not there at all is a typo. */ |
| 34 |
3 |
| IV idx = pk_url_idx(aTHX_ app, key); |
| 35 |
3 |
▶ | if (idx >= 0) |
Branch: 1 branch
| Branch | True | False | Total |
| if (idx >= 0) |
1 |
2 |
3 |
|
| 36 |
3 |
▶ | croak("Punk: {%% url.%s %%}: '%s' captures, so it needs " |
Branch: 2 branches
| Branch | True | False | Total |
| croak("Punk: {%% url.%s %%}: '%s' captures, so it needs " |
1 |
0 |
1 |
| croak("Punk: {%% url.%s %%}: '%s' captures, so it needs " |
1 |
0 |
1 |
|
| 37 |
|
| "values - use the filter: {%% row | url_for('%s') %%}", |
| 38 |
|
| SvPV_nolen(key), SvPV_nolen(key), SvPV_nolen(key)); |
| 39 |
4 |
▶ | croak("Punk: {%% url.%s %%}: no route is named '%s' - the `url` " |
Branch: 1 branch
| Branch | True | False | Total |
| croak("Punk: {%% url.%s %%}: no route is named '%s' - the `url` " |
2 |
0 |
2 |
|
| 40 |
|
| "hash holds the application's named static routes", |
| 41 |
|
| SvPV_nolen(key), SvPV_nolen(key)); |
| 42 |
|
| } |
| 43 |
|
| |
| 44 |
10 |
| RETVAL = newSVpvs(""); |
| 45 |
10 |
▶ | if (pfx && *pfx && SvOK(*pfx)) sv_catsv(RETVAL, *pfx); |
Branch: 3 branches
| Branch | True | False | Total |
| if (pfx && *pfx && SvOK(*pfx)) sv_catsv(RETVAL, *pfx); |
10 |
0 |
10 |
| if (pfx && *pfx && SvOK(*pfx)) sv_catsv(RETVAL, *pfx); |
10 |
0 |
10 |
| if (pfx && *pfx && SvOK(*pfx)) sv_catsv(RETVAL, *pfx); |
10 |
0 |
10 |
|
| 46 |
10 |
▶ | if (path) sv_catsv(RETVAL, path); |
Branch: 1 branch
| Branch | True | False | Total |
| if (path) sv_catsv(RETVAL, path); |
10 |
0 |
10 |
|
| 47 |
|
| } |
| 48 |
|
| OUTPUT: |
| 49 |
|
| RETVAL |
| 50 |
|
| |
| 51 |
|
| # A template asking whether a name is there, without building the URL. |
| 52 |
|
| bool |
| 53 |
|
| EXISTS(self, key) |
| 54 |
|
| SV *self |
| 55 |
|
| SV *key |
| 56 |
|
| CODE: |
| 57 |
|
| { |
| 58 |
0 |
| AV *o = (AV *)SvRV(self); |
| 59 |
0 |
| SV **appsv = av_fetch(o, PKU_T_APP, 0); |
| 60 |
0 |
▶ | HV *app = (appsv && *appsv && SvROK(*appsv) |
Branch: 2 branches
| Branch | True | False | Total |
| HV *app = (appsv && *appsv && SvROK(*appsv) |
0 |
0 |
0 |
| HV *app = (appsv && *appsv && SvROK(*appsv) |
0 |
0 |
0 |
|
| 61 |
0 |
▶ | && SvTYPE(SvRV(*appsv)) == SVt_PVHV) |
Branch: 1 branch
| Branch | True | False | Total |
| && SvTYPE(SvRV(*appsv)) == SVt_PVHV) |
0 |
0 |
0 |
|
| 62 |
0 |
▶ | ? (HV *)SvRV(*appsv) : NULL; |
Branch: 1 branch
| Branch | True | False | Total |
| ? (HV *)SvRV(*appsv) : NULL; |
0 |
0 |
0 |
|
| 63 |
0 |
▶ | RETVAL = app ? pk_url_static_path(aTHX_ app, key, NULL) : 0; |
Branch: 3 branches
| Branch | True | False | Total |
| RETVAL = app ? pk_url_static_path(aTHX_ app, key, NULL) : 0; |
0 |
0 |
0 |
| RETVAL = app ? pk_url_static_path(aTHX_ app, key, NULL) : 0; |
0 |
0 |
0 |
| RETVAL = app ? pk_url_static_path(aTHX_ app, key, NULL) : 0; |
0 |
0 |
0 |
|
| 64 |
|
| } |
| 65 |
|
| OUTPUT: |
| 66 |
|
| RETVAL |