RE: Making a module-It can't be this hard.
Hi there, On Sat, 26 Oct 2002, Per Einar Ellefsen wrote: > At 00:01 26.10.2002, Robert Covell wrote: > > > >The modules I have declared do contain a package name. > > > >Is it not possible or easy to just use/require/include a pl or pm file that > >contains a set of function for me to reuse. Also: have you tried running httpd -X? See the mod_perl Guide (you'll find a link on the mod_perl home page http://perl.apache.org) 73, Ged.
RE: Making a module-It can't be this hard.
At 00:01 26.10.2002, Robert Covell wrote: I have read that link you provided, thanks. The modules I have declared do contain a package name. Is it not possible or easy to just use/require/include a pl or pm file that contains a set of function for me to reuse. Is this a valid pm and pl file? package Test; sub DisplaySection { print $_[0]; } 1; and in my pl file(without the other stuff to make it run): use Test; &DisplaySection("Test12"); Some comments: - Don't use the name Test. It's a module already provided with the perl distribution, and there will therefore be subtle conflicts. - I don't see how the above code could work in any case: you declare the subroutine in the package Test, and then you call it in the package used for the registry script. Unless you define another subroutine DisplaySection in that package, there is no way for Perl to find the correct subroutine. The correct thing would be: package My::DisplayModule; ... same as before ... 1; and in the script: use My::DisplayModule; My::DisplayModule::DisplaySection("Test12"); This is of course only one of many ways of doing it. I would suggest reading up on general Perl documentation regarding modules and package, such as perlmod, perlmodlib, perlboot, perltoot, perltooc, perlbot ... Just read on :) But you really need to learn this to work correctly with Perl, and especially with mod_perl. As Perrin also mentioned, there are some subtleties with the way packages work under mod_perl that are explained in the 1.0 user's guide. -Original Message- From: Perrin Harkins [mailto:perrin@;elem.com] It sounds like you are using perl4-style libs that don't declare a package name. You can find a description of the problem and some solutions here: http://perl.apache.org/docs/1.0/guide/porting.html#Name_collisions_with_Modu les_and_libs The basic fix is to give your modules unique package names. See the perlmod man page for more on package names. -- Per Einar Ellefsen [EMAIL PROTECTED]
RE: Making a module-It can't be this hard.
I have read that link you provided, thanks. The modules I have declared do contain a package name. Is it not possible or easy to just use/require/include a pl or pm file that contains a set of function for me to reuse. Is this a valid pm and pl file? package Test; sub DisplaySection { print $_[0]; } 1; and in my pl file(without the other stuff to make it run): use Test; &DisplaySection("Test12"); -Original Message- From: Perrin Harkins [mailto:perrin@;elem.com] Sent: Friday, October 25, 2002 4:10 PM To: [EMAIL PROTECTED] Cc: [EMAIL PROTECTED] Subject: Re: Making a module-It can't be this hard. Robert Covell wrote: > I simply want to make a module so I can reuse a common header instead of > manually changing each page. Under mod-perl how do you simply create a > module that I can use/require/include that I can call a subroutine/function > to generate some html based on the page you are on. > > It works 5 out of 10 times. When it fails I get: > > [Fri Oct 25 14:24:05 2002] [error] Undefined subroutine > &Apache::ROOTvirusmailcenter_2erolet_2ecom::index_2epl::DisplaySection > called at /mnt/data1/www/htdocsM/mailcenter/index.pl line 410. It sounds like you are using perl4-style libs that don't declare a package name. You can find a description of the problem and some solutions here: http://perl.apache.org/docs/1.0/guide/porting.html#Name_collisions_with_Modu les_and_libs The basic fix is to give your modules unique package names. See the perlmod man page for more on package names. - Perrin
Re: Making a module-It can't be this hard.
Robert Covell wrote: I simply want to make a module so I can reuse a common header instead of manually changing each page. Under mod-perl how do you simply create a module that I can use/require/include that I can call a subroutine/function to generate some html based on the page you are on. It works 5 out of 10 times. When it fails I get: [Fri Oct 25 14:24:05 2002] [error] Undefined subroutine &Apache::ROOTvirusmailcenter_2erolet_2ecom::index_2epl::DisplaySection called at /mnt/data1/www/htdocsM/mailcenter/index.pl line 410. It sounds like you are using perl4-style libs that don't declare a package name. You can find a description of the problem and some solutions here: http://perl.apache.org/docs/1.0/guide/porting.html#Name_collisions_with_Modules_and_libs The basic fix is to give your modules unique package names. See the perlmod man page for more on package names. - Perrin