You are viewing a plain text version of this content. The canonical link for it is here.
Posted to modperl@perl.apache.org by Tim Edwards <mo...@hotmail.com> on 2003/08/28 22:09:24 UTC

Modules Problem

I in the process of switching my scripts over to Mod Perl.

I decide since Mod Perl doesn't like Sub routine in the the main program I'd 
export make Modules out of the more come ones. Simple process I thought. 
However no mater what I do I get an error. I tried making a simple one using 
the example code from the site and failed stil.

Error:

Undefined subroutine &main::CISCHeader called at /var/www/perl/test.pl line 
5.

Here the Module Located in the ModPerl Directory under the a directory 
listed int eh @inc:

package ModPerl::Rules1;

sub CISCHeader {
   print "Content-type: text/plain\n\n";
   print "mod_perl rules!\n";
   return 1;
}
1;

The Script:

#!/usr/bin/perl -w
use strict;
use ModPerl::Rules1;

CISCHeader();

I'm Stumpped and would love some advise or suggestions.

_________________________________________________________________
Enter for your chance to IM with Bon Jovi, Seal, Bow Wow, or Mary J Blige 
using MSN Messenger http://entertainment.msn.com/imastar



-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html


Re: Modules Problem

Posted by Perrin Harkins <pe...@elem.com>.
On Thu, 2003-08-28 at 16:09, Tim Edwards wrote:
> I in the process of switching my scripts over to Mod Perl.
> 
> I decide since Mod Perl doesn't like Sub routine in the the main program I'd 
> export make Modules out of the more come ones.

Just to be clear, mod_perl has no problem with subroutines inside of the
main program.  Apache::Registry has issues with it but only if you are
using lexically scoped variables and declaring them outside of your subs
rather than passing all parameters to the subs.

In other words, don't do this with Apache::Registry:

my $cgi = CGI->new();

foo();

sub foo {
    my $input = $cgi->param('input');
}

That breaks because $cgi is not passed to foo(), so it becomes a closure
and will always be the same as it was the first time the script was run.

> Error:
> 
> Undefined subroutine &main::CISCHeader called at /var/www/perl/test.pl line 
> 5.
> 
> Here the Module Located in the ModPerl Directory under the a directory 
> listed int eh @inc:
> 
> package ModPerl::Rules1;
> 
> sub CISCHeader {
>    print "Content-type: text/plain\n\n";
>    print "mod_perl rules!\n";
>    return 1;
> }
> 1;
> 
> The Script:
> 
> #!/usr/bin/perl -w
> use strict;
> use ModPerl::Rules1;
> 
> CISCHeader();

Your module doesn't export the CISCHeader sub, so you have to call it
with the full name: ModPerl::Rules1::CISCHeader().  If this doesn't make
sense to you, you should read the "perlmod" man page that explains how
modules and packages work.

- Perrin


-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html


Re: Modules Problem

Posted by Bruce Tennant <bl...@yahoo.com>.
You need to setup exports in your Rules1 package.
 
Take a look at Exporter. (perldoc Exporter)
 
OR, call the function with its fully qualified package name

Tim Edwards <mo...@hotmail.com> wrote:
I in the process of switching my scripts over to Mod Perl.

I decide since Mod Perl doesn't like Sub routine in the the main program I'd 
export make Modules out of the more come ones. Simple process I thought. 
However no mater what I do I get an error. I tried making a simple one using 
the example code from the site and failed stil.

Error:

Undefined subroutine &main::CISCHeader called at /var/www/perl/test.pl line 
5.

Here the Module Located in the ModPerl Directory under the a directory 
listed int eh @inc:

package ModPerl::Rules1;

sub CISCHeader {
print "Content-type: text/plain\n\n";
print "mod_perl rules!\n";
return 1;
}
1;

The Script:

#!/usr/bin/perl -w
use strict;
use ModPerl::Rules1;

CISCHeader();

I'm Stumpped and would love some advise or suggestions.

_________________________________________________________________
Enter for your chance to IM with Bon Jovi, Seal, Bow Wow, or Mary J Blige 
using MSN Messenger http://entertainment.msn.com/imastar



-- 
Reporting bugs: http://perl.apache.org/bugs/
Mail list info: http://perl.apache.org/maillist/modperl.html


www.bluewolverine.com

---------------------------------
Do you Yahoo!?
Yahoo! SiteBuilder - Free, easy-to-use web site design software