line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#the dumb terminal webmysql module |
2
|
|
|
|
|
|
|
#mt 16/11/2003 2.4 added parseFragmentToString |
3
|
|
|
|
|
|
|
package Plack::App::WebMySQL::General; |
4
|
|
|
|
|
|
|
BEGIN { |
5
|
1
|
|
|
1
|
|
738
|
use Exporter(); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
19
|
|
6
|
1
|
|
|
1
|
|
3
|
use Plack::App::WebMySQL; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
81
|
|
7
|
1
|
|
|
1
|
|
7
|
@ISA = qw(Exporter); |
8
|
1
|
|
|
|
|
462
|
@EXPORT = qw(getData replace parsePage parseFragmentToString); |
9
|
|
|
|
|
|
|
} |
10
|
|
|
|
|
|
|
############################################################################################################### |
11
|
|
|
|
|
|
|
sub getData{ #gets cgi form data into a hash |
12
|
|
|
|
|
|
|
#foreach (keys %ENV){print STDERR "$_ = $ENV{$_}\n";} |
13
|
0
|
|
|
0
|
0
|
|
my $cgi = CGI::new(); |
14
|
0
|
|
|
|
|
|
%form = (); #empty first as PSGI will keep globals set until the server is killed. |
15
|
0
|
|
|
|
|
|
foreach($cgi -> param()){ |
16
|
0
|
|
|
|
|
|
$form{$_} = $cgi -> param($_); |
17
|
|
|
|
|
|
|
#print STDERR "$_ = $form{$_}\n"; |
18
|
|
|
|
|
|
|
} |
19
|
0
|
|
|
|
|
|
return 1; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
############################################################################################################### |
22
|
|
|
|
|
|
|
sub replace{ #make sure we dont get any undefined values when replacing template placeholders |
23
|
0
|
0
|
|
0
|
0
|
|
if(defined($form{$_[0]})){return $form{$_[0]};} #return hash value |
|
0
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
else{ |
25
|
0
|
|
|
|
|
|
print STDERR "$0: $_[0] is undefined in placeholder replace\n"; |
26
|
0
|
|
|
|
|
|
return ""; #return nothing |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
############################################################################################################### |
30
|
|
|
|
|
|
|
sub parsePage{ #displays a html page |
31
|
0
|
|
|
0
|
0
|
|
my $page = shift; |
32
|
0
|
|
|
|
|
|
my $ignoreError = shift; |
33
|
0
|
0
|
0
|
|
|
|
if($error && !$ignoreError){ #an error has not been encountered and we are not ignoring it |
34
|
0
|
|
|
|
|
|
$page = "error"; |
35
|
0
|
|
|
|
|
|
print STDERR "$0: $error\n"; #log this error too |
36
|
|
|
|
|
|
|
} |
37
|
0
|
0
|
|
|
|
|
if(open(TEMPLATE, "
|
38
|
0
|
|
|
|
|
|
while(){ #read the file a line at a time |
39
|
0
|
|
|
|
|
|
$_ =~ s//\n\t/; |
40
|
0
|
|
|
|
|
|
$_ =~ s//$ENV{'SCRIPT_NAME'}/g; #replace the name for this script |
41
|
0
|
|
|
|
|
|
$_ =~ s//$ENV{'HTTP_HOST'}/g; #replace webserver name |
42
|
0
|
|
|
|
|
|
$_ =~ s//$error/g; #replace the error message |
43
|
0
|
|
|
|
|
|
$_ =~ s//$VERSION/g; #replace version number |
44
|
0
|
|
|
|
|
|
$_ =~ s//&replace($1)/eg; #replace the placeholders in the template |
|
0
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
$_ =~ s||
\n\n|; |
46
|
0
|
|
|
|
|
|
print; |
47
|
|
|
|
|
|
|
} |
48
|
0
|
|
|
|
|
|
close(TEMPLATE); |
49
|
|
|
|
|
|
|
} |
50
|
|
|
|
|
|
|
else{ |
51
|
0
|
|
|
|
|
|
print << "(NO TEMPLATE)"; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
Could not open HTML template: webmysql/templates/$page.html |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
(NO TEMPLATE) |
58
|
|
|
|
|
|
|
} |
59
|
|
|
|
|
|
|
} |
60
|
|
|
|
|
|
|
############################################################################################################### |
61
|
|
|
|
|
|
|
sub parseFragmentToString{ #save a html fragment to a string |
62
|
0
|
|
|
0
|
0
|
|
my $page = shift; |
63
|
0
|
|
|
|
|
|
my $string = "\n"; |
64
|
0
|
0
|
|
|
|
|
if(open(TEMPLATE, "
|
65
|
0
|
|
|
|
|
|
while(){ #read the file a line at a time |
66
|
0
|
|
|
|
|
|
$_ =~ s//$ENV{'SCRIPT_NAME'}/g; #replace the name for this script |
67
|
0
|
|
|
|
|
|
$_ =~ s//$ENV{'HTTP_HOST'}/g; #replace webserver name |
68
|
0
|
|
|
|
|
|
$_ =~ s//$error/g; #replace the error message |
69
|
0
|
|
|
|
|
|
$_ =~ s//$VERSION/g; #replace version number |
70
|
0
|
|
|
|
|
|
$_ =~ s//&replace($1)/eg; #replace the placeholders in the template |
|
0
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
$string .= $_ |
72
|
|
|
|
|
|
|
} |
73
|
0
|
|
|
|
|
|
close(TEMPLATE); |
74
|
|
|
|
|
|
|
} |
75
|
0
|
|
|
|
|
|
else{$error = "Cant open HTML fragment: $page";} |
76
|
0
|
|
|
|
|
|
return $string; |
77
|
|
|
|
|
|
|
} |
78
|
|
|
|
|
|
|
############################################################################### |
79
|
|
|
|
|
|
|
return 1; |
80
|
|
|
|
1
|
|
|
END {} |
81
|
|
|
|
|
|
|
|