in reply to Re: Constants imported from other perl scripts doesn't want to exist :(
in thread Constants imported from other perl scripts doesn't want to exist :(

I changed it but it didn't make any difference.
  • Comment on Re^2: Constants imported from other perl scripts doesn't want to exist :(

Replies are listed 'Best First'.
Re^3: Constants imported from other perl scripts doesn't want to exist :(
by borisz (Canon) on Sep 17, 2005 at 19:05 UTC
    I'm sure, you have a typo somewhere. This should work.
    use strict; eval 'use constant SOMETHING => "asdf"' unless(defined(&SOMETHING)); 1;
    Boris
      No I haven't. Here's the actual .config_defaults.pl:
      #!/usr/bin/perl use strict; eval 'use constant NAME_MAXLENGTH => 30' unless(defined(&NAME_MAXLENGT +H)); eval 'use constant LINK_MAXLENGTH => 256' unless(defined(&LINK_MAXLENG +TH)); eval 'use constant SUBJECT_MAXLENGTH => 256' unless(defined(&SUBJECT_M +AXLENGTH)); eval 'use constant POST_MAXLENGTH => 8192' unless(defined(&POST_MAXLEN +GTH)); 1;
      require() related:
      my $dir = dirname($ENV{"SCRIPT_FILENAME"})."/"; require("$dir.config_defaults.pl");
      Code snippet where the first error occurs (if it's commented, the next constant gets error'd):
      &error("Subject is too long/empty.") if (length $$subject > &SUBJECT_M +AXLENGTH || ($$subject eq "" && $mode eq "post"));
      The error message:
      [error] -e: Undefined subroutine &ModPerl::ROOT::ModPerl::Registry::[v +ery long fullpath]post_2epl::SUBJECT_MAXLENGTH called at (eval 50) li +ne 195.\n
        It just works. If it does not in your setup the error is mod_perl related. Try another handler. I would start with ModPerl::PerlRun.
        Boris

        If you are requiring the module in a BEGIN block in a mod_perl environment, then your BEGIN block may not be compiled/runned in every request (ie. when your script run).

        Check the docs in http://perl.apache.org, especially the BEGIN blocks part in the porting section of the guide (this is from the mod_perl 1 guide, but I don't think this changed in mod_perl 2).

        Using mod_perl could be triky if you came from CGI (I was bitted by some differences of running under Apache::Registry vs. CGI recently). The main difference is that the compilation of your script is done only once, and BEGIN blocks AFAIK, are only called at compile time and then discarded.

        If you are comming from CGI as me, I strongly recommend to read the full porting section of the mod_perl guide, it will save you a lot of troubles. Also reading the Perl Reference in the mod_perl documentation may be usefull (I know it was for me ;),

        Also note the difference between require vs. use. require's work at runtime and use's at compile time. Putting a require module; inside a BEGIN block is like doing use module (); (so it don't import any symbol into your main namespace).

        Seeing what you are doing, I think you may want the code on your config.pl to be executed at runtime, so just remove the BEGIN { } construct around your require and it should work. If you do this, make sure the configuration file is in a path in you @INC or your script will die by not finding it.

        So, as borisz suggest, this is more a mod_perl issue, you may consider editting your node title to reflect it, so monks with more knowledge in mod_perl can see it, and help you.

        HTH, God bless you
        rruiz