Jifty/Plugin/RequestInspector/View.pm untested

filter: Statementstmt 0.0% 0 / 94 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 121 CC 2 SCAR 12.8
CC
2
Cov
0%
_render_request
6.0
BEGIN
2.0
BEGIN
2.0
CRAP 3.6
1 package Jifty::Plugin::RequestInspector::View;
2 use strict;
3 use warnings;
4 use Jifty::View::Declare -base;
5  
6 template '/__jifty/admin/requests' => page {
7 title => "Request Inspector"
8 }
9 content {
10 render_region(
11 name => 'aggregate',
12 path => '/__jifty/admin/requests/aggregate',
13 );
14  
15 h2 { "Request Inspector" };
16  
17 render_region(
18 name => 'request_inspector',
19 path => '/__jifty/admin/requests/requests',
20 );
21  
22 div {
23 hyperlink(
24 label => "Clear requests",
25 onclick => [
26 {
27 refresh => 'request_inspector',
28 args => {
29 clear_requests => 1,
30 },
31 },
32 {
33 refresh => "aggregate",
34 }
35 ],
36 ),
37 };
38 };
39  
40 template '/__jifty/admin/requests/requests' => sub {
41 my $request_inspector = Jifty->find_plugin('Jifty::Plugin::RequestInspector');
42 $request_inspector->clear_requests if get('clear_requests');
43  
44 ol {
45 attr { id is 'request_inspector' };
46  
47 for my $request ($request_inspector->requests) {
48 _render_request($request);
49 }
50 };
51  
52 render_region(
53 name => 'more_button',
54 path => '/__jifty/admin/requests/more_button',
55 );
56 };
57  
58 template '/__jifty/admin/requests/more_button' => sub {
59 my $request_inspector = Jifty->find_plugin('Jifty::Plugin::RequestInspector');
60 my $last_id = $request_inspector->last_id;
61  
62 hyperlink(
63 label => "Load subsequent requests",
64 onclick => [{
65 element => '#request_inspector',
66 append => '/__jifty/admin/requests/more_requests',
67 effect => 'slideDown',
68 arguments => {
69 last_id => $last_id,
70 },
71 },
72 {
73 refresh_self => 1,
74 },
75 {
76 refresh => "aggregate",
77 }],
78 );
79 };
80  
81 template '/__jifty/admin/requests/more_requests' => sub {
82 my $request_inspector = Jifty->find_plugin('Jifty::Plugin::RequestInspector');
83 my $last_id = get('last_id');
84  
85 my @requests = $request_inspector->requests( after => $last_id );
86  
87 for my $request (@requests) {
88 _render_request($request);
89 }
90 };
91  
92 template '/__jifty/admin/requests/aggregate' => sub {
93 my $request_inspector = Jifty->find_plugin('Jifty::Plugin::RequestInspector');
94 my @aggregates = grep {$_->can('inspect_render_aggregate')} $request_inspector->inspector_plugins;
95 return unless @aggregates;
96  
97 h2 { "Aggregate information" };
98 dl {
99 for my $plugin (@aggregates) {
100 my $plugin_name = ref $plugin;
101 (my $short_name = $plugin_name) =~ s/^Jifty::Plugin:://;
102 dt {
103 hyperlink(
104 label => $short_name,
105 onclick => {
106 region => Jifty->web->qualified_region($plugin_name),
107 replace_with => '/__jifty/admin/requests/aggregate_plugin',
108 toggle => 1,
109 effect => 'slideDown',
110 arguments => {
111 plugin_name => $plugin_name,
112 },
113 },
114 );
115 };
116 dd {
117 render_region($plugin_name);
118 };
119 }
120 }
121 };
122  
123 template '/__jifty/admin/requests/aggregate_plugin' => sub {
124 my $plugin_name = get('plugin_name');
125  
126 my $request_inspector = Jifty->find_plugin('Jifty::Plugin::RequestInspector');
127 my @plugin_data = $request_inspector->get_all_plugin_data($plugin_name);
128  
129 my $plugin = Jifty->find_plugin($plugin_name)
130 or abort(404);
131  
132 $plugin->inspect_render_aggregate(@plugin_data);
133 };
134  
135 template '/__jifty/admin/requests/plugins' => sub {
136 my $id = get('id');
137 my $request_inspector = Jifty->find_plugin('Jifty::Plugin::RequestInspector');
138  
139 dl {
140 for my $plugin ($request_inspector->inspector_plugins) {
141 my $plugin_name = ref $plugin;
142 my $plugin_data = $request_inspector->get_plugin_data($id, $plugin_name);
143 next if !defined($plugin_data);
144  
145 dt {
146 (my $short_name = $plugin_name) =~ s/^Jifty::Plugin:://;
147 if ($plugin->can('inspect_render_analysis')) {
148 hyperlink(
149 label => $short_name,
150 onclick => {
151 region => Jifty->web->qualified_region($plugin_name),
152 replace_with => '/__jifty/admin/requests/plugin',
153 toggle => 1,
154 effect => 'slideDown',
155 arguments => {
156 id => $id,
157 plugin_name => $plugin_name,
158 },
159 },
160 );
161 }
162 else {
163 outs $short_name;
164 }
165 };
166 dd {
167 if ($plugin->can('inspect_render_summary')) {
168 outs $plugin->inspect_render_summary($plugin_data, $id);
169 }
170 render_region($plugin_name);
171 };
172 }
173 };
174 };
175  
176 template '/__jifty/admin/requests/plugin' => sub {
177 my $id = get('id');
178 my $plugin_name = get('plugin_name');
179  
180 my $request_inspector = Jifty->find_plugin('Jifty::Plugin::RequestInspector');
181 my $plugin_data = $request_inspector->get_plugin_data($id, $plugin_name);
182  
183 my $plugin = Jifty->find_plugin($plugin_name)
184 or abort(404);
185  
186 $plugin->inspect_render_analysis($plugin_data, $id);
187 };
188  
189 sub _render_request {
190 my $request = shift;
191  
192 li {
193 my $id = $request->{id};
194  
195 hyperlink(
196 label => $request->{url},
197 onclick => {
198 region => Jifty->web->qualified_region("request_$id"),
199 replace_with => '/__jifty/admin/requests/plugins',
200 toggle => 1,
201 effect => 'slideDown',
202 arguments => {
203 id => $id,
204 },
205 },
206 );
207  
208 outs sprintf ' (%.2gs)', $request->{end} - $request->{start};
209 if ($request->{cookie}) {
210 outs " [" . $request->{cookie} . "]";
211 }
212  
213 render_region("request_$id");
214 };
215 }
216  
217 1;
218  
219 __END__