Author: phred Date: Fri Dec 21 08:22:23 2007 New Revision: 606234 URL: http://svn.apache.org/viewvc?rev=606234&view=rev Log: Matt Sergeant has graciously donated Apache::Reload to the ASF. This commit moves Apache2::Reload from the mod_perl core to the Apache::Reload distribution, including svn mv's of a few files in changeset 606232 from the mod_perl core to this distro.
Reviewed in part by Gozer, Phillip, and Geoff. Added: perl/Apache-Reload/trunk/lib/Apache2/ perl/Apache-Reload/trunk/lib/Apache2/Reload.pm - copied, changed from r594783, perl/modperl/trunk/lib/Apache2/Reload.pm perl/Apache-Reload/trunk/t/conf/ perl/Apache-Reload/trunk/t/conf/extra.last.conf.in perl/Apache-Reload/trunk/t/lib/ perl/Apache-Reload/trunk/t/lib/Apache/ perl/Apache-Reload/trunk/t/lib/Apache/TestReload.pm perl/Apache-Reload/trunk/t/lib/Apache2/ perl/Apache-Reload/trunk/t/lib/Apache2/TestReload.pm - copied, changed from r594783, perl/modperl/trunk/t/response/TestModules/reload.pm perl/Apache-Reload/trunk/t/reload.t - copied, changed from r594783, perl/modperl/trunk/t/modules/reload.t Modified: perl/Apache-Reload/trunk/Changes perl/Apache-Reload/trunk/MANIFEST perl/Apache-Reload/trunk/Makefile.PL perl/Apache-Reload/trunk/README perl/Apache-Reload/trunk/RELEASE perl/Apache-Reload/trunk/lib/Apache/Reload.pm Modified: perl/Apache-Reload/trunk/Changes URL: http://svn.apache.org/viewvc/perl/Apache-Reload/trunk/Changes?rev=606234&r1=606233&r2=606234&view=diff ============================================================================== --- perl/Apache-Reload/trunk/Changes (original) +++ perl/Apache-Reload/trunk/Changes Fri Dec 21 08:22:23 2007 @@ -6,7 +6,17 @@ =over 1 -=item 0.08-dev +=item 0.10-dev + +Apache::Reload and Apache2::Reload bundled for CPAN release +This release incorporates unreleased changes in 0.08 and 0.09 +[Fred Moyer <[EMAIL PROTECTED]>] + +=item 0.09 + +Apache2::Reload was part of mod_perl2 core in this version + +=item 0.08 Remove modified modules before reloading them [Javier Ureuen Val] Modified: perl/Apache-Reload/trunk/MANIFEST URL: http://svn.apache.org/viewvc/perl/Apache-Reload/trunk/MANIFEST?rev=606234&r1=606233&r2=606234&view=diff ============================================================================== --- perl/Apache-Reload/trunk/MANIFEST (original) +++ perl/Apache-Reload/trunk/MANIFEST Fri Dec 21 08:22:23 2007 @@ -3,4 +3,9 @@ README LICENSE lib/Apache/Reload.pm +lib/Apache2/Reload.pm +t/reload.t +t/lib/Apache/TestReload.pm +t/lib/Apache2/TestReload.pm RELEASE +Changes Modified: perl/Apache-Reload/trunk/Makefile.PL URL: http://svn.apache.org/viewvc/perl/Apache-Reload/trunk/Makefile.PL?rev=606234&r1=606233&r2=606234&view=diff ============================================================================== --- perl/Apache-Reload/trunk/Makefile.PL (original) +++ perl/Apache-Reload/trunk/Makefile.PL Fri Dec 21 08:22:23 2007 @@ -38,9 +38,9 @@ require ModPerl::MM; ModPerl::MM::WriteMakefile( %common_opts, - VERSION_FROM => "lib/Apache/Reload.pm", - NAME => "Apache::Reload", - ABSTRACT_FROM => 'lib/Apache/Reload.pm', + VERSION_FROM => "lib/Apache2/Reload.pm", + NAME => "Apache2::Reload", + ABSTRACT_FROM => 'lib/Apache2/Reload.pm', ); } Modified: perl/Apache-Reload/trunk/README URL: http://svn.apache.org/viewvc/perl/Apache-Reload/trunk/README?rev=606234&r1=606233&r2=606234&view=diff ============================================================================== --- perl/Apache-Reload/trunk/README (original) +++ perl/Apache-Reload/trunk/README Fri Dec 21 08:22:23 2007 @@ -101,6 +101,10 @@ AUTHOR Matt Sergeant, [EMAIL PROTECTED] +MAINTAINERS + +the mod_perl developers, [EMAIL PROTECTED] + SEE ALSO Apache::StatINC, Stonehenge::Reload Modified: perl/Apache-Reload/trunk/RELEASE URL: http://svn.apache.org/viewvc/perl/Apache-Reload/trunk/RELEASE?rev=606234&r1=606233&r2=606234&view=diff ============================================================================== --- perl/Apache-Reload/trunk/RELEASE (original) +++ perl/Apache-Reload/trunk/RELEASE Fri Dec 21 08:22:23 2007 @@ -40,8 +40,8 @@ a. edit ./Changes: - find lib -type f -name "*.pm" | \ - xargs perl -pi -e 's,0.08-dev,0.08-rc1,g' - - perl -pi -e 's,0.08-dev,0.08-rc1,g' Changes + xargs perl -pi -e 's,0.10-dev,0.10-rc1,g' + - perl -pi -e 's,0.10-dev,0.10-rc1,g' Changes - don't commit these (see dev@ archives) @@ -60,7 +60,7 @@ o dev/perl.apache.org o modperl/perl.apache.org - Subject: [RELEASE CANDIDATE] Apache-Reload 0.08 RC\d+ + Subject: [RELEASE CANDIDATE] Apache-Reload 0.10 RC\d+ (or maybe longer to give most people a chance to catch up). no need to tag this package @@ -95,7 +95,7 @@ 5. Announce the package a. post ... to the modperl, announce lists - Subject: [ANNOUNCE] Apache-Reload 0.08 + Subject: [ANNOUNCE] Apache-Reload 0.10 include - MD5 sig (as it comes from CPAN upload announce). - the latest Changes @@ -107,7 +107,7 @@ b. edit ./Changes: - start a new item with incremented version + '-dev' - =item 0.92-dev + =item 0.11-dev c. bump up version numbers in this file to make it easier to do the next release. @@ -115,4 +115,4 @@ $ perl -pi -e 's/(\d+)\.(\d+)/join(".", $1, $2+1)/eg' RELEASE d. commit Changes - % svn ci -m "start 0.92-dev cycle" Changes RELEASE lib/Apache/Reload.pm + % svn ci -m "start 0.11-dev cycle" Changes RELEASE lib/Apache/Reload.pm Modified: perl/Apache-Reload/trunk/lib/Apache/Reload.pm URL: http://svn.apache.org/viewvc/perl/Apache-Reload/trunk/lib/Apache/Reload.pm?rev=606234&r1=606233&r2=606234&view=diff ============================================================================== --- perl/Apache-Reload/trunk/lib/Apache/Reload.pm (original) +++ perl/Apache-Reload/trunk/lib/Apache/Reload.pm Fri Dec 21 08:22:23 2007 @@ -17,7 +17,7 @@ use strict; -$Apache::Reload::VERSION = '0.08'; +$Apache::Reload::VERSION = '0.10'; use vars qw(%INCS %Stat $TouchTime %UndefFields); @@ -261,6 +261,10 @@ =head1 AUTHOR Matt Sergeant, [EMAIL PROTECTED] + +=head1 MAINTAINERS + +the mod_perl developers, [EMAIL PROTECTED] =head1 SEE ALSO Copied: perl/Apache-Reload/trunk/lib/Apache2/Reload.pm (from r594783, perl/modperl/trunk/lib/Apache2/Reload.pm) URL: http://svn.apache.org/viewvc/perl/Apache-Reload/trunk/lib/Apache2/Reload.pm?p2=perl/Apache-Reload/trunk/lib/Apache2/Reload.pm&p1=perl/modperl/trunk/lib/Apache2/Reload.pm&r1=594783&r2=606234&rev=606234&view=diff ============================================================================== --- perl/modperl/trunk/lib/Apache2/Reload.pm (original) +++ perl/Apache-Reload/trunk/lib/Apache2/Reload.pm Fri Dec 21 08:22:23 2007 @@ -20,7 +20,7 @@ use mod_perl2; -our $VERSION = '0.09'; +our $VERSION = '0.10'; use Apache2::Const -compile => qw(OK); @@ -182,4 +182,391 @@ } 1; + __END__ + +=head1 NAME + +Apache2::Reload - Reload Perl Modules when Changed on Disk + +=head1 Synopsis + + # Monitor and reload all modules in %INC: + # httpd.conf: + PerlModule Apache2::Reload + PerlInitHandler Apache2::Reload + + # when working with protocols and connection filters + # PerlPreConnectionHandler Apache2::Reload + + # Reload groups of modules: + # httpd.conf: + PerlModule Apache2::Reload + PerlInitHandler Apache2::Reload + PerlSetVar ReloadAll Off + PerlSetVar ReloadModules "ModPerl::* Apache2::*" + #PerlSetVar ReloadDebug On + + # Reload a single module from within itself: + package My::Apache2::Module; + use Apache2::Reload; + sub handler { ... } + 1; + +=head1 Description + +C<Apache2::Reload> reloads modules that change on the disk. + +When Perl pulls a file via C<require>, it stores the filename in the +global hash C<%INC>. The next time Perl tries to C<require> the same +file, it sees the file in C<%INC> and does not reload from disk. This +module's handler can be configured to iterate over the modules in +C<%INC> and reload those that have changed on disk or only specific +modules that have registered themselves with C<Apache2::Reload>. It can +also do the check for modified modules, when a special touch-file has +been modified. + +Note that C<Apache2::Reload> operates on the current context of +C<@INC>. Which means, when called as a C<Perl*Handler> it will not +see C<@INC> paths added or removed by C<ModPerl::Registry> scripts, as +the value of C<@INC> is saved on server startup and restored to that +value after each request. In other words, if you want +C<Apache2::Reload> to work with modules that live in custom C<@INC> +paths, you should modify C<@INC> when the server is started. Besides, +C<'use lib'> in the startup script, you can also set the C<PERL5LIB> +variable in the httpd's environment to include any non-standard 'lib' +directories that you choose. For example, to accomplish that you can +include a line: + + PERL5LIB=/home/httpd/perl/extra; export PERL5LIB + +in the script that starts Apache. Alternatively, you can set this +environment variable in I<httpd.conf>: + + PerlSetEnv PERL5LIB /home/httpd/perl/extra + +=head2 Monitor All Modules in C<%INC> + +To monitor and reload all modules in C<%INC> at the beginning of +request's processing, simply add the following configuration to your +I<httpd.conf>: + + PerlModule Apache2::Reload + PerlInitHandler Apache2::Reload + +When working with connection filters and protocol modules +C<Apache2::Reload> should be invoked in the pre_connection stage: + + PerlPreConnectionHandler Apache2::Reload + +See also the discussion on +C<L<PerlPreConnectionHandler|docs::2.0::user::handlers::protocols/PerlPreConnectionHandler>>. + +=head2 Register Modules Implicitly + +To only reload modules that have registered with C<Apache2::Reload>, +add the following to the I<httpd.conf>: + + PerlModule Apache2::Reload + PerlInitHandler Apache2::Reload + PerlSetVar ReloadAll Off + # ReloadAll defaults to On + +Then any modules with the line: + + use Apache2::Reload; + +Will be reloaded when they change. + +=head2 Register Modules Explicitly + +You can also register modules explicitly in your I<httpd.conf> file +that you want to be reloaded on change: + + PerlModule Apache2::Reload + PerlInitHandler Apache2::Reload + PerlSetVar ReloadAll Off + PerlSetVar ReloadModules "My::Foo My::Bar Foo::Bar::Test" + +Note that these are split on whitespace, but the module list B<must> +be in quotes, otherwise Apache tries to parse the parameter list. + +The C<*> wild character can be used to register groups of files under +the same namespace. For example the setting: + + PerlSetVar ReloadModules "ModPerl::* Apache2::*" + +will monitor all modules under the namespaces C<ModPerl::> and +C<Apache2::>. + +=head2 Monitor Only Certain Sub Directories + +To reload modules only in certain directories (and their +subdirectories) add the following to the I<httpd.conf>: + + PerlModule Apache2::Reload + PerlInitHandler Apache2::Reload + PerlSetVar ReloadDirectories "/tmp/project1 /tmp/project2" + +You can further narrow the list of modules to be reloaded from the +chosen directories with C<ReloadModules> as in: + + PerlModule Apache2::Reload + PerlInitHandler Apache2::Reload + PerlSetVar ReloadDirectories "/tmp/project1 /tmp/project2" + PerlSetVar ReloadAll Off + PerlSetVar ReloadModules "MyApache2::*" + +In this configuration example only modules from the namespace +C<MyApache2::> found in the directories I</tmp/project1/> and +I</tmp/project2/> (and their subdirectories) will be reloaded. + +=head2 Special "Touch" File + +You can also declare a file, which when gets C<touch(1)>ed, causes the +reloads to be performed. For example if you set: + + PerlSetVar ReloadTouchFile /tmp/reload_modules + +and don't C<touch(1)> the file I</tmp/reload_modules>, the reloads +won't happen until you go to the command line and type: + + % touch /tmp/reload_modules + +When you do that, the modules that have been changed, will be +magically reloaded on the next request. This option works with any +mode described before. + +=head2 Unregistering a module + +In some cases, it might be necessary to explicitely stop reloading +a module. + + Apache2::Reload->unregister_module('Some::Module'); + +But be carefull, since unregistering a module in this way will only +do so for the current interpreter. This feature should be used with +care. + +=head1 Performance Issues + +This module is perfectly suited for a development environment. Though +it's possible that you would like to use it in a production +environment, since with C<Apache2::Reload> you don't have to restart +the server in order to reload changed modules during software +updates. Though this convenience comes at a price: + +=over + +=item * + +If the "touch" file feature is used, C<Apache2::Reload> has to stat(2) +the touch file on each request, which adds a slight but most likely +insignificant overhead to response times. Otherwise C<Apache2::Reload> +will stat(2) each registered module or even worse--all modules in +C<%INC>, which will significantly slow everything down. + +=item * + +Once the child process reloads the modules, the memory used by these +modules is not shared with the parent process anymore. Therefore the +memory consumption may grow significantly. + +=back + +Therefore doing a full server stop and restart is probably a better +solution. + +=head1 Debug + +If you aren't sure whether the modules that are supposed to be +reloaded, are actually getting reloaded, turn the debug mode on: + + PerlSetVar ReloadDebug On + +=head1 Caveats + +=head2 Problems With Reloading Modules Which Do Not Declare Their Package Name + +If you modify modules, which don't declare their C<package>, and rely on +C<Apache2::Reload> to reload them, you may encounter problems: i.e., +it'll appear as if the module wasn't reloaded when in fact it +was. This happens because when C<Apache2::Reload> C<require()>s such a +module all the global symbols end up in the C<Apache2::Reload> +namespace! So the module does get reloaded and you see the compile +time errors if there are any, but the symbols don't get imported to +the right namespace. Therefore the old version of the code is running. + + +=head2 Failing to Find a File to Reload + +C<Apache2::Reload> uses C<%INC> to find the files on the filesystem. If +an entry for a certain filepath in C<%INC> is relative, +C<Apache2::Reload> will use C<@INC> to try to resolve that relative +path. Now remember that mod_perl freezes the value of C<@INC> at the +server startup, and you can modify it only for the duration of one +request when you need to load some module which is not in on of the +C<@INC> directories. So a module gets loaded, and registered in +C<%INC> with a relative path. Now when C<Apache2::Reload> tries to find +that module to check whether it has been modified, it can't find since +its directory is not in C<@INC>. So C<Apache2::Reload> will silently +skip that module. + +You can enable the C<Debug|/Debug> mode to see what C<Apache2::Reload> +does behind the scenes. + + + +=head2 Problems with Scripts Running with Registry Handlers that Cache the Code + +The following problem is relevant only to registry handlers that cache +the compiled script. For example it concerns +C<L<ModPerl::Registry|docs::2.0::api::ModPerl::Registry>> but not +C<L<ModPerl::PerlRun|docs::2.0::api::ModPerl::PerlRun>>. + +=head3 The Problem + +Let's say that there is a module C<My::Utils>: + + #file:My/Utils.pm + #---------------- + package My::Utils; + BEGIN { warn __PACKAGE__ , " was reloaded\n" } + use base qw(Exporter); + @EXPORT = qw(colour); + sub colour { "white" } + 1; + +And a registry script F<test.pl>: + + #file:test.pl + #------------ + use My::Utils; + print "Content-type: text/plain\n\n"; + print "the color is " . colour(); + +Assuming that the server is running in a single mode, we request the +script for the first time and we get the response: + + the color is white + +Now we change F<My/Utils.pm>: + + - sub colour { "white" } + + sub colour { "red" } + +And issue the request again. C<Apache2::Reload> does its job and we can +see that C<My::Utils> was reloaded (look in the I<error_log> +file). However the script still returns: + + the color is white + +=head3 The Explanation + +Even though F<My/Utils.pm> was reloaded, C<ModPerl::Registry>'s cached +code won't run 'C<use My::Utils;>' again (since it happens only once, +i.e. during the compile time). Therefore the script doesn't know that +the subroutine reference has been changed. + +This is easy to verify. Let's change the script to be: + + #file:test.pl + #------------ + use My::Utils; + print "Content-type: text/plain\n\n"; + my $sub_int = \&colour; + my $sub_ext = \&My::Utils::colour; + print "int $sub_int\n"; + print "ext $sub_ext\n"; + +Issue a request, you will see something similar to: + + int CODE(0x8510af8) + ext CODE(0x8510af8) + +As you can see both point to the same CODE reference (meaning that +it's the same symbol). After modifying F<My/Utils.pm> again: + + - sub colour { "red" } + + sub colour { "blue" } + +and calling the script on the secondnd time, we get: + + int CODE(0x8510af8) + ext CODE(0x851112c) + +You can see that the internal CODE reference is not the same as the +external one. + +=head3 The Solution + +There are two solutions to this problem: + +Solution 1: replace C<use()> with an explicit C<require()> + +C<import()>. + + - use My::Utils; + + require My::Utils; My::Utils->import(); + +now the changed functions will be reimported on every request. + +Solution 2: remember to touch the script itself every time you change +the module that it requires. + +=head1 Threaded MPM and Multiple Perl Interpreters + +If you use C<Apache2::Reload> with a threaded MPM and multiple Perl +interpreters, the modules will be reloaded by each interpreter as they +are used, not every interpreters at once. Similar to mod_perl 1.0 +where each child has its own Perl interpreter, the modules are +reloaded as each child is hit with a request. + +If a module is loaded at startup, the syntax tree of each subroutine +is shared between interpreters (big win), but each subroutine has its +own padlist (where lexical my variables are stored). Once +C<Apache2::Reload> reloads a module, this sharing goes away and each +Perl interpreter will have its own copy of the syntax tree for the +reloaded subroutines. + + +=head1 Pseudo-hashes + +The short summary of this is: Don't use pseudo-hashes. They are +deprecated since Perl 5.8 and are removed in 5.9. + +Use an array with constant indexes. Its faster in the general case, +its more guaranteed, and generally, it works. + +The long summary is that some work has been done to get this module +working with modules that use pseudo-hashes, but it's still broken in +the case of a single module that contains multiple packages that all +use pseudo-hashes. + +So don't do that. + + + + +=head1 Copyright + +mod_perl 2.0 and its core modules are copyrighted under +The Apache Software License, Version 2.0. + + +=head1 Authors + +Matt Sergeant, [EMAIL PROTECTED] + +Stas Bekman (porting to mod_perl 2.0) + +A few concepts borrowed from C<Stonehenge::Reload> by Randal Schwartz +and C<Apache::StatINC> (mod_perl 1.x) by Doug MacEachern and Ask +Bjoern Hansen. + +=head1 MAINTAINERS + +the mod_perl developers, [EMAIL PROTECTED] + + +=cut + Added: perl/Apache-Reload/trunk/t/conf/extra.last.conf.in URL: http://svn.apache.org/viewvc/perl/Apache-Reload/trunk/t/conf/extra.last.conf.in?rev=606234&view=auto ============================================================================== --- perl/Apache-Reload/trunk/t/conf/extra.last.conf.in (added) +++ perl/Apache-Reload/trunk/t/conf/extra.last.conf.in Fri Dec 21 08:22:23 2007 @@ -0,0 +1,21 @@ +<IfModule mod_perl.c> + <IfDefine APACHE2> + PerlModule Apache2::Reload + PerlModule Apache2::TestReload + </IfDefine> + <IfDefine APACHE1> + PerlModule Apache::Reload + PerlModule Apache::TestReload + </IfDefine> + <Location /reload> + SetHandler perl-script + <IfDefine APACHE2> + PerlInitHandler Apache2::Reload + PerlResponseHandler Apache2::TestReload + </IfDefine> + <IfDefine APACHE1> + PerlInitHandler Apache::Reload + PerlHandler Apache::TestReload + </IfDefine> + </Location> +</IfModule> Added: perl/Apache-Reload/trunk/t/lib/Apache/TestReload.pm URL: http://svn.apache.org/viewvc/perl/Apache-Reload/trunk/t/lib/Apache/TestReload.pm?rev=606234&view=auto ============================================================================== --- perl/Apache-Reload/trunk/t/lib/Apache/TestReload.pm (added) +++ perl/Apache-Reload/trunk/t/lib/Apache/TestReload.pm Fri Dec 21 08:22:23 2007 @@ -0,0 +1,44 @@ +package Apache::TestReload; + +use strict; +use warnings FATAL => 'all'; + +#use ModPerl::Util (); +use Apache::Constants qw(:common); + +my $package = 'Reload::Test'; + +our $pass = 0; + +sub handler { + my $r = shift; + $pass++; + $r->send_http_header('text/plain'); + if ((defined ($r->args)) && ($r->args eq 'last')) { + #Apache2::Reload->unregister_module($package); + #ModPerl::Util::unload_package($package); + $pass = 0; + $r->print("unregistered OK"); + return OK; + } + + eval "require $package"; + + Reload::Test::run($r); + + return OK; +} + +# This one shouldn't be touched +package Reload::Test::SubPackage; + +sub subpackage { + if ($Apache::TestReload::pass == '2') { + return 'SUBPACKAGE'; + } + else { + return 'subpackage'; + } +} + +1; Copied: perl/Apache-Reload/trunk/t/lib/Apache2/TestReload.pm (from r594783, perl/modperl/trunk/t/response/TestModules/reload.pm) URL: http://svn.apache.org/viewvc/perl/Apache-Reload/trunk/t/lib/Apache2/TestReload.pm?p2=perl/Apache-Reload/trunk/t/lib/Apache2/TestReload.pm&p1=perl/modperl/trunk/t/response/TestModules/reload.pm&r1=594783&r2=606234&rev=606234&view=diff ============================================================================== --- perl/modperl/trunk/t/response/TestModules/reload.pm (original) +++ perl/Apache-Reload/trunk/t/lib/Apache2/TestReload.pm Fri Dec 21 08:22:23 2007 @@ -1,13 +1,14 @@ -package TestModules::reload; +package Apache2::TestReload; use strict; use warnings FATAL => 'all'; use ModPerl::Util (); - +use Apache2::RequestRec (); use Apache2::Const -compile => qw(OK); +use Apache2::RequestIO (); -my $package = 'Apache2::Reload::Test'; +my $package = 'Reload::Test'; our $pass = 0; @@ -22,29 +23,23 @@ return Apache2::Const::OK; } - eval "use $package"; + eval "require $package"; - Apache2::Reload::Test::run($r); + Reload::Test::run($r); return Apache2::Const::OK; } -#This one shouldn't be touched -package Apache2::Reload::Test::SubPackage; +# This one shouldn't be touched +package Reload::Test::SubPackage; -sub subpackage { - if ($TestModules::reload::pass == '2') { - return 'subpackage'; +sub subpackage { + if ($Apache2::TestReload::pass == '2') { + return 'SUBPACKAGE'; } else { - return 'SUBPACKAGE'; + return 'subpackage'; } } 1; -__END__ - -PerlModule Apache2::Reload -PerlInitHandler Apache::TestHandler::same_interp_fixup Apache2::Reload -PerlSetVar ReloadDebug Off -PerlSetVar ReloadAll Off Copied: perl/Apache-Reload/trunk/t/reload.t (from r594783, perl/modperl/trunk/t/modules/reload.t) URL: http://svn.apache.org/viewvc/perl/Apache-Reload/trunk/t/reload.t?p2=perl/Apache-Reload/trunk/t/reload.t&p1=perl/modperl/trunk/t/modules/reload.t&r1=594783&r2=606234&rev=606234&view=diff ============================================================================== --- perl/modperl/trunk/t/modules/reload.t (original) +++ perl/Apache-Reload/trunk/t/reload.t Fri Dec 21 08:22:23 2007 @@ -4,19 +4,17 @@ use Apache::Test; use Apache::TestUtil; use Apache::TestRequest; -use File::Spec::Functions qw(catfile); +use File::Spec::Functions qw(catfile tmpdir); -use TestCommon::SameInterp; +Apache::TestRequest::user_agent(keep_alive => 1); plan tests => 3, need 'HTML::HeadParser'; -my $test_file = catfile Apache::Test::vars("serverroot"), - qw(lib Apache2 Reload Test.pm); +my $test_file = catfile qw(Reload Test.pm); -my $module = 'TestModules::reload'; -my $location = '/' . Apache::TestRequest::module2path($module); +my $location = '/reload'; -my @tests = qw(simple const prototype subpackage); +my @tests = qw(const prototype simple subpackage); my $header = join '', <DATA>; @@ -33,71 +31,34 @@ sub prototype($$) { 'PROTOTYPE' } EOF -t_write_file($test_file, $header, $initial); - -t_debug "getting the same interp ID for $location"; -my $same_interp = Apache::TestRequest::same_interp_tie($location); - -my $skip = $same_interp ? 0 : 1; +t_write_test_lib($test_file, $header, $initial); { my $expected = join '', map { "$_:$_\n" } sort @tests; - my $received = same_interp_req_body($same_interp, \&GET, - $location); - $skip++ unless defined $received; - same_interp_skip_not_found( - $skip, - $received, - $expected, - "Initial" - ); + my $received = GET $location; + ok t_cmp($received->content, $expected, 'Initial'); } -t_write_file($test_file, $header, $modified); -touch_mtime($test_file); +t_write_test_lib($test_file, $header, $modified); { my $expected = join '', map { "$_:" . uc($_) . "\n" } sort @tests; - my $received = same_interp_req_body($same_interp, \&GET, - $location); - $skip++ unless defined $received; - same_interp_skip_not_found( - $skip, - $received, - $expected, - "Reload" - ); + my $received = GET $location; + ok t_cmp($received->content, $expected, 'Reload'); } { my $expected = "unregistered OK"; - my $received = same_interp_req_body($same_interp, \&GET, - $location . '?last' ); - $skip++ unless defined $received; - same_interp_skip_not_found( - $skip, - $received, - $expected, - "Unregister" - ); -} - -sub touch_mtime { - my $file = shift; - # push the mtime into the future (at least 2 secs to work on win32) - # so Apache2::Reload will reload the package - my $time = time + 5; # make it 5 to be sure - utime $time, $time, $file; + my $received = GET "$location?last"; + ok t_cmp($received->content, $expected, 'Unregister'); } __DATA__ -package Apache2::Reload::Test; - -use Apache2::Reload; +package Reload::Test; -our @methods = qw(simple const prototype subpackage); +our @methods = qw(const prototype simple subpackage); -sub subpackage { return Apache2::Reload::Test::SubPackage::subpackage() } +sub subpackage { return Reload::Test::SubPackage::subpackage() } sub run { my $r = shift; @@ -105,3 +66,5 @@ $r->print($m, ':', __PACKAGE__->$m(), "\n"); } } + +1;