File Coverage

blib/lib/Apache/TaintRequest.pm
Criterion Covered Total %
statement 7 9 77.7
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 12 83.3


line stmt bran cond sub pod time code
1             package Apache::TaintRequest;
2              
3 1     1   501 use strict;
  1         2  
  1         32  
4 1     1   4 use warnings;
  1         1  
  1         24  
5              
6 1     1   1229 use Apache;
  0            
  0            
7             use Apache::Util qw(escape_html);
8             use Taint qw(tainted);
9              
10             $Apache::TaintRequest::VERSION = '0.10';
11             @Apache::TaintRequest::ISA = qw(Apache);
12              
13             sub new {
14             my ($class, $r) = @_;
15              
16             $r ||= Apache->request;
17              
18             tie *STDOUT, $class, $r;
19              
20             return tied *STDOUT;
21             }
22              
23              
24             sub print {
25             my ($self, @data) = @_;
26              
27             foreach my $value (@data) {
28             # Dereference scalar references.
29             $value = $$value if ref $value eq 'SCALAR';
30              
31             # Escape any HTML content if the data is tainted.
32             $value = escape_html($value) if tainted($value);
33             }
34              
35             $self->SUPER::print(@data);
36             }
37              
38             sub TIEHANDLE {
39             my ($class, $r) = @_;
40              
41             return bless { r => $r }, $class;
42             }
43              
44             sub PRINT {
45             shift->print(@_);
46             }
47              
48             1;
49              
50             __END__