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

Hi,

I have some cgi scripts that run without errors when I do not have mod_perl2 installed on apache22.

Three scripts are involved: template_editor_a.cgi template_editor_b.cgi editor.cgi, containing shared functions

I put template_editor_a.cgi in package A; template_editor_b in package B; editor.cgi in pacakge C.

I am calling C::build(\@data, $rec) from package A and from package B.

If I restart the webserver and execute template_editor_a.cgi, the call is fine, and my form shows.

If I execute template_editor_b.cgi, I get an error on C::build sayiing 'Type of arg1 to C::build must be array (not reference constructor) at line X of template_editor_b.cgi.

If I now restart the web server, executing template_editor_b.cgi works fine, but when I execute template_editor_a.cgi, I now get 'Type of arg1 to C::build must be array (not reference constructor) at line Y of template_editor_a.cgi.

I can post the code, but here's the pertinent bits (I hope). Any ideas what's happening? The actual error message is posted at the end many thanks, -jeff

package A; use strict; … my @array1 = qw(name display file recur msglist); my $rec = new WDDX; … my $listrec = C::build(\@array1, $rec); --- package B; use strict; … my @array2 = qw(name display file recur msglist); my $rec = new WDDX; … my $listrec = C::build(\@array2, $rec); … package C; sub build(\@$); sub build(\@$) { my $data = $_[0]; my $rec = $_[1]; … }
Sat Jan 07 03:50:18 2012 error Type of arg 1 to C::build must be array (not reference constructor) at /www/localhost/cgi-bin/template_editor_a.cgi line 67, near "$wddx) "\n

Replies are listed 'Best First'.
Re: mod_perl2 seems to affect subsequent calls to shared script
by CountZero (Bishop) on Jan 07, 2012 at 19:29 UTC
    Why are you using prototypes in your subroutine definition? I am quite sure it is not doing what you --wrongly-- think it should do.

    Actually the \@ prototype causes the subroutine to accept an array only!

    Drop those prototypes, they serve no purpose here.

    CountZero

    A program should be light and agile, its subroutines connected like a string of pearls. The spirit and intent of the program should be retained throughout. There should be neither too little or too much, neither needless loops nor useless variables, neither lack of structure nor overwhelming rigidity." - The Tao of Programming, 4.1 - Geoffrey James

      okay, I'm happy to eat crow - went back to what was working outside of the mod_perl2 environment, removed all the prototypes, and restarted apache, and all versions of the template editor run without problems. thanks
      I'll dump 'em permanently, had removed them in various iterations to no (functional) improvement, but went back to what I'd started with after too many changes. thanks for the feedback -jeff