lib/Amon2/Setup/Asset/XSRFTokenJS.pm

filter: Statementstmt 100% 9 / 9 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod 0.0% 0 / 2 totaltotal 86.6% 13 / 15 CC 1 SCAR 0.0
CC
1
Cov
100%
BEGIN
1.0
BEGIN
1.0
tags
1.0
CRAP 1.0
« blib/lib/auto/share/dist/Amon2/flavor/Large/script/web.pl ↑ Summary blib/lib/Amon2/Web/Response.pm »
1 package Amon2::Setup::Asset::XSRFTokenJS;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4  
5 2 ▶sub tags {
Subroutine tags: called CC=1 SCAR=0.0
Pod undocumented
6 2 <<',,,';
7 <script src="<: uri_for('/static/js/xsrf-token.js') :>"></script>
8 ,,,
9 }
10  
11 1 ▶sub files {
Subroutine files: called CC=1 SCAR=0.0
Pod undocumented
12 return {
13 1 'js/xsrf-token.js' => '(function (document) {
14 "use strict";
15  
16 document.addEventListener("DOMContentLoaded", function () {
17 var xsrf_token = getXSRFToken();
18 var forms = document.querySelectorAll("form");
19 for (var i = 0; i < forms.length; i++) {
20 var form = forms[i];
21 var method = form.getAttribute("method");
22 if (method === "get" || method === "GET") {
23 continue;
24 }
25  
26 var input = document.createElement("input");
27 input.setAttribute("type", "hidden");
28 input.setAttribute("name", "XSRF-TOKEN");
29 input.setAttribute("value", xsrf_token);
30 form.insertBefore(input, form.firstChild);
31 }
32  
33 function getXSRFToken() {
34 var cookies = document.cookie.split(/\\s*;\\s*/);
35 for (var i=0,l=cookies.length; i<l; i++) {
36 var matched = cookies[i].match(/^XSRF-TOKEN=(.*)$/);
37 if (matched) {
38 return matched[1];
39 }
40 }
41 return undefined;
42 }
43 });
44 })(document);
45 '
46 }
47 ;
48 }
49  
50 1 1;
« blib/lib/auto/share/dist/Amon2/flavor/Large/script/web.pl ↑ Summary blib/lib/Amon2/Web/Response.pm »