Better reload: first unload everything that changed, then load everything

hinted-selects
Vitaliy Filippov 2014-10-24 13:45:19 +04:00
parent dc09a5645f
commit 44a221fb48
2 changed files with 24 additions and 12 deletions

View File

@ -355,6 +355,7 @@ my $STATS;
sub reload
{
my ($file, $mtime);
my @reload;
for my $key (keys %INC)
{
$file = $INC{$key} or next;
@ -367,16 +368,21 @@ sub reload
# Modified
if ($mtime > $STATS->{$file})
{
print STDERR __PACKAGE__ . ": $key -> $file modified, reloading\n";
print STDERR __PACKAGE__ . ": $key -> $file modified, unloading\n";
unload($key) or next;
eval { require $key };
if ($@)
{
warn $@;
}
push @reload, $key;
$STATS->{$file} = $mtime;
}
}
for (@reload)
{
print STDERR __PACKAGE__ . ": Reloading $_\n";
eval { require $_ };
if ($@)
{
warn $@;
}
}
}
sub unload

View File

@ -149,6 +149,7 @@ my $STATS;
sub reload
{
my ($file, $mtime);
my @reload;
for my $key (keys %INC)
{
$file = $INC{$key} or next;
@ -161,16 +162,21 @@ sub reload
# Modified
if ($mtime > $STATS->{$file})
{
print STDERR __PACKAGE__ . ": $key -> $file modified, reloading\n";
print STDERR __PACKAGE__ . ": $key -> $file modified, unloading\n";
unload($key) or next;
eval { require $key };
if ($@)
{
warn $@;
}
push @reload, $key;
$STATS->{$file} = $mtime;
}
}
for (@reload)
{
print STDERR __PACKAGE__ . ": Reloading $_\n";
eval { require $_ };
if ($@)
{
warn $@;
}
}
}
sub unload