Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations strongm on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

How to Load a custom-written perl module 2

Status
Not open for further replies.

olivetreetech

Programmer
Dec 15, 2004
8
US
I wrote a perl module and got it working in a test environment a few months ago. Now I'm trying to get it working in production and I'm getting the following error:

error: Can't locate object method "new" via package "RT::SelectAffiliate" (perhaps you forgot to load "RT::SelectAffiliate"?) at /usr/local/rt2/WebRT/html/Elements/SelectAffiliate line 29, <GEN22> line 29.

context: ...
25: %}
26: </SELECT>
27:
28: <%INIT>
29: my $sa=new RT::SelectAffiliate ($session{'CurrentUser'});
30: $sa->UnLimit;
31: </%INIT>
32:
33: <%ARGS>
...

code stack:
/usr/local/rt2/WebRT/html/Elements/SelectAffiliate:29
/usr/local/rt2/WebRT/html/Search/PickRestriction:18
/usr/local/rt2/WebRT/html/Search/Listing.html:106
/usr/local/rt2/WebRT/html/autohandler:60

Do I somehow have to load the module in my production environment before I can use it?

I faintly remember doing something like this, but I've googled a ton and can't find how I did it.

Thanks.
 
There's no reason why it shouldn't work so long as you've placed it in a known library and defined it's use at the beginning of the script. i.e.
Code:
use lib "/tmp/weburl/LIB";
use RT::SelectAffiliate;

Rob Waite
 
I've added my module SelectAffiliate.pm to the /usr/local/rt2/lib/RT directory (which is where all the other custom perl modules are). Do I have to do something more than this for Perl to know it is available to use?

Here is the entire script where the error is being thrown (but only in production not the test environment)

Code:
<%PERL>

my $dbh = DBI->connect("DBI:mysql:rt2:localhost", "username", "password", {PrintError=> 0, RaiseError=>1}) or die print "No DB connect: ", $!;

if ($module eq "Users" and $id ne "new"){
	$SelectAffiliate::sth= $dbh->prepare("Select SupportAffiliation from Users where id=$id");}
elsif ($module eq "Groups" and $id ne ""){
	$SelectAffiliate::sth= $dbh->prepare("Select SupportAffiliation from Groups where id=$id");}
else{
	$SelectAffiliate::sth =  $dbh->prepare("select '0' from SupportAffiliation");}

$SelectAffiliate::sth->execute;
while (my $hit = $SelectAffiliate::sth->fetchrow_hashref()){
  $SelectAffiliate::curAffiliate =  $hit->{SupportAffiliation};
 }
$SelectAffiliate::sth->finish;
$dbh->disconnect;
</%PERL>

<SELECT NAME="<%$Name%>">
<OPTION VALUE=""></OPTION>
% while (my $affiliate=$sa->Next) {
<OPTION VALUE="<%$affiliate->Name%>" <%($affiliate->Name eq $SelectAffiliate::curAffiliate) && 'SELECTED'%> >
<%$affiliate->Name%></OPTION>
%}
</SELECT>

<%INIT>
my $sa=new RT::SelectAffiliate ($session{'CurrentUser'});
$sa->UnLimit;
</%INIT>

<%ARGS>
$Name => undef
$id => undef
$module => undef
</%ARGS>
 
Code:
use lib " /usr/local/rt2/lib/RT";
at the top of your script that's calling the module
--Paul


cigless ...
 
I have this exact code working in a test environment with no "use" statement. Can you explain how this could be possible?
 
The location you have the module stored in the test environment is included in the path that perl searches for modules

the line above is basically saying

Code:
as well as everywhere else you know to look, also check out this location

the use lib directive is a shortcut rather than having to define a full install pack for your module which would add your module to a perl accessible directory which would no longer need the use lib directive

Hope that makes sense
--Paul


cigless ...
 
Isn't there an easy way to add the module to the perl accessible directory? Via the command shell?
 
use lib is what I've gotten away with for a good while. And I found that out here
--Paul

cigless ...
 
I tried everything suggested above and the solution finally came about by using:

use lib "/tmp/weburl/LIB";
use RT::SelectAffiliate;

Thanks for the help!
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top