blib/lib/Apache/TestReport.pm untested

filter: Statementstmt 0.0% 0 / 56 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 5 MC/DCmcdc 0.0% 0 / 3 Subroutinesub 0.0% 0 / 19 Podpod 0.0% 0 / 12 totaltotal 0.0% 0 / 101 CC 4 SCAR 13.2
CC
4
Cov
0%
dump_core_file
12.0
core_dump
6.0
new
2.0
CRAP 3.7
1 # Licensed to the Apache Software Foundation (ASF) under one or more
2 # contributor license agreements. See the NOTICE file distributed with
3 # this work for additional information regarding copyright ownership.
4 # The ASF licenses this file to You under the Apache License, Version 2.0
5 # (the "License"); you may not use this file except in compliance with
6 # the License. You may obtain a copy of the License at
7 #
8 # http://www.apache.org/licenses/LICENSE-2.0
9 #
10 # Unless required by applicable law or agreed to in writing, software
11 # distributed under the License is distributed on an "AS IS" BASIS,
12 # WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13 # See the License for the specific language governing permissions and
14 # limitations under the License.
15 #
16 package Apache::TestReport;
17  
18 use strict;
19 use warnings FATAL => 'all';
20  
21 use Apache::Test ();
22 use Apache::TestConfig ();
23  
24 use File::Spec::Functions qw(catfile);
25 use File::Find;
26  
27 sub new {
28 my $class = shift;
29 bless { @_ }, $class;
30 }
31  
32 # generate t/REPORT script (or a different filename) which will drive
33 # Apache::TestReport
34 sub generate_script {
35 my ($class, $file) = @_;
36  
37 $file ||= catfile 't', 'REPORT';
38  
39 my $content = join "\n",
40 "BEGIN { eval { require blib && blib->import; } }",
41 Apache::TestConfig->perlscript_header,
42 "use $class;",
43 "$class->new(\@ARGV)->run;";
44  
45 Apache::Test::basic_config()->write_perlscript($file, $content);
46 }
47  
48 sub replace {
49 my($self, $template) = @_;
50  
51 $template =~ s{\@(\w+)\@} {
52 my $method = lc $1;
53 eval { $self->$method() } || $self->{$1} || '';
54 }eg;
55  
56 $template;
57 }
58  
59 sub run {
60 my $self = shift;
61  
62 print $self->replace($self->template);
63 }
64  
65 sub config { Apache::TestConfig::as_string() }
66  
67 sub report_to { 'test-dev@httpd.apache.org' }
68  
69 sub postit_note {
70 my $self = shift;
71  
72 my($to, $where) = split '@', $self->report_to;
73  
74 return <<EOF;
75 Note: Complete the rest of the details and post this bug report to
76 $to <at> $where. To subscribe to the list send an empty
77 email to $to-subscribe\@$where.
78 EOF
79 }
80  
81 sub executable { $0 }
82  
83 my $core_dump;
84 sub core_dump {
85 my $self = shift;
86  
87 $core_dump = "";
88  
89 if (eval { require Devel::GDB }) {
90 find(\&dump_core_file, 't')
91 }
92  
93 $core_dump || ' [CORE TRACE COMES HERE]';
94 }
95  
96 sub dump_core_file {
97 return unless /^core(\.\d+)?$/;
98  
99 my $core = $_;
100 my $gdb = new Devel::GDB ();
101 my $test_config = Apache::TestConfig->new({thaw=>1});
102 my $httpd = $test_config->{vars}->{httpd};
103  
104 return unless defined $httpd;
105  
106 $core_dump .= join '',
107 $gdb->get("file $httpd"),
108 $gdb->get('sharedlibrary'),
109 $gdb->get("core $core"),
110 $gdb->get('info threads'),
111 $gdb->get('thread apply all bt');
112 }
113  
114 sub date { scalar gmtime() . " GMT" }
115  
116 sub template {
117 <<'EOI'
118 -------------8<---------- Start Bug Report ------------8<----------
119 1. Problem Description:
120  
121 [DESCRIBE THE PROBLEM HERE]
122  
123 2. Used Components and their Configuration:
124  
125 @CONFIG@
126  
127 3. This is the core dump trace: (if you get a core dump):
128  
129 @CORE_DUMP@
130  
131 This report was generated by @EXECUTABLE@ on @DATE@.
132  
133 -------------8<---------- End Bug Report --------------8<----------
134  
135 @POSTIT_NOTE@
136  
137 EOI
138  
139 }
140  
141 1;
142 __END__