in reply to Reloading changed modules

Apache::Reload module seems to apply the same technique. Here a snippet:
if ($mtime > $Stat{$file}) { delete $INC{$key}; # warn "Reloading $key\n"; if (my $symref = $UndefFields{$key}) { # warn "undeffing fields\n"; no strict 'refs'; undef %{$symref}; } require $key; warn("Apache::Reload: process $$ reloading $key\n") if $DEBUG; } $Stat{$file} = $mtime;
The same technique, except that it copes with your "${package}::FIELDS" (which $symref in the snippet above is a reference to).

For further info about %FIELDS, you can check the fields pragma man page (but check 5.8.0 perldelta about the deprecation of 5.6.1 pseudohashes' "user visible" implementation).

Update: Clarified final note.

Replies are listed 'Best First'.
Re: Re: Reloading changed modules
by castaway (Parson) on Dec 21, 2002 at 17:41 UTC
    Thanks, I'll take a look.
    I should have tested better before, it seems my eval "no warnings; require $modname"; does not suppress the 'Subroutine redefined' warnings, any idea why?
    Casty
      The module doesn't have 'use warnings;' in it does it? I've used the exact same technique to reload modules except for backwards compatibility I used 'local($^W) = 0;' to supress 'Subroutine redefined'.
        Your local($^W) = 0; does not work for me, I get 'Can't modify constant item in local ..'
        Using use warnings; at the top and then:
        no warnings; eval "require $modname"; use warnings;
        Still produces the warnings :(
        C.
        No it doesn't, but it has #!/usr/bin/perl -w at the top..
        Casty