File Coverage

blib/lib/Apache/Voodoo/Debug/Native/common.pm
Criterion Covered Total %
statement 12 122 9.8
branch 0 84 0.0
condition 0 9 0.0
subroutine 4 27 14.8
pod 0 14 0.0
total 16 256 6.2


line stmt bran cond sub pod time code
1             package Apache::Voodoo::Debug::Native::common;
2              
3             $VERSION = "3.0200";
4              
5 1     1   6 use strict;
  1         3  
  1         31  
6 1     1   5 use warnings;
  1         1  
  1         26  
7              
8 1     1   5 use base("Apache::Voodoo");
  1         1  
  1         85  
9              
10 1     1   5 use DBI;
  1         2  
  1         2042  
11              
12             sub set_dbh {
13 0     0 0   my $self = shift;
14 0           $self->{dbh} = shift;
15             }
16              
17             sub get_dbh {
18 0     0 0   return $_[0]->{dbh};
19             }
20              
21             sub db_disconnect {
22 0     0 0   my $self = shift;
23 0 0         if ($self->{dbh}) {
24 0           $self->{dbh}->disconnect;
25             }
26             }
27              
28             sub create_schema {
29 0     0 0   my $self = shift;
30              
31 0           $self->_create_request();
32 0           $self->_create_profile();
33 0           $self->_create_debug();
34 0           $self->_create_params();
35 0           $self->_create_session();
36 0           $self->_create_template_conf();
37 0           $self->_create_return_data();
38              
39 0           $self->_create_version();
40             }
41              
42             sub _create_version {
43 0     0     my $self = shift;
44 0 0         $self->{dbh}->do("CREATE TABLE version (version varchar(64) not null)") || $self->db_error();
45 0 0         $self->{dbh}->do("INSERT INTO version (version) VALUES(?)",undef,$self->{version}) || $self->db_error();
46             }
47              
48             sub _create_request {
49 0     0     my $self = shift;
50              
51 0 0         $self->{dbh}->do("CREATE TABLE request (
52             id ".$self->_pkey_syntax.",
53             request_timestamp varchar(64) not null,
54             application varchar(64) not null,
55             session_id varchar(64),
56             url varchar(255),
57             status varchar(128)
58             )") || $self->db_error();
59              
60 0 0         $self->{dbh}->do("CREATE INDEX request_request_timestamp ON request(request_timestamp)") || $self->db_error();
61 0 0         $self->{dbh}->do("CREATE INDEX request_session_id ON request(session_id)") || $self->db_error();
62 0 0         $self->{dbh}->do("CREATE INDEX request_application ON request(application)") || $self->db_error();
63 0 0         $self->{dbh}->do("CREATE INDEX request_url ON request(url)") || $self->db_error();
64             }
65              
66             sub _get_request_id {
67 0     0     my $self = shift;
68 0           my $id = shift;
69              
70 0   0       my $res = $self->{dbh}->selectcol_arrayref("
71             SELECT
72             id
73             FROM
74             request
75             WHERE
76             request_timestamp = ? AND
77             application = ?",undef,
78             $id->{request_id},
79             $id->{app_id}) || $self->db_error();
80              
81 0           return $res->[0];
82             }
83              
84             sub handle_request {
85 0     0 0   my $self = shift;
86 0           my $data = shift;
87              
88 0 0         $self->{dbh}->do("
89             INSERT INTO request (
90             request_timestamp,
91             application
92             )
93             VALUES (
94             ?,
95             ?
96             )",undef,
97             $data->{id}->{request_id},
98             $data->{id}->{app_id}) || $self->db_error();
99             }
100              
101             sub handle_url {
102 0     0 0   my $self = shift;
103 0           my $data = shift;
104              
105 0 0         $self->{dbh}->do("
106             UPDATE request
107             SET
108             url = ?
109             WHERE
110             request_timestamp = ? AND
111             application = ?
112             ",undef,
113             $data->{data},
114             $data->{id}->{request_id},
115             $data->{id}->{app_id}) || $self->db_error();
116             }
117              
118             sub handle_session_id {
119 0     0 0   my $self = shift;
120 0           my $data = shift;
121              
122 0 0         $self->{dbh}->do("
123             UPDATE request
124             SET
125             session_id = ?
126             WHERE
127             request_timestamp = ? AND
128             application = ?
129             ",undef,
130             $data->{data},
131             $data->{id}->{request_id},
132             $data->{id}->{app_id}) || $self->db_error();
133             }
134              
135             sub handle_status {
136 0     0 0   my $self = shift;
137 0           my $data = shift;
138              
139 0 0         $self->{dbh}->do("
140             UPDATE request
141             SET
142             status = ?
143             WHERE
144             request_timestamp = ? AND
145             application = ?
146             ",undef,
147             $data->{data},
148             $data->{id}->{request_id},
149             $data->{id}->{app_id}) || $self->db_error();
150             }
151              
152             sub _create_profile {
153 0     0     my $self = shift;
154              
155 0 0         $self->{dbh}->do("CREATE TABLE profile (
156             request_id integer not null,
157             timestamp varchar(64) not null,
158             data varchar(255)
159             )") || $self->db_error();
160              
161 0 0         $self->{dbh}->do("CREATE INDEX profile_request_id ON profile(request_id)") || $self->db_error();
162 0 0         $self->{dbh}->do("CREATE INDEX profile_timestamp ON profile(timestamp)") || $self->db_error();
163             }
164              
165             sub handle_profile {
166 0     0 0   my $self = shift;
167 0           my $data = shift;
168              
169 0           my $request_id = $self->_get_request_id($data->{id});
170 0 0         unless ($request_id) {
171 0           warn "no such request\n";
172 0           return;
173             }
174              
175 0 0         $self->{dbh}->do("
176             INSERT INTO profile (
177             request_id,
178             timestamp,
179             data
180             )
181             VALUES (
182             ?,
183             ?,
184             ?
185             )",undef,
186             $request_id,
187             $data->{timestamp},
188             $data->{data}) || $self->db_error();
189             }
190              
191             sub _create_debug {
192 0     0     my $self = shift;
193              
194 0 0         $self->{dbh}->do("CREATE TABLE debug (
195             request_id integer not null,
196             seq integer unsigned not null,
197             level varchar(64) not null,
198             stack text not null,
199             data text
200             )") || $self->db_error();
201              
202 0 0         $self->{dbh}->do("CREATE INDEX debug_request_id ON debug(request_id)") || $self->db_error();
203 0 0         $self->{dbh}->do("CREATE INDEX debug_seq ON debug(seq)" ) || $self->db_error();
204 0 0         $self->{dbh}->do("CREATE INDEX debug_level ON debug(level)" ) || $self->db_error();
205             }
206              
207             sub handle_debug {
208 0     0 0   my $self = shift;
209 0           my $data = shift;
210              
211 0           my $request_id = $self->_get_request_id($data->{id});
212 0 0         unless ($request_id) {
213 0           warn "no such request\n";
214 0           return;
215             }
216              
217 0   0       my $res = $self->{dbh}->selectcol_arrayref("
218             SELECT
219             MAX(seq)
220             FROM
221             debug
222             WHERE request_id = ?",undef,$request_id) || $self->db_error();
223              
224 0 0         my $seq = (($res->[0])?$res->[0]:0) + 1;
225              
226 0           $data->{data} =~ s/^\s+//;
227 0           $data->{data} =~ s/\s+$//;
228              
229 0 0         $self->{dbh}->do("
230             INSERT INTO debug(
231             request_id,
232             seq,
233             level,
234             stack,
235             data
236             )
237             VALUES (
238             ?,
239             ?,
240             ?,
241             ?,
242             ?
243             )",undef,
244             $request_id,
245             $seq,
246             $data->{level},
247             $data->{stack},
248             $data->{data}) || $self->db_error();
249             }
250              
251             sub _create_params {
252 0     0     my $self = shift;
253              
254 0 0         $self->{dbh}->do("CREATE TABLE params (
255             request_id integer not null,
256             data text
257             )") || $self->db_error();
258              
259 0 0         $self->{dbh}->do("CREATE INDEX params_request_id ON params(request_id)") || $self->db_error();
260             }
261              
262             sub handle_params {
263 0     0 0   my $self = shift;
264 0           my $data = shift;
265              
266 0           my $request_id = $self->_get_request_id($data->{id});
267 0 0         unless ($request_id) {
268 0           warn "no such request\n";
269 0           return;
270             }
271              
272 0 0         $self->{dbh}->do("
273             INSERT INTO params (
274             request_id,
275             data
276             )
277             VALUES (
278             ?,
279             ?
280             )",undef,
281             $request_id,
282             $data->{data}) || $self->db_error();
283             }
284              
285             sub _create_session {
286 0     0     my $self = shift;
287              
288 0 0         $self->{dbh}->do("CREATE TABLE session (
289             request_id integer not null,
290             data text
291             )") || $self->db_error();
292              
293 0 0         $self->{dbh}->do("CREATE INDEX session_request_id ON session(request_id)") || $self->db_error();
294             }
295              
296             sub handle_session {
297 0     0 0   my $self = shift;
298 0           my $data = shift;
299              
300 0           my $request_id = $self->_get_request_id($data->{id});
301 0 0         unless ($request_id) {
302 0           warn "no such request\n";
303 0           return;
304             }
305              
306 0 0         $self->{dbh}->do("
307             INSERT INTO session (
308             request_id,
309             data
310             )
311             VALUES (
312             ?,
313             ?
314             )",undef,
315             $request_id,
316             $data->{data}) || $self->db_error();
317             }
318              
319             sub _create_template_conf {
320 0     0     my $self = shift;
321              
322 0 0         $self->{dbh}->do("CREATE TABLE template_conf (
323             request_id integer not null,
324             data text
325             )") || $self->db_error();
326              
327 0 0         $self->{dbh}->do("CREATE INDEX tc_request_id ON template_conf(request_id)") || $self->db_error();
328             }
329              
330             sub handle_template_conf {
331 0     0 0   my $self = shift;
332 0           my $data = shift;
333              
334 0           my $request_id = $self->_get_request_id($data->{id});
335 0 0         unless ($request_id) {
336 0           warn "no such request\n";
337 0           return;
338             }
339              
340 0 0         $self->{dbh}->do("
341             INSERT INTO template_conf (
342             request_id,
343             data
344             )
345             VALUES (
346             ?,
347             ?
348             )",undef,
349             $request_id,
350             $data->{data}) || $self->db_error();
351             }
352              
353             sub _create_return_data {
354 0     0     my $self = shift;
355              
356 0 0         $self->{dbh}->do("CREATE TABLE return_data (
357             request_id integer not null,
358             seq integer not null,
359             handler varchar(128) not null,
360             method varchar(64) not null,
361             data text
362             )") || $self->db_error();
363              
364 0 0         $self->{dbh}->do("CREATE INDEX return_request_id ON return_data(request_id)") || $self->db_error();
365 0 0         $self->{dbh}->do("CREATE INDEX return_seq ON return_data(seq)") || $self->db_error();
366             }
367              
368             sub handle_return_data {
369 0     0 0   my $self = shift;
370 0           my $data = shift;
371              
372 0           my $request_id = $self->_get_request_id($data->{id});
373 0 0         unless ($request_id) {
374 0           warn "no such request\n";
375 0           return;
376             }
377              
378 0   0       my $res = $self->{dbh}->selectcol_arrayref("
379             SELECT
380             MAX(seq)
381             FROM
382             return_data
383             WHERE request_id = ?",undef,$request_id) || $self->db_error();
384              
385 0 0         my $seq = (($res->[0])?$res->[0]:0) + 1;
386              
387 0 0         $self->{dbh}->do("
388             INSERT INTO return_data (
389             request_id,
390             seq,
391             handler,
392             method,
393             data
394             )
395             VALUES (
396             ?,
397             ?,
398             ?,
399             ?,
400             ?
401             )",undef,
402             $request_id,
403             $seq,
404             $data->{handler},
405             $data->{method},
406             $data->{data}) || $self->db_error();
407             }
408              
409             1;
410              
411             ################################################################################
412             # Copyright (c) 2005-2010 Steven Edwards (maverick@smurfbane.org).
413             # All rights reserved.
414             #
415             # You may use and distribute Apache::Voodoo under the terms described in the
416             # LICENSE file include in this package. The summary is it's a legalese version
417             # of the Artistic License :)
418             #
419             ################################################################################