File Coverage

lib/Amon2/Setup/Asset/XSRFTokenJS.pm
Criterion Covered Total %
statement 7 8 87.5
branch n/a
condition n/a
subroutine 3 4 75.0
pod 0 2 0.0
total 10 14 71.4


line stmt bran cond sub pod time code
1             # This file is generated by author/assets.pl. Do not edit manually.
2             package Amon2::Setup::Asset::XSRFTokenJS;
3 1     1   385 use strict;
  1         2  
  1         37  
4 1     1   6 use warnings;
  1         3  
  1         91  
5              
6             sub tags {
7 1     1 0 5 <<',,,';
8             <script src="<: uri_for('/static/js/xsrf-token.js') :>"></script>
9             ,,,
10             }
11              
12             sub files {
13             return {
14 0     0 0   'js/xsrf-token.js' => '(function (document, $) {
15             $(function () {
16             "use strict";
17              
18             var xsrf_token = getXSRFToken();
19             $("form").each(function () {
20             var form = $(this);
21             var method = form.attr(\'method\');
22             if (method === \'get\' || method === \'GET\') {
23             return;
24             }
25              
26             var input = $(document.createElement(\'input\'));
27             input.attr(\'type\', \'hidden\');
28             input.attr(\'name\', \'XSRF-TOKEN\');
29             input.attr(\'value\', xsrf_token);
30             form.prepend(input);
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, jQuery);
45             '
46             }
47             ;
48             }
49              
50             1;