File Coverage

URI.xsi
Criterion Covered Total %
statement 90 109 82.5
branch 143 352 40.6
condition n/a
subroutine n/a
pod n/a
total 233 461 50.5


line stmt bran cond sub pod time code
1             MODE: INLINE
2              
3             static U32 uxs_hashval;
4              
5             MODULE = URI::XS PACKAGE = URI::XS
6             PROTOTYPES: DISABLE
7              
8             BOOT {
9 26 50         Stash stash(__PACKAGE__);
10 13           PERL_HASH(uxs_hashval, "URI::XS", 7);
11            
12 91 50         xs::exp::create_constants(stash, {
    50          
    50          
    50          
    50          
    50          
    100          
    0          
13             {"ALLOW_SUFFIX_REFERENCE", URI::Flags::allow_suffix_reference},
14             {"QUERY_PARAM_SEMICOLON", URI::Flags::query_param_semicolon},
15             {"ALLOW_EXTENDED_CHARS", URI::Flags::allow_extended_chars},
16            
17             // deprecated names
18             {"ALLOW_LEADING_AUTHORITY", URI::Flags::allow_suffix_reference},
19             {"PARAM_DELIM_SEMICOLON", URI::Flags::query_param_semicolon},
20 78 50         });
21 13 50         xs::exp::autoexport(stash);
    50          
22             }
23              
24             URI* new (SV* CLASS, string url = string(), int flags = 0) {
25 192           PROTO = CLASS;
26 96 50         RETVAL = make_backref(url, flags);
27 96 50         }
28 96 50          
29             string URI::url (SV* newval = NULL, int flags = 0) {
30 59 50         if (newval) {
31 0 0         THIS->assign(SvOK(newval) ? xs::in(newval) : "", flags);
    0          
    0          
    0          
    0          
32 0           XSRETURN_UNDEF;
33             }
34 59 50         RETVAL = THIS->to_string();
    50          
35             }
36            
37             string URI::scheme (SV* newval = NULL) : ALIAS(proto=1, protocol=2) {
38 79 100         if (newval) {
39 12 50         THIS->scheme(SvOK(newval) ? xs::in(newval) : "");
    0          
    0          
    50          
    100          
40 7           XSRETURN_UNDEF;
41             }
42 67 50         RETVAL = THIS->scheme();
43             PERL_UNUSED_VAR(ix);
44             }
45              
46             string URI::user_info (SV* newval = NULL) {
47 59 50         if (newval) {
48 0 0         THIS->user_info(SvOK(newval) ? xs::in(newval) : "");
    0          
    0          
    0          
    0          
49 0           XSRETURN_UNDEF;
50             }
51 59 50         RETVAL = THIS->user_info();
52             }
53            
54             string URI::host (SV* newval = NULL) {
55 67 100         if (newval) {
56 3 50         THIS->host(SvOK(newval) ? xs::in(newval) : "");
    0          
    0          
    50          
    50          
57 3           XSRETURN_UNDEF;
58             }
59 64 50         RETVAL = THIS->host();
60             }
61            
62             int URI::port (SV* newval = NULL) {
63 19 100         if (newval) {
64 2 50         THIS->port(SvIV(newval));
    0          
65 19           XSRETURN_UNDEF;
66             }
67 17           RETVAL = THIS->port();
68             }
69            
70             string URI::path (SV* newval = NULL) {
71 65 100         if (newval) {
72 2 50         THIS->path(SvOK(newval) ? xs::in(newval) : "");
    0          
    0          
    50          
    50          
73 2           XSRETURN_UNDEF;
74             }
75 63 50         RETVAL = THIS->path();
76             }
77            
78             string URI::query_string (SV* newval = NULL) {
79 76 100         if (newval) {
80 4 50         THIS->query_string(SvOK(newval) ? xs::in(newval) : "");
    0          
    0          
    50          
    50          
81 4           XSRETURN_UNDEF;
82             }
83 72 50         RETVAL = THIS->query_string();
    50          
84             }
85            
86             string URI::raw_query (SV* newval = NULL) {
87 1 50         if (newval) {
88 0 0         THIS->raw_query(SvOK(newval) ? xs::in(newval) : "");
    0          
    0          
    0          
    0          
89 0           XSRETURN_UNDEF;
90             }
91 1 50         RETVAL = THIS->raw_query();
    50          
92             }
93            
94             Ref URI::query (...) {
95 8 100         if (items > 1) {
96 2 50         add_query_args(THIS, MARK+2, items-1, true);
97 2           XSRETURN_UNDEF;
98             }
99 6 50         auto data = data_get(ST(0));
100 6 50         RETVAL = data->query_hash(THIS);
101             }
102            
103             void URI::add_query (...) {
104 3           add_query_args(THIS, MARK+2, items-1);
105             }
106              
107             string URI::param (string_view name, SV* val = NULL) : ALIAS(multiparam = 1) {
108 17 100         if (val) {
109 1 50         add_param(THIS, string(name), val, true);
    50          
    50          
110 1           XSRETURN_UNDEF;
111             }
112 16 100         if (ix == 0) { // param method
113 13 50         auto it = THIS->query().find(name);
    50          
114 13 50         if (it == THIS->query().cend()) XSRETURN_UNDEF;
    100          
115 12 50         RETVAL = it->second;
116             } else { // multiparam method
117 3 50         size_t nvals = THIS->query().count(name);
    50          
118 3           switch (nvals) {
119             case 0:
120 3           XSRETURN_EMPTY; break;
121             case 1:
122 1 50         RETVAL = THIS->query().find(name)->second; break;
    50          
    50          
123             default:
124 2           SP -= items;
125 2 50         EXTEND(SP, (int)nvals);
    50          
    0          
126 2 50         const auto& query = THIS->query();
127 2 50         auto pair = query.equal_range(name);
128 6 100         for (auto it = pair.first; it != pair.second; ++it) mPUSHp(it->second.data(), it->second.length());
    50          
129 2           XSRETURN(nvals);
130             }
131             }
132             }
133              
134             int URI::nparam () {
135 1 50         RETVAL = THIS->query().size();
136             }
137            
138             size_t URI::remove_param (string name) {
139 0 0         RETVAL = THIS->query().erase(name);
    0          
140             }
141            
142             string URI::fragment (SV* newval = NULL) : ALIAS(hash=1) {
143 122 100         if (newval) {
144 2 50         THIS->fragment(SvOK(newval) ? xs::in(newval) : "");
    0          
    0          
    50          
    50          
145 2           XSRETURN_UNDEF;
146             }
147 120 50         RETVAL = THIS->fragment();
148             PERL_UNUSED_VAR(ix);
149             }
150            
151             string URI::location (SV* newval = NULL) {
152 8 100         if (newval) {
153 2 50         THIS->location(SvOK(newval) ? xs::in(newval) : "");
    0          
    0          
    50          
    50          
154 2           XSRETURN_UNDEF;
155             }
156 6 50         RETVAL = THIS->location();
    50          
157             }
158              
159 63           uint16_t URI::explicit_port ()
160              
161 0           uint16_t URI::default_port ()
162              
163 2 50         string URI::explicit_location ()
    50          
164            
165             string URI::relative () : ALIAS(rel=1) {
166 2 50         RETVAL = THIS->relative();
    50          
167             PERL_UNUSED_VAR(ix);
168             }
169            
170             string URI::to_string (...) : ALIAS(as_string=1) {
171 243 50         RETVAL = THIS->to_string();
    50          
172             PERL_UNUSED_VAR(ix);
173             }
174              
175 13           bool URI::secure ()
176              
177             void URI::set (Sv source, int flags = 0) : ALIAS(assign=1) {
178             PERL_UNUSED_VAR(ix);
179 15 100         if (source.is_string()) THIS->assign(xs::in(source), flags);
    50          
    100          
180 4 50         else THIS->assign(*xs::in>(source));
    100          
181             }
182            
183             bool URI::equals (Sv other, ...) {
184 30 50         if (other.is_string()) RETVAL = THIS->to_string() == xs::in(other);
    50          
    50          
    50          
185             else {
186 0 0         Object obj = other;
187 0 0         if (obj && obj.stash().isa("URI::XS")) RETVAL = THIS->equals(*xs::in(obj));
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
    0          
188 0           else RETVAL = false;
189             }
190             }
191              
192             URI* URI::clone () {
193 4           PROTO = Object(ST(0)).stash();
194 2 50         if (dynamic_cast(THIS)) RETVAL = URI::create(*THIS);
    50          
195 2 50         else RETVAL = new URI(*THIS);
    100          
    100          
    50          
196 1 50         }
    50          
197            
198             void URI::path_segments (...) {
199 8 100         if (items > 1) {
200 6           std::vector list;
201 3 50         list.reserve(items-1);
202 10 100         for (I32 i = 1; i < items; ++i) list.push_back(xs::in(ST(i)));
    50          
    50          
203 3 50         THIS->path_segments(list.cbegin(), list.cend());
204 3           XSRETURN_EMPTY;
205             }
206 13 50         const std::vector list = THIS->path_segments();
207 5 50         EXTEND(SP, (int)list.size());
    50          
    50          
    0          
208 11 100         for (auto it = list.begin(); it != list.end(); ++it) mPUSHp(it->data(), it->length());
    50          
209             }
210              
211             bool URI::to_bool (...) {
212 14 50         RETVAL = THIS->scheme().length() || THIS->host().length() || THIS->path().length() || THIS->query_string().length() ||
    50          
    50          
    50          
213 7           THIS->fragment().length();
214             }
215              
216             string URI::user (SV* newval = NULL) {
217 0 0         if (newval) {
218 0 0         THIS->user(xs::in(newval));
    0          
219 0           XSRETURN_UNDEF;
220             }
221 0 0         RETVAL = THIS->user();
    0          
222             }
223              
224             string URI::password (SV* newval = NULL) {
225 0 0         if (newval) {
226 0 0         THIS->password(xs::in(newval));
    0          
227 0           XSRETURN_UNDEF;
228             }
229 0 0         RETVAL = THIS->password();
    0          
230             }