line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package HTML::Myasp; |
2
|
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
require Exporter; |
4
|
|
|
|
|
|
|
|
5
|
|
|
|
|
|
|
@ISA = qw(Exporter); |
6
|
|
|
|
|
|
|
@EXPORT = qw/send_page/; |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
require 5.005_62; |
9
|
1
|
|
|
1
|
|
32237
|
use strict; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
46
|
|
10
|
1
|
|
|
1
|
|
5
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
51
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.05'; |
13
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
6
|
|
|
1
|
|
|
|
|
192
|
|
15
|
1
|
|
|
1
|
|
3753
|
use Data::Dumper; |
|
1
|
|
|
|
|
20452
|
|
|
1
|
|
|
|
|
693
|
|
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
my %CACHE; |
18
|
|
|
|
|
|
|
our $DEBUG = 0; |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
our %g_hparam; |
21
|
|
|
|
|
|
|
our %g_hreplace; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
#----------------------------------------------------------------------------------------------- |
24
|
|
|
|
|
|
|
sub add_sub_entry { |
25
|
|
|
|
|
|
|
|
26
|
0
|
|
|
0
|
0
|
|
%g_hparam = (%g_hparam, @_); |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
#----------------------------------------------------------------------------------------------- |
31
|
|
|
|
|
|
|
# add an entry in the direct replace hash (the second) |
32
|
|
|
|
|
|
|
sub add_replace_entry { |
33
|
|
|
|
|
|
|
|
34
|
0
|
|
|
0
|
0
|
|
%g_hreplace = (%g_hreplace, @_); |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
#----------------------------------------------------------------------------------------------- |
39
|
|
|
|
|
|
|
sub send_page { |
40
|
|
|
|
|
|
|
|
41
|
0
|
|
|
0
|
0
|
|
local $SIG{__DIE__} = \&Carp::confess; |
42
|
|
|
|
|
|
|
|
43
|
0
|
|
|
|
|
|
my ($file, $hparam, $hreplace) = @_; |
44
|
|
|
|
|
|
|
|
45
|
0
|
|
|
|
|
|
map {$hparam->{$_} = $g_hparam{$_} } keys %g_hparam; |
|
0
|
|
|
|
|
|
|
46
|
0
|
|
|
|
|
|
map {$hreplace->{$_} = $g_hreplace{$_} } keys %g_hreplace; |
|
0
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
0
|
0
|
|
|
|
|
print STDERR "Sub Routine reference hash is\n" if $DEBUG; |
49
|
0
|
0
|
|
|
|
|
warn Dumper $hparam if $DEBUG; |
50
|
0
|
0
|
|
|
|
|
print STDERR "Direct replacing hash\n" if $DEBUG; |
51
|
0
|
0
|
|
|
|
|
warn Dumper $hreplace if $DEBUG; |
52
|
|
|
|
|
|
|
|
53
|
0
|
|
|
|
|
|
my $tagprefix; |
54
|
|
|
|
|
|
|
|
55
|
0
|
|
|
|
|
|
my ($source, $string_text); |
56
|
0
|
0
|
|
|
|
|
if (length($file) > 128) { |
57
|
0
|
|
|
|
|
|
$source = 'string'; |
58
|
0
|
|
|
|
|
|
$string_text = $file; |
59
|
0
|
|
|
|
|
|
$file = substr($file,0,255); |
60
|
|
|
|
|
|
|
} else { |
61
|
0
|
|
|
|
|
|
$source = 'file'; |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
0
|
0
|
|
|
|
|
warn "Source is coming from a $source" if $DEBUG; |
65
|
|
|
|
|
|
|
|
66
|
0
|
0
|
|
|
|
|
if (exists $ENV{MOD_PERL}) { |
67
|
0
|
|
|
|
|
|
my $r = Apache->request(); |
68
|
0
|
|
|
|
|
|
$file = $r->document_root() . "/$file"; # if mod_perl the document root is prefixed to the file path |
69
|
0
|
|
0
|
|
|
|
$tagprefix = $r->dir_config("TagPrefix") || 'myasp'; |
70
|
|
|
|
|
|
|
} else { |
71
|
0
|
|
|
|
|
|
$tagprefix = 'myasp'; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
|
74
|
0
|
0
|
|
|
|
|
$tagprefix = $ENV{TagPrefix} if $ENV{TagPrefix}; # always environment variables can change behavior |
75
|
|
|
|
|
|
|
|
76
|
0
|
0
|
|
|
|
|
warn "TagPrefix is $tagprefix" if $DEBUG; |
77
|
|
|
|
|
|
|
|
78
|
0
|
0
|
|
|
|
|
my $mtime = $source eq 'file' ? (stat($file))[9] : time; |
79
|
|
|
|
|
|
|
|
80
|
0
|
|
|
|
|
|
my ($package,$filename,$line) = caller; |
81
|
0
|
|
|
|
|
|
my $caller_mtime = (stat($filename))[9]; |
82
|
|
|
|
|
|
|
|
83
|
0
|
0
|
0
|
|
|
|
if (!$CACHE{$file} || $mtime > $CACHE{$file}->{load_time} || $caller_mtime > $CACHE{$file}->{caller_mtime}) { |
|
|
|
0
|
|
|
|
|
84
|
|
|
|
|
|
|
|
85
|
0
|
0
|
|
|
|
|
warn "File $file reloaded or loaded first time" if $DEBUG; |
86
|
|
|
|
|
|
|
|
87
|
0
|
0
|
|
|
|
|
if ($source eq 'file') { |
88
|
1
|
|
|
1
|
|
1309
|
use IO::File; |
|
1
|
|
|
|
|
49771
|
|
|
1
|
|
|
|
|
2712
|
|
89
|
0
|
|
|
|
|
|
my $fh = new IO::File; |
90
|
0
|
0
|
|
|
|
|
unless ($fh->open("<$file")) { |
91
|
0
|
|
|
|
|
|
print " Archivo no encontrado: $file "; |
92
|
0
|
|
|
|
|
|
return; |
93
|
|
|
|
|
|
|
} |
94
|
0
|
|
|
|
|
|
local $/ = undef; |
95
|
0
|
|
|
|
|
|
$CACHE{$file}->{f_text} = <$fh>; |
96
|
0
|
|
|
|
|
|
close $fh; |
97
|
|
|
|
|
|
|
} else { |
98
|
0
|
|
|
|
|
|
$CACHE{$file}->{f_text} = $string_text; |
99
|
|
|
|
|
|
|
} |
100
|
|
|
|
|
|
|
|
101
|
0
|
|
|
|
|
|
$CACHE{$file}->{load_time} = time; |
102
|
0
|
|
|
|
|
|
$CACHE{$file}->{caller_mtime} = time; |
103
|
|
|
|
|
|
|
|
104
|
|
|
|
|
|
|
|
105
|
0
|
|
|
|
|
|
my ($last, @data); |
106
|
|
|
|
|
|
|
|
107
|
0
|
|
|
|
|
|
while ($CACHE{$file}->{f_text} =~ m#(.+?)<$tagprefix:(.+?)(\s.+?)?>(.*?)$tagprefix:\2>#gs) { |
108
|
|
|
|
|
|
|
|
109
|
0
|
0
|
|
|
|
|
warn "$2 mark found" if $DEBUG; |
110
|
|
|
|
|
|
|
|
111
|
0
|
|
|
|
|
|
my %arr; |
112
|
0
|
0
|
|
|
|
|
if ($3) { |
113
|
0
|
|
|
|
|
|
my $aux = $3; |
114
|
0
|
|
|
|
|
|
$aux =~ s/^\s+//; $aux =~ s/\s+$//; |
|
0
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
# while (my ($key, $value) = $aux =~ /(\S+)=("[^"]"|\S+)/gs) { |
117
|
|
|
|
|
|
|
# $arr{$key} = $value; |
118
|
|
|
|
|
|
|
# } |
119
|
|
|
|
|
|
|
|
120
|
0
|
|
|
|
|
|
%arr = split /=|\s+/, $aux; |
121
|
|
|
|
|
|
|
|
122
|
0
|
|
|
|
|
|
foreach (keys %arr) { |
123
|
0
|
|
|
|
|
|
$arr{$_} =~ s/"//g; |
124
|
|
|
|
|
|
|
} |
125
|
|
|
|
|
|
|
} |
126
|
0
|
|
|
|
|
|
push @data, {-html => $1, -type=>'html'}; |
127
|
0
|
0
|
|
|
|
|
push @data, {-name=>"-$2", -coderef => $hparam->{"\-$2"}, -type=>'cod', -param_ref => \%arr, -param_body => $4} if $hparam->{"\-$2"}; |
128
|
|
|
|
|
|
|
|
129
|
0
|
|
|
|
|
|
$last = $'; |
130
|
|
|
|
|
|
|
|
131
|
|
|
|
|
|
|
} |
132
|
0
|
0
|
|
|
|
|
if (@data) { |
133
|
0
|
|
|
|
|
|
push @data, {-html => $last, -type=>'html'}; |
134
|
|
|
|
|
|
|
} else { |
135
|
0
|
|
|
|
|
|
push @data, {-html =>$CACHE{$file}->{f_text}, -type=>'html'}; |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
|
138
|
0
|
|
|
|
|
|
$CACHE{$file}->{data} = \@data; |
139
|
|
|
|
|
|
|
|
140
|
|
|
|
|
|
|
} else { |
141
|
0
|
0
|
|
|
|
|
warn "Cache Hit file $file" if $DEBUG; |
142
|
|
|
|
|
|
|
} |
143
|
|
|
|
|
|
|
|
144
|
|
|
|
|
|
|
|
145
|
|
|
|
|
|
|
# the tags fields in the page are |
146
|
|
|
|
|
|
|
|
147
|
0
|
0
|
|
|
|
|
print STDERR "Begin parsed data file ***********\n" if $DEBUG; |
148
|
0
|
0
|
|
|
|
|
warn Dumper $CACHE{$file} if $DEBUG; |
149
|
0
|
0
|
|
|
|
|
print STDERR "End parsed data file ***********\n" if $DEBUG; |
150
|
|
|
|
|
|
|
|
151
|
0
|
|
|
|
|
|
foreach my $x (@{$CACHE{$file}->{data}}) { |
|
0
|
|
|
|
|
|
|
152
|
0
|
0
|
|
|
|
|
if ($x->{-type} eq 'html') { |
153
|
0
|
0
|
|
|
|
|
next unless $x->{-html}; |
154
|
0
|
|
|
|
|
|
my $temp = $x->{-html}; |
155
|
0
|
0
|
|
|
|
|
print STDERR "Checking HTML replacing keywords\n" if $DEBUG; |
156
|
0
|
0
|
|
|
|
|
warn $temp if $DEBUG; |
157
|
|
|
|
|
|
|
|
158
|
0
|
|
|
|
|
|
foreach my $key (keys %$hreplace) { |
159
|
0
|
0
|
|
|
|
|
warn "Checking key \"${key}\" and replacing with \"$hreplace->{$key}\"" if $DEBUG; |
160
|
|
|
|
|
|
|
|
161
|
0
|
0
|
|
|
|
|
if ($temp =~ s/\b${key}\b/$hreplace->{$key}/gis) { |
162
|
0
|
0
|
|
|
|
|
warn "String $key replaced" if $DEBUG; |
163
|
|
|
|
|
|
|
} |
164
|
|
|
|
|
|
|
} |
165
|
0
|
|
|
|
|
|
print $temp; |
166
|
|
|
|
|
|
|
} else { |
167
|
|
|
|
|
|
|
|
168
|
0
|
0
|
|
|
|
|
warn "Calling function $x->{-name}" if $DEBUG; |
169
|
0
|
0
|
|
|
|
|
&Carp::cluck ("Stack de llamadas") if $DEBUG; |
170
|
0
|
0
|
|
|
|
|
print STDERR "The atributes of the tag are\n" if $DEBUG; |
171
|
0
|
0
|
|
|
|
|
warn Dumper $x->{-param_ref} if $DEBUG; |
172
|
0
|
0
|
|
|
|
|
print STDERR "*** Begin body between the marks is \n$x->{-param_body}\n" if $DEBUG; |
173
|
0
|
0
|
|
|
|
|
print STDERR "*** End body between the marks\n" if $DEBUG; |
174
|
|
|
|
|
|
|
|
175
|
0
|
0
|
|
|
|
|
unless (ref($hparam->{$x->{-name}})) { |
176
|
0
|
|
|
|
|
|
warn "Tag in template but not a handler subroutine defined: key $x->{-name}, template $file, called from $filename line $line"; |
177
|
0
|
|
|
|
|
|
next; |
178
|
|
|
|
|
|
|
} else { |
179
|
0
|
|
|
|
|
|
&{$hparam->{$x->{-name}}}($x->{-param_ref}, $x->{-param_body}); |
|
0
|
|
|
|
|
|
|
180
|
|
|
|
|
|
|
} |
181
|
|
|
|
|
|
|
} |
182
|
|
|
|
|
|
|
|
183
|
|
|
|
|
|
|
} |
184
|
|
|
|
|
|
|
|
185
|
0
|
|
|
|
|
|
1; |
186
|
|
|
|
|
|
|
|
187
|
|
|
|
|
|
|
} |
188
|
|
|
|
|
|
|
|
189
|
|
|
|
|
|
|
|
190
|
|
|
|
|
|
|
|
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
1; |
193
|
|
|
|
|
|
|
__END__ |