glwtta has asked for the wisdom of the Perl Monks concerning the following question:

Greetings Monks,

I am having a problem with Apache::Reload, which is really more of an annoyance, but nonetheless:

I've written a couple of classes to encapsulate some configuration and path information, they inherit from a class that's declared roughly like this:

use base qw(Class::Accessor Class::Fields); use fields qw(id dir_base url_base dir_tmp conf); __PACKAGE__->mk_accessors(__PACKAGE__->show_fields('Public'));

The inheriting class would be along the lines of:

use base qw(My::Abstract::Class); use fields qw(dir blast_input blast_output t_result_thumb t_result_ima +ge t_region_thumb t_mview t_mview_thumb t_parsed_result); use fields qw(temp_out temp_in); use fields qw(url blast_output_url t_result_thumb_url t_result_image_u +rl t_region_thumb_url t_mview_thumb_url); __PACKAGE__->mk_accessors(__PACKAGE__->show_fields('Public'));

The actual problem is similar to the old "function redefined" warnings when running under Apache::Reload - it occurs when the module changes (ie A::R has to recompile it), and doesn't appear in production when running without A::R.

The difference is that rather than a simple warning I get

Field name 'temp_out' already in use at /usr/lib/perl5/5.6.1/fields.pm + line 34 BEGIN failed--compilation aborted at My::Config::Thing line 14. Compilation failed in require at /usr/lib/perl5/site_perl/5.6.1/Apache +/Reload.pm line 132.

So, two questions:
1. This goes away without Reload.pm, so I am guessing it's not really a problem? But it is annoying because I am back to restarting apache after every change - is there a way to get around this?
2. Why 'temp_out'? I would expect it to choke on the first field that's declared. Any ideas?

Replies are listed 'Best First'.
Re: mod_perl, Apache::Reload and Class::Fields
by perrin (Chancellor) on Jul 17, 2003 at 18:15 UTC
    This kind of reloading trick (i.e. deleting a module from %INC and then requiring it again) is not foolproof and some modules just don't work with it. It looks like fields.pm doesn't like being run twice. You could add some code to clear %FIELDS in a BEGIN block, but that's pretty ugly. You could also tell Apache::Reload not to reload the modules you have that use fields.pm, but that could be a lot.
Re: mod_perl, Apache::Reload and Class::Fields
by mod_alex (Beadle) on Jul 18, 2003 at 06:24 UTC
    I strongly suggest you to reload httpd server in case of these warnings