http://qs321.pair.com?node_id=11123179

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

New to perl modules, I have the issue where, my perl script calls in a perl module. I get one of three responses when I load that script: 1. error 500 page 2. error Undefined subroutine called 3. the correct output, though lately that isn't happening at all :( The resultant pages seem to rotate between the three (above) and my ISP assured my last week, they had disabled caching, which at that time was identified as the cause. What else could be stopping this module from working? here's the calling script: login.pl
#!/usr/bin/perl -w use strict; use warnings; use CGI; use Data::Dumper; my $cgi = new CGI; BEGIN{ unshift @INC, "/var/www/vhosts/myDomain.com/secured.myDomain.com +/cgi-bin/library"; } print $cgi->header; use doctypeAndHeader; header();
And, here's the module called doctypeAndHeader.pm
package doctypeAndHeader; use strict; use warnings; use Exporter; use vars qw(@ISA @EXPORT); @ISA = qw(Exporter); @EXPORT = ("header"); sub header{ my $doctypeAndHeader = ''; $doctypeAndHeader = getDoctypeAndHeader(); print qq($doctypeAndHeader); } sub getDoctypeAndHeader{ # configs my $pageTitle = 'Bangor Town Centre'; #my $scriptUrl = $ENV{"SCRIPT_NAME"}; #my @scriptNameArray = split( '/' , $script_url); #my $scriptName = $scriptNameArray[-1]; my $doctypeAndHeader = "<!doctype html> <html> <head> <title>$pageTitle</title> </head> <body></body> </html>"; return $doctypeAndHeader; } 1;

Replies are listed 'Best First'.
Re: Why server error out with module
by pryrt (Abbot) on Oct 26, 2020 at 15:38 UTC
    Adding use CGI::Carp qw(fatalsToBrowser); during debug can help (especially if hippo's suggestion of searching ISP error logs isn't convenient).

    And, in the BEGIN block, you might want to log some of the CGI header variables from %ENV, like $ENV{SERVER_ADDR}, possibly to your own logfile or to STDERR, or move your $cgi->header print so that it's in the BEGIN before the unshift -- it might indicate that your ISP has a round-robin of servers where one or more servers aren't behaving identically to the others, or some such. By putting it as early as possible (in BEGIN blocks, before local libraries are used), you increase the chances that your debug code will be printed somewhere you can read it before the script crashes.

    http://www.cgi101.com/book/ch3/text.html lists other interesting environment variables, and a way to dump all of the %ENV... SERVER_ADDR isn't in their list, but it's available on my shared hosting system.


    edits: fix typos and links
Re: Why server error out with module
by hippo (Bishop) on Oct 26, 2020 at 14:27 UTC
    3. the correct output, though lately that isn't happening at all :(

    Your script and module don't produce any output that would be rendered in an HTML page.. See replies - this is not the case.

    1. error 500 page

    When that happens, consult the error log on the server to determine the cause.

    FWIW, my money is still on something odd your hoster is doing.


    🦛

      Do you mean this wouldn't be rendered? It is outputted sometimes, between either a 500 page or a software error message regarding failing to find a sub routine.
      <!doctype html> <html> <head> <title>$pageTitle</title> </head> <body></body> </html>

        My mistake - you are quite right. I had missed the print qq($doctypeAndHeader); line. You don't need to quote a single variable when you print it like that, BTW. print $doctypeAndHeader; will do just as well and might be less confusing.

        So, you should be seeing this on each call. If not, check the webserver error log for the reasons. Good luck!


        🦛

Re: Why server error out with module
by Anonymous Monk on Oct 27, 2020 at 00:28 UTC

    Hi

    What webserver tech are you using?