| 1 |
use strict; |
|---|
| 2 |
package Module::Reload; |
|---|
| 3 |
use vars qw($VERSION $Debug %Stat); |
|---|
| 4 |
$VERSION = "1.07"; |
|---|
| 5 |
|
|---|
| 6 |
sub check { |
|---|
| 7 |
my $c=0; |
|---|
| 8 |
while (my($key,$file) = each %INC) { |
|---|
| 9 |
next if $file eq $INC{"Module/Reload.pm"}; |
|---|
| 10 |
local $^W = 0; |
|---|
| 11 |
my $mtime = (stat $file)[9]; |
|---|
| 12 |
$Stat{$file} = $^T |
|---|
| 13 |
unless defined $Stat{$file}; |
|---|
| 14 |
warn "Module::Reload: stat '$file' got $mtime >? $Stat{$file}\n" |
|---|
| 15 |
if $Debug >= 3; |
|---|
| 16 |
if ($mtime > $Stat{$file}) { |
|---|
| 17 |
delete $INC{$key}; |
|---|
| 18 |
eval { |
|---|
| 19 |
local $SIG{__WARN__} = \&warn; |
|---|
| 20 |
require $key; |
|---|
| 21 |
}; |
|---|
| 22 |
if ($@) { |
|---|
| 23 |
warn "Module::Reload: error during reload of '$key': $@\n" |
|---|
| 24 |
} |
|---|
| 25 |
elsif ($Debug) { |
|---|
| 26 |
warn "Module::Reload: process $$ reloaded '$key'\n" |
|---|
| 27 |
if $Debug == 1; |
|---|
| 28 |
warn("Module::Reload: process $$ reloaded '$key' (\@INC=". |
|---|
| 29 |
join(', ',@INC).")\n") |
|---|
| 30 |
if $Debug >= 2; |
|---|
| 31 |
} |
|---|
| 32 |
++$c; |
|---|
| 33 |
} |
|---|
| 34 |
$Stat{$file} = $mtime; |
|---|
| 35 |
} |
|---|
| 36 |
$c; |
|---|
| 37 |
} |
|---|
| 38 |
|
|---|
| 39 |
1; |
|---|
| 40 |
|
|---|
| 41 |
__END__ |
|---|
| 42 |
|
|---|
| 43 |
=head1 NAME |
|---|
| 44 |
|
|---|
| 45 |
Module::Reload - Reload %INC files when updated on disk |
|---|
| 46 |
|
|---|
| 47 |
=head1 SYNOPSIS |
|---|
| 48 |
|
|---|
| 49 |
Module::Reload->check; |
|---|
| 50 |
|
|---|
| 51 |
=head1 DESCRIPTION |
|---|
| 52 |
|
|---|
| 53 |
When Perl pulls a file via C<require>, it stores the filename in the |
|---|
| 54 |
global hash C<%INC>. The next time Perl tries to C<require> the same |
|---|
| 55 |
file, it sees the file in C<%INC> and does not reload from disk. This |
|---|
| 56 |
module's handler iterates over C<%INC> and reloads the file if it has |
|---|
| 57 |
changed on disk. |
|---|
| 58 |
|
|---|
| 59 |
Set $Module::Reload::Debug to enable debugging output. |
|---|
| 60 |
|
|---|
| 61 |
=head1 BUGS |
|---|
| 62 |
|
|---|
| 63 |
A growing number of pragmas (C<base>, C<fields>, etc.) assume that |
|---|
| 64 |
they are loaded once only. When you reload the same file again, they |
|---|
| 65 |
tend to become confused and break. If you feel motivated to submit |
|---|
| 66 |
patches for these problems, I would encourage that. |
|---|
| 67 |
|
|---|
| 68 |
=head1 SEE ALSO |
|---|
| 69 |
|
|---|
| 70 |
Event |
|---|
| 71 |
|
|---|
| 72 |
=head1 AUTHOR |
|---|
| 73 |
|
|---|
| 74 |
Copyright � 1997-1998 Doug MacEachern & Joshua Pritikin. All rights reserved. |
|---|
| 75 |
|
|---|
| 76 |
This package is free software and is provided "as is" without express |
|---|
| 77 |
or implied warranty. It may be used, redistributed and/or modified |
|---|
| 78 |
under the terms of the Perl Artistic License (see |
|---|
| 79 |
http://www.perl.com/perl/misc/Artistic.html) |
|---|
| 80 |
|
|---|