Bus/psp.pm untested

filter: Statementstmt 0.0% 0 / 92 Branchbran 0.0% 0 / 42 Conditioncond 0.0% 0 / 54 MC/DCmcdc 0.0% 0 / 31 Subroutinesub 0.0% 0 / 10 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 234 CC 22 SCAR 46.1
CC
22
Cov
0%
parse
210.0
eval
20.0
_furl
12.0
CRAP 100.5
1 #!perl -w
2 #
3 # CGI::Bus::psp - Perl Script Processor
4 #
5 # admiral
6 #
7 #
8
9 package CGI::Bus::psp;
10 require 5.000;
11 use strict;
12 use CGI::Carp qw(fatalsToBrowser warningsToBrowser);
13 use CGI::Bus::Base;
14 use vars qw(@ISA);
15 @ISA =qw(CGI::Bus::Base);
16
17
18 1;
19
20
21 #######################
22
23
24 sub _fdir { # File Dir
25 ($_[1] ||'') =~/^(.+?)[\\\/][^\\\/]+$/ ? $1 : ($_[0]->ppath ||$_[1] ||'')
26 }
27
28
29 sub _furl { # File URL
30 my $s =shift;
31 my $f =$_[0] ||$s->qpath;
32 foreach my $b ('p','b') {
33 my $m =$b .'path';
34 my $p =$s->$m();
35 next if lc(substr($f,0,length($p))) ne lc($p);
36 my $u =length($f) >length($p)+1 ? substr($f,length($p)+1) : '';
37 $m =$b .'url';
38 return $s->$m($u)
39 }
40 $s->purl
41 }
42
43
44 sub evalf { # PerlScript Eval File
45 local @_ =@_;
46 my $s =shift;
47 my $o =substr($_[0],0,1) eq '-' ? shift : '-';
48 my $u =shift;
49 my $f =ref($u) ? $u->[0] : $u;
50 my $t;
51 my $h =CORE::eval('use IO::File; IO::File->new()');
52 $h->open($f,'r') ||$s->parent->die("Cannot open file '" .($f||'') ."': $!");
53 read($h, $t, -s $f) && close($h) || $s->parent->die("Cannot load '$f'");
54 $s->eval($o,$s->parse($o, $t, $u), $f, @_);
55 }
56
57
58 sub eval { # PerlScript Eval Source
59 my $s =shift;
60 my $p =$s->parent;
61 my $o =substr($_[0],0,1) eq '-' ? shift : '-';
62 my $t =shift;
63 $p->print->httpheader() if $o !~/e/; # -e to embed html
64 $p->evalsub($t, $p, $o, @_);
65 $p->die($@) if $@
66 }
67
68
69 sub parse { # PerlScript Parse Source
70 my $s =shift;
71 my $opt =substr($_[0],0,1) eq '-' ? shift : '-';
72 my $i =$_[0];
73 my $o ='';
74 my ($ol,$or) =('','');
75 my ($ts,$tl,$ta,$tc) =('','','','');
76 if ($i =~/<(!DOCTYPE|html|head)/i && $`) {
77 $i ='<' .$1 .$'
78 }
79 if ($_[1] && $i =~m{(<body[^>]*>)}i) {
80 my ($i0,$i1) =($` .$1 ,$');
81 $i =$i0
82 .('<base href="'. $s->htmlescape(ref($_[1]) ? $_[1]->[1] : $s->_furl($s->_fdir($_[1]))).'/" />')
83 .$i1
84 }
85 if ($opt =~/e/i && $i =~m{<body[^>]*>}i) {
86 $i =$';
87 $i =$` if $i =~m{</body>}i
88 }
89 while ($i) {
90 if (not $i =~m{<(\%@|\%|SCRIPT) *(Language *= *|)* *(PerlScript|Perl|)* *(RUNAT *= *Server|)*[ >]*}i) {
91 $ol =$i; $i ='';
92 $ts ='';
93 }
94 elsif (($2 && !$3) || (!$3 && $tl eq '1')) {
95 $ol =$` .$&;
96 $i =$';
97 $tl =1;
98 $tc =$ts ='';
99 }
100 elsif ($1) {
101 $ol =$`; $i =$';
102 $ts =uc($1||''); $tl =($2 && $3)||''; $ta=$4||'';
103 if ($i =~m{ *(\%>|</SCRIPT>)}i) {$tc =$`; $i =$'}
104 else {$tc =''}
105 }
106 else {
107 $ol =$i; $i ='';
108 }
109 $ol =~s/(["\$\@%\\])/\\$1/g;
110 $ol =~s/[\n]/\\n");\n\$_[0]->print("/g;
111 $o .= "\$_[0]->print(\"$ol\\n\");\n";
112 next if !$ts || !$tc || $ts eq '%@';
113 $tc =~s/\&lt;?/</g;
114 $tc =~s/\&gt;?/>/g;
115 $tc =~s/\&amp;?/\&/g;
116 $tc =~s/\&quot;?/"/g;
117 if ($ts eq '%') { $o .= "\$_[0]->print($tc);\n" }
118 elsif ($ts eq 'SCRIPT') { $o .= $tc .";\n"}
119 }
120 $o;
121 }
122
123