blib/lib/CGI/PrintWrapper.pm

filter: Statementstmt 95.4% 42 / 44 Branchbran 64.2% 9 / 14 Conditioncond 33.3% 1 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 100% 10 / 10 Podpod 100% 3 / 3 totaltotal 85.5% 65 / 76 CC 9 SCAR 11.7
CC
9
Cov
85%
new
6.5
io
2.3
cgi
2.3
CRAP 3.2
↑ Summary
1 package CGI::PrintWrapper;
2  
3 # This is a lightweight wrapper for CGI so that you can call its
4 # methods, but have the results printed to the request object (passing
5 # through the Template object, of course).
6  
7 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 ▶use Carp ( );
Subroutine BEGIN: called CC=1 SCAR=0.0
10 3 ▶use CGI ( );
Subroutine BEGIN: called CC=1 SCAR=0.0
11 3 ▶use CGI::Pretty;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13  
14 3 $CGI::PrintWrapper::VERSION = (substr q$Revision: 1.8 $, 10) - 1;
15 3 my $rcs = '$Id: PrintWrapper.pm,v 1.8 1999/12/30 13:38:06 binkley Exp $';
16  
17  
18 4 ▶sub new ($$;@) {
Subroutine new: called CC=6 SCAR=18.7
Pod documented
19 4 my ($this, $h, @cgi_args) = @_;
20 4 ▶ @cgi_args = ('') unless @cgi_args;
Branch: 1 branch
BranchTrueFalseTotal
unless @cgi_args 3 1 4
21  
22 4 ▶ $h or Carp::croak ('No print handle');
Branch: 1 branch
BranchTrueFalseTotal
$h or Carp::croak("No print handle") 4 0 4
23 4 ▶ $h->can ('print') or Carp::croak ("'$h' is not a print handle");
Branch: 1 branch
BranchTrueFalseTotal
$h->can("print") or Carp::croak("'${h}' is not a print handle") 4 0 4
24  
25 4 ▶ my $class = ref ($this) || $this;
Condition33%1/3
ref $this || $this
l!l&&r!l&&!r
040
MC/DC0%0/2
ref $this || $this
ref $this $this
Truth table33%1/3
A || B
A= ref $thisB= $this
ABresult
1X1
011
000
26 # Need to create an empty CGI object to avoid CGI trying to read in
27 # the parameters -- we are using CGI for printing forms, not for
28 # processing scripts:
29 4 my $cgi;
30 4 eval { $cgi = CGI->new (@cgi_args); };
31 4 ▶ $@ and Carp::croak ("Couldn't create CGI object because $@");
Branch: 1 branch
BranchTrueFalseTotal
$@ and Carp::croak("Couldn't create CGI object because $@") 0 4 4
32  
33 4 bless [$h, $cgi], $class;
34 }
35  
36 3 ▶sub io ($;$) {
Subroutine io: called CC=2 SCAR=8.1
Pod documented
37 3 ▶ if (scalar @_ == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 1) { } 3 0 3
38 3 $_[0]->[0];
39 } else {
40 0 $_[0]->[0] = $_[1];
41 }
42 }
43  
44 # Modify CGI without printing:
45 2 ▶sub cgi ($;$) {
Subroutine cgi: called CC=2 SCAR=8.1
Pod documented
46 2 ▶ if (scalar @_ == 1) {
Branch: 1 branch
BranchTrueFalseTotal
if (scalar @_ == 1) { } 2 0 2
47 2 $_[0]->[1];
48 } else {
49 0 $_[0]->[1] = $_[1];
50 }
51 }
52  
53 7 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=2 SCAR=6.9
54 3 ▶ no strict qw(refs);
Subroutine BEGIN: called CC=1 SCAR=0.0
55  
56 7 my $sub = $CGI::PrintWrapper::AUTOLOAD;
57 7 $sub =~ s/.*:://; # strip package
58 # We don't particularly want to print this: :-)
59 7 ▶ return if $sub eq 'DESTROY';
Branch: 1 branch
BranchTrueFalseTotal
if $sub eq "DESTROY" 4 3 7
60  
61 # Fixup our call to invoke the same-named CGI function, but to print
62 # the resulting string to our handle. Update our symbol table so
63 # that future calls can bypass AUTOLOAD entirely. Be careful to
64 # capture the handle ($$self) inside the sub--not outside--so that
65 # calls from other instances don't reuse a previous handle (correct
66 # scoping):
67 3 ▶ *{$CGI::PrintWrapper::AUTOLOAD} = sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
68 5 my $self = shift;
69 5 my $cgi_sub = "CGI::$sub";
70  
71 5 $self->[0]->print ($self->[1]->$cgi_sub (@_));
72  
73 5 return $self;
74 3 };
75  
76 3 goto &$CGI::PrintWrapper::AUTOLOAD;
77 }
78  
79 3 1;
80  
81  
82 __END__
↑ Summary