Apache-ASP
view release on metacpan or search on metacpan
$data .= $munge; # append what's left
# print STDERR $file."\n\n".$data."\n\n";
# so we have the full script for people
if(! $self->{compile_includes}) {
# do pod comments again if we have any included files
if(%includes && $self->{pod_comments}) {
&PodComments($self, \$data);
}
if($self->{GlobalASA}{'exists'}) {
$self->{Server}{ScriptRef} = \$data;
$self->{GlobalASA}->ExecuteEvent('Script_OnParse');
}
}
# $self->Debug("parsing includes done $self->{'basename'}");
# strip carriage returns; do this as early as possible, but after includes
# since we want to rip out the carriage returns from them too, these
# changes should make things Win & Mac compatible
# my $CRLF = "\015\012";
$data =~ s/\015?\012/\n/sgo;
$data =~ s/\s+$//so; # strip trailing white space
my $script = &ParseHelper($self, \$data, 1);
if($script) {
my $strict = $self->{use_strict} ? "use strict;" : "no strict";
$$script = join(";;",
$strict,
"use vars qw(\$".join(" \$",@Apache::ASP::Objects).')',
($file_exists ? "\n#line 1 $root_file\n" : ''),
$$script,
);
return {
is_perl => 1,
data => $script,
};
} else {
return {
is_raw => 1,
data => \$data,
};
}
}
sub ParseHelper {
my($self, $data, $check_static_file) = @_;
my($script, $text, $perl);
if($self->{xml_subs_match}) {
my $start = $$data;
$self->{dbg} && $self->Debug("start parse of data", length($$data));
$$data = $self->ParseXMLSubs($$data);
# print STDERR "START $start\n\n";
# print STDERR "END $$data\n\n";
}
# we only do this check the first time we call ParseHelper() from
# Parse() with $check_static_file set. Calls from ParseXMLSubs()
# will leave this off. This is where we start to throw data
# back that lets the system render a static file as is instead
# of executing it as a per subroutine.
return if ($check_static_file && $$data !~ /\<\%.*?\%\>/s);
my(@out, $perl_block, $last_perl_block);
$$data .= "<%;;;%>"; # always end with some perl code for parsing.
# can't do it for <%= %><% %> constructions
# $$data =~ s/\%\>(\s*)\<\%/;$1/isg; # compress close code blocks, move white space to code
while($$data =~ s/^(.*?)\<\%(.*?)\%\>//so) {
($text, $perl) = ($1,$2);
$perl_block = ($perl =~ /^\s*\=(.*)$/so) ? 0 : 1;
my $perl_scalar = $1;
# with some extra text parsing, we remove asp formatting from
# influencing the generated html formatting, in particular
# dealing with perl blocks and new lines
if($text) {
# don't touch the white space, to preserve line numbers
$text =~ s/\\/\\\\/gso;
$text =~ s/\'/\\\'/gso;
if($last_perl_block) {
$last_perl_block = 0;
}
push(@out, "\'".$text."\'")
}
if($perl) {
if(! $perl_block) {
# we have a scalar assignment here
push(@out, '('.$perl_scalar.')');
} else {
$last_perl_block = 1;
if(@out) {
# we pass by reference here with the idea that we are not
# copying the HTML twice this way. This might be large
# saving on a typical site with rich HTML headers & footers
$script .= '&Apache::ASP::WriteRef($main::Response, \('.join('.', @out).'));';
# $script .= '$main::Response->{Bit} = \('.join('.', @out).');';
# $script .= '($main::Response->{Buffer} && ! $main::Response->{Ended}) ? '.
# '${$main::Response->{out}} .= ${$main::Response->{Bit}} : '.
# '$main::Response->WriteRef($main::Response->{Bit}); ';
@out = ();
}
# allow old <% #comment %> style to still work, but we
# need to insert a newline at the end of the comment for
# it to still exist, with the lines now being sync'd up
# if these old comments still exist, they perl script
# will be off by one line from the asp script
if ($perl !~ /\n\s*$/so) {
if($perl =~ /\#[^\n]*$/so) {
# print STDERR "NEW adding newline to [$perl]\n";
$perl .= "\n";
}
}
# if the $file is an absolute path, then just return the file
# if the $file is a relative path, concat it with the passed in directory
sub AbsPath {
my($file, $dir) = @_;
# we test for first unix style and then win32 style path conventions
if($file =~ m|^/| or $file =~ m|^.\:|) {
$file;
} else {
# we only can absolute the path if the directory path is absolute
if($dir =~ m|^/| or $dir =~ m|^.\:|) {
$file = $dir.'/'.$file;
} else {
$file;
}
}
}
sub CompilePerl {
my($self, $script, $subid, $package) = @_;
$package ||= $self->{GlobalASA}{'package'};
$subid ||= '';
ref($script) || die("no ref to perl script to compile");
$subid && $self->UndefRoutine($subid);
$self->{dbg} && $self->Debug("compiling into package $package subid [$subid]");
$self->{compile_perl_count}++; # counter used in test case closure.t
my $eval =
join(" ;; ",
"package $package;", # for no sub closure
"sub $subid { ",
"package $package;", # for sub closure
$$script,
'}',
);
# $eval =~ tr///; # untaint
$eval =~ /^(.*)$/s;
$eval = $1;
my $sub_ref;
if($self->{use_strict}) {
local $SIG{__WARN__} = sub { die("maybe use strict error: ", @_) };
# comment out for now, until 3.0 release for this may create lots
# of compile time errors for people that will need to fix scripts
# local $^W = 1; # trigger my closure errors, --jc 9/7/2002
$sub_ref = eval $eval;
} else {
local $SIG{__WARN__} = sub { $self->Out(@_) };
$sub_ref = eval $eval;
}
my $rv; # for readability
my $error = $@;
if($@) {
$self->CompileError($eval); # don't throw error, so we can throw die later
$subid && $self->UndefRoutine($subid);
$rv = undef;
} else {
if($subid) {
if(&config($self, 'RegisterIncludes')) {
$self->RegisterIncludes($script);
}
$rv = $subid;
} else {
$rv = $sub_ref;
}
}
$@ = $error;
$rv;
}
sub TestForSubs {
my($self, $script) = @_;
$$script =~ /(^|\n)\s*sub\s+([^\s\{]+)\s*\{/ ? 1 : 0;
}
sub InitPackageGlobals {
my $self = shift;
unless($self->{response_tied}) {
# set printing to Response object
$self->{response_tied} = 1;
tie *RESPONSE, 'Apache::ASP::Response', $self->{Response};
select(RESPONSE);
}
# ---- init package objects ----
# unoptimized this because we should only call this function once
# and maybe twice if there is a defined Script_OnStart
for my $object (@Apache::ASP::Objects) {
for my $import_package (@{$self->{init_packages}}) {
my $init_var = $import_package.'::'.$object;
$$init_var = $self->{$object}; }
}
undef;
}
sub Run {
my $self = shift;
($self->{stat_inc_match} || $self->{stat_inc}) && $self->StatINC;
my $compiled;
if(! $self->{errs}) {
my $compile_file = $self->{filehandle}; # filehandle for filtering
unless($compile_file) {
# need SearchDirs() to make full path for base file, test suite is
# not OK with using $self->{filename}
$compile_file = $self->SearchDirs($self->{basename});
unless($compile_file) {
$self->Error("no file found for $self->{basename}");
return;
}
will become the default by Apache::ASP version 3.0
++Optimization for static HTML/XML files that are served up
via Apache::ASP so that they are not compiled into perl subroutines
first. This makes especially native XSLT both faster & take
less memory to serve, before XSL & XML files being transformed
by XSLT would both be compiled as normal ASP script first, so
now this will happen if they really are ASP scripts with embedded
<% %> code blocks & XMLSubs being executed.
+Consolidate some config data for Apache::ASP->Loader to use
globals in @Apache::ASP::CompileChecksumKeys to know which
config data is important for precompiling ASP scripts.
+Further streamlined code compilation. Now both base
scripts and includes use the internal CompileInclude() API
to generate code.
-Fixed runtime HTML error output when Debug is set to -2/2,
so that script correctly again gets rendered in final perl form.
Added compile time error output to ./site/eg/syntax_error.asp
when a special link is clicked for a quick visual test.
-Cleaned up some bad coding practices in ./site/eg/global.asa
associated changes in other example files. Comment example
global.asa some for the first time reader
-DemoASP.pm examples module needed "use strict" fix, thanks
to Allan Vest for bug report
--$rv = $Response->Include({ File => ..., Cache => 1});
now works to get the first returned value fetched from
the cache. Before, because a list was always returned,
$rv would have been equal to the number of items returned,
even if the return value list has just one element.
(d) added site/robots.txt file with just a comment for
search engine indexing
-fixed ./site/eg/binary_write.htm to not use
$Response->{ContentLength} because it does not exist.
Fixed it to use $Response->AddHeader now instead
=item $VERSION = 2.41; $DATE="09/29/2002"
-Removed CVS Revision tag from Apache::ASP::Date, which
was causing bad revision numbers in CPAN after CVS integration
of Apache::ASP
+removed cgi/asp link to ../asp-perl from distribution. This
link was for the deprecated asp script which is now asp-perl
=item $VERSION = 2.39; $DATE="09/10/2002"
-Turn off $^W explicitly before reloading global.asa. Reloading
global.asa when $^W is set will trigger subroutine redefinition
warnings. Reloading global.asa should occur without any problems
under normal usage of the system, thus this work around.
This fix is important to UseStrict functionality because warnings
automatically become thrown as die() errors with UseStrict enabled,
so we have to disable normal soft warnings here.
-$Response->Include() runtime errors now throw a die() that
can be trapped. This was old functionality that has been restored.
Other compile time errors should still trigger a hard error
like script compilation, global.asa, or $Response->Include()
without an eval()
+Some better error handling with Debug 3 or -3 set, cleaned
up developer errors messages somewhat.
=item $VERSION = 2.37; $DATE="07/03/2002"
-Fixed the testing directory structures for t/long_names.t
so that tar software like Archive::Tar & Solaris tar that
have problems with long file names will still be able
to untar distribution successfully. Now t/long_names.t
generates its testing directory structures at runtime.
-Fixes for "make test" to work under perl 5.8.0 RC2,
courtesy of Manabu Higashida
+SessionQueryForce setting created for disabling use of cookies
for $Session session-id passing, rather requiring use of SessionQuery*
functionality for session-id passing via URL query string.
By default, even when SessionQuery* options are used, cookies will
be used if available with SessionQuery* functionality acting only
as a backup, so this makes it so that cookies will never be used.
+Escape ' with HTMLEncode() to '
-Trying to fix t/server_mail.t to work better for platforms
that it should skip testing on. Updated t/server.t test case.
+Remove exit() from Makefile.PL so CPAN.pm's automatic
follow prereq mechanism works correctly. Thanks to Slaven Rezic
for pointing this out.
+Added Apache::compat loading in mod_perl environment for better
mod_perl 2.0 support.
=item $VERSION = 2.35; $DATE="05/30/2002"
+Destroy better $Server & $Response objects so that my
closure references to these to not attempt to work in the future
against invalid internal data. There was enough data left in these
old objects to make debugging the my closure problem confusing, where
it looked like the ASP object state became invalid.
+Added system debug diagnostics to inspect StateManager group cleanup
(d) Documentation update about flock() work around for
Win95/Win98/WinMe systems, confirmed by Rex Arul
(d) Documentation/site build bug found by Mitsunobu Ozato,
where <% %> not being escaped correctly with $Server->HTMLEncode().
New japanese documentation project started by him
at http://sourceforge.jp/projects/apache-asp-jp/
-InitPackageGlobals() called after new Apache::ASP object created so
core system templates can be compiled even when there was a runtime
compilation error of user templates. Bug fix needed pointed out by
+Updated documentation with new config settings and
API extensions.
+Added AllowApplicationState config option which allows
you to leave $Application undefined, and will not
execute Application_OnStart or Application_OnEnd.
This can be a slight performance increase of 2-3% if
you are not using $Application, but are using $Session.
+Added $Session->Lock() / $Session->UnLock() API routines
necessary additions since access to session is not
serialized by default like IIS ASP. Also prompted
by change in locking code which retied to SDBM_File
or DB_File each lock. If you $Session->Lock / UnLock
around many read/writes, you will increase performance.
+Added StateCache config which, if set will cache
the file handle locks for $Application and an internal
database used for tracking $Session info. This caching can
make an ASP application perform up to 10% faster,
at a cost of each web server process holding 2 more
cached file handles open, per ASP application using
this configuration. The data written to or read from
these state databases is not cached, just the locking
file handles are held open.
-Added in much more locking in session manager
and session garbage collector to help avoid collisions
between the two. There were definite windows that the
two would collide in, during which bad things could
happen on a high volume site.
-Fixed some warnings in DESTROY and ParseParams()
=item $VERSION = 0.14; $DATE="07/29/1999";
-CGI & StatINC or StatINCMatch would have bad results
at times, with StatINC deleting dynamically compiled
CGI subroutines, that were imported into other scripts
and modules namespaces.
A couple tweaks, and now StatINC & CGI play nice again ;)
StatINCMatch should be safe to use in production with CGI.
This affects in particular environments that use file upload,
since CGI is loaded automatically by Apache::ASP to handle
file uploads.
This fix should also affect other seemingly random
times when StatINC or StatINCMatch don't seem to do
the right thing.
+use of ASP objects like $Response are now "use strict"
safe in scripts, while UniquePackages config is set.
+Better handling of "use strict" errors in ASP scripts.
The error is detected, and the developer is pointed to the
Apache error log for the exact error.
The script with "use strict" errors will be recompiled again. Its seems
though that "use strict" will only throw its error once, so that a script
can be recompiled with the same errors, and work w/o any use strict
error messaging.
=item $VERSION = 0.12; $DATE="07/01/1999";
-Compiles are now 10 +times faster for scripts with lots of big
embedded perl blocks <% #perl %>
Compiles were slow because of an old PerlScript compatibility
parsing trick where $Request->QueryString('hi')->{item}
would be parsed to $Request->QueryString('hi') which works.
I think the regexp that I was using had O(n^2) characteristics
and it took a really big perl block to 10 +seconds to parse
to understand there was a problem :(
I doubt anyone needed this compatibility, I don't even see
any code that looks like this in the online PerlScript examples,
so I've commented out this parsing trick for now. If you
need me to bring back this functionality, it will be in the
form of a config setting.
For information on PerlScript compatibility, see the PerlScript
section in the ASP docs.
-Added UniquePackages config option, that if set brings back
the old method of compiling each ASP script into its own
separate package. As of v.10, scripts are compiled by default
into the same package, so that scripts, dynamic includes & global.asa
can share globals. This BROKE scripts in the same ASP Application
that defined the same sub routines, as their subs would redefine
each other.
UniquePackages has scripts compiled into separate perl packages,
so they may define subs with the same name, w/o fear of overlap.
Under this settings, scripts will not be able to share globals.
-Secure field for cookies in $Response->Cookies() must be TRUE to
force cookie to be secure. Before, it just had to be defined,
which gave wrong behavior for Secure => 0.
+$Response->{IsClientConnected} set to one by default. Will
work out a real value when I upgrade to apache 1.3.6. This
value has no meaning before, as apache aborts the perl code
when a client drops its connection in earlier versions.
+better compile time debugging of dynamic includes, with
Debug 2 setting
+"use strict" friendly handling of compiling dynamic includes
with errors
=item $VERSION = 0.11; $DATE="06/24/1999";
+Lots of documentation updates
+The MailHost config option is the smtp server used for
relay emails for the Mail* config options.
+MailAlertTo config option used for sending a short administrative
alert for an internal ASP error, server code 500. This is the
when the real GlobalPackage changed on disk, as we do a full sweep
through the namespace. Now, we skip those subs that we know to
be includes or scripts.
-Using Apache::Symbol::undef() to undefine precompiled scripts
and includes when reloading those scripts. Doing just an undef()
would sometimes result in an "active subroutine undef" error.
This bug came out when I started thrashing the StatINC system
for production use.
+StatINCMatch setting created for production use reloading of
perl modules. StatINCMatch allows StatINC reloading of a
subset of all the modules defined in %INC, those that match
$module =~ /$StatINCMatch/, where module is some module name
like Class/Struct.pm
+Reoptimized pod comment parsing. I slowed it down to sync
lines numbers in the last version, but found another corner I could cut.
=item $VERSION = 0.10; $DATE="05/24/1999";
+= improvement; - = bug fix
+Added index.html file to ./eg to help people wade through
the examples. This one has been long overdue.
+Clean config option, or setting $Response->{Clean} to 1 - 9,
uses HTML::Clean to compress text/html output of ASP scripts.
I like the Clean 1 setting which is lightweight, stripping
white space for about 10% compression, at a cost of less than
a 5% performance penalty.
+Using pod style commenting no longer confuses the line
numbering. ASP script line numbers are almost exactly match
their compiled perl version, except that normal inline includes
(not dynamic) insert extra text which can confuse line numbering.
If you want perl error line numbers to entirely sync with your
ASP scripts, I would suggest learning how to use dynamic includes,
as opposed to inline includes.
-Wrapped StatINC reloading of libs in an eval, and capturing
error for Debug 2 setting. This makes changing libs with StatINC
on a little more friendly when there are errors.
-$Request->QueryString() now stores multiple values for the
same key, just as $Request->Form() has since v.07. In
wantarray() context like @vals = $Request->QueryString('dupkey'),
@vals will store whatever values where associated with dupkey
in the query string like (1,2) from: ?dupkey=1&dupkey=2
+The GlobalPackage config directive may be defined
to explicitly set the perl module that all scripts and global.asa
are compiled into.
-Dynamic includes may be in the Global directory, just like
normal includes.
+Perl script generated from asp scripts should match line
for line, seen in errors, except when using inline (default)
includes, pod comments, or <% #comment %> perl comments, which
will throw off the line counts by adding text, removing
text, or having an extra newline added, respectively.
-Script_OnEnd may now send output to the browser. Before
$main::Response->End() was being called at the end of the
main script preventing further output.
++All scripts are compiled as routines in a namespace uniquely
defined by the global.asa of the ASP application. Thus,
scripts, includes, and global.asa routines will share
all globals defined in the global.asa namespace. This means
that globals between scripts will be shared, and globals
defined in a global.asa will be available to scripts.
Scripts used to have their own namespace, thus globals
were not shared between them.
+a -o $output_dir switch on the ./cgi/asp script allows
it to execute scripts and write their output to an output
directory. Useful for building static html sites, based on
asp scripts. An example use would be:
asp -b -o out *.asp
Without an output directory, script output is written to STDOUT
=item $VERSION = 0.09; $DATE="04/22/1999";
+Updated Makefile.PL optional modules output for CGI & DB_File
+Improved docs on $Response->Cookies() and $Request->Cookies()
+Added PERFORMANCE doc to main README, and added sub section
on precompiling scripts with Apache::ASP->Loader()
+Naming of CompileIncludes switched over to DynamicIncludes
for greater clarity.
+Dynamic includes can now reference ASP objects like $Session
w/o the $main::* syntax. These subs are no longer anonymous
subs, and are now compiled into the namespace of the global.asa package.
+Apache::ASP->Loader() precompiles dynamic includes too. Making this work
required fixing some subtle bugs / dependencies in the compiling process.
+Added Apache::ASP->Loader() similar to Apache::RegistryLoader for
precompiling ASP scripts. Precompile a whole site at server
startup with one function call.
+Prettied the error messaging with Debug 2.
+$Response->Debug(@args) debugging extension, which
allows a developer to hook into the module's debugging,
and only have @args be written to error_log when Debug is greater
than 0.
-Put write locking code around State writes, like $Session
and $Application. I thought I fixed this bug a while ago.
-API change: converted $Session->Timeout() and $Session->SessionID()
( run in 3.058 seconds using v1.01-cache-2.11-cpan-437f7b0c052 )