perl TemplateToolkit - Can't locate object method "new" via package - perl

I have inherited a web project that is perl based and I'm attempting to set up a local testing server so changes can be made internally to the project.
The server architecture
Ubuntu 9.10
php 5.2.10
mysql 5.1.37
perl 5.10.0-24ubuntu4
All the dependent modules and packages are installed such as DateTime.pm, TemplateToolkit.pm but running the application throws the following error message:
Can't locate object method "new" via package "Template" (perhaps you forgot to load "Template"?) at ../lib//KPS/TemplateToolkit.pm line 51
The code block that this refers to is:
sub new {
return Template->new(
INCLUDE_PATH => $KPS::Config::templatepath,
ABSOLUTE => 1,
DEBUG => 1,
);
}
If anybody is able to shed any light on this or point me in the right direction it would be greatly appreciated.
Thanks
Simnom

You need to load Template Toolkit first, with:
use Template;
To make sure that Template::Toolkit is properly installed on this system, from a console you could run:
perl -MTemplate -e0
If it returns without an error, it means Template.pm wsa loaded succesfully; if not, it will give you an error of "Can't locate Template.pm in #INC...".

An additional thing to check because the accepted answer test could be successful even if you are not setup correctly; make sure that the package declaration in the module has the correct path. The scenario is as follows:
You do
use a::b;
...
a::b->new();
and then in b.pm you do
package b;
You may be banging your head for a while until you realize that you need to do
package a::b;

Related

Perl Par::Packer Can't find module issue

I have a perl program that uses WWW::Mechanize::Firefox on windows 7 32bit with strawberry perl.
It works fine with the command C:\>perl testcase.pl. When I compile it with C:\>pp -o testcase.exe testcase.pl it compiles with no errors.
When I run the testcase.exe it gives me the error:
Failed to connect to , Can't locate object method "setup" via package "MozRepl::Client" at MozRepl.pm line 224
The code I am using for testcase.pl is:
#!perl
use MozRepl;
use WWW::Mechanize::Firefox;
use warnings;
system('start firefox');
sleep(5);
$mech = WWW::Mechanize::Firefox->new;
Also note that a program without WWW::Mechanize::Firefox and MozRepl does work fine.
The problem has obviously been narrowed down to PAR::Packer not liking MozRepl, any idea what it might be?
PAR::Packer sometimes has a hard time identifying which modules need to be included in a PAR package in order to fulfill all of the requirements of the program you are trying to package.
It copes OK if the dependancies are loaded via plain 'use', or 'require' statements where the module to be loaded is a literal string, but it won't have much chance if the module is being loaded dynamically with something like:
require $myModuleToLoad;
Browsing the source code of MozRepl and related modules shows that they make heavy use of plugins loaded dynamically. I suspect that some of these are not being packaged.
You can manually specify module(s) to be included in the PAR package by adding -M Module::Name to the pp command line for each of the modules to be added (replacing Module::Name with the actual module name of course).
The hard part might be identifying which modules to include. One way to do this is to temporarily add something like this to the end of your script:
END { print "$_ -> $INC{$_}\n" foreach sort keys %INC; }
then run your script normally, not through PAR. It should list all the modules that were loaded. You can compare that with the actual modules present in the PAR package and add the missing ones using the -M option to pp.
You can see the modules inside your PAR file by opening it with an unzipping tool, such as 7zip. Or in Linux:
unzip -l {parfile}

Perl undefined yp_get_default_domain detected by DynaLoader.pm when using ARSperl, yet library exists

I have a Ubuntu server that recently pushed a Perl update to 5.14.2 when I installed cpanminus. This broke compatibility with the BMC Remedy API module. It looks like I can't roll back to the old version of Perl, so I've tried recompiling ARSperl for Perl 5.14.2.
The problem is, when I run an old Perl script that used the old module, I get the following:
Can't load '/usr/local/lib/perl5/5.14.2/auto/ARS/ARS.so' for module ARS:
/usr/local/lib/perl5/5.14.2/auto/ARS/ARS.so: undefined symbol:
yp_get_default_domain at /usr/local/lib/perl5/5.14.2/i686-linux/DynaLoader.pm line 190.
So, a bit of Googling tells me that yp_get_default_domain lives in libnsl. I've gone so far as to try recompiling both the ARSperl module and Perl itself with "-lnsl" explicitly called out in the Makefile. Unfortunately, this has gotten me nowhere. The library is indeed installed on the system under /usr/lib/i386-linux-gnu/.
In ARSperl Makefile:
LDFLAGS = -fstack-protector -L/usr/local/lib -L/usr/lib -L/usr/lib/i386-linux-gnu -lnsl
My question is therefore two-fold for the Perl gurus out there.
-How can I determine which of Perl, DynaLoader, or the ARS.so itself can't find "yp_get_default_domain"?
-What is the best next step to troubleshoot the above DynaLoader message for a missing library that is actually present on the system and linked in the module?
Thank you in advance for sharing your knowledge and advice.
Add the directory where library is installed to the $ARS_LDPATH in Makefile.PL
Something like
$ARSAPI = "C:\\ARS_Library\\api764win";
if( $WINDOWS ){
$ARS_LDPATH = qq{-L"$ARSAPI/lib"};
$INCLUDES = qq{-I"$ARSAPI/include"};
}else{
$ARS_LDPATH = "-L$ARSAPI/lib";
$INCLUDES = "-I$ARSAPI/include";
}
We updated to ARSperl 1.93, started using AR API version 6.3 rather than 5.1.2 and added "-lsnl" to the ARSperl Makefile.PL $ARS_LIBS in the section for 6.3.
That resulted in Perl segfaulting every time the ARS.so module was run. After lots of testing and trying to diagnose why segfaults were occurring, we recompiled a separate instance of Perl-5.14.2 from source under /opt/ and removed the 64int option. Updating the shebang lines on all our Perl scripts that need the ARS module to redirect to the Perl version under /opt seems to have gotten things working again.
Thank you Chankey Pathak for pointing me toward the Makefile.PL, I wouldn't have immediately started looking at changing things there without this advice.

Is it possible to setup the cross module version in VERSION_FROM option (of Makefile.PL)?

I want to setup the same version for few projects in one place.
I've tried:
use ExtUtils::MakeMaker;
WriteMakefile(
VERSION_FROM => 'lib/project/version.pm',
...
In 'lib/project/version.pm':
package project::version;
use AnotherProject;
our $VERSION = AnotherProject->VERSION();
1;
Note: AnotherProject is located in separate directory, but could be loaded by 'use AnotherProject'. And contain 'our $VERSION="1.00"'.
$ perl Makefile.PL
WARNING: Setting VERSION via file 'lib/project/version.pm' failed
at /usr/lib64/perl5/5.18.2/ExtUtils/MakeMaker.pm line 599.
Can't parse version 'undef'
Is it possible to pass (get) the version string from another module?
Maybe there is another way to do it, please support me.
When you use VERSION_FROM, ExtUtils::MakeMaker doesn't run the file you point at, it parses it itself and tries to find a version number that way. In this case, that won't work. Using VERSION instead of VERSION_FROM in Makefile.PL and calling the other module from there should work.

What can’t perl locate an object method via an installed module?

I am running a Perl program that uses Math::Vector,
but I am getting the following error.
Can't locate object method "UnitVecPoints" via package "Math::Vector"
at /usr/local/share/perl5/Math/Vector.pm line 135.
How do I proceed? The module is correctly installed.
The module is no longer on CPAN. I found it on backpan, though: http://backpan.perl.org/authors/id/W/WS/WSYVINSKI/Vector.pm
It seems to call UnitVecPoints, but it only defines UnitVectorPoints. Try to edit the file /usr/local/share/perl5/Math/Vector.pm, providing the correct subroutine name.

Cant Locate Image/Info.pm Module Error

I'm trying to get the resolution,width,height of the images in the specific file.
I have the following code.
#use strict;
use Image::Info qw(image_info dim);
use File::List;
#perl2exe_include Image::Info::JPEG;
#perl2exe_include PerlIO;
my $file = <ImageFilePath>;
my $info = image_info($file);
my $res = $info->{resolution};
print "$$res[0]\n";
I have the Perl Version 5.16.3
I get the following error:
Can't locate Image/Info.pm in #INC (#INC contains: c:\program files\Perl\lib c:/program files/Perl/site/lib c:/program files/Perl/lib .) at Img_Res.pl line 3.
BEGIN failed--compilation aborted at Img_Res.pl line 3.
Can anyone give me the solution to this?
From the code part of question I am concluding that you are trying to create an executable using Perl2EXE, because you are using the line
#perl2exe_include Image::Info::JPEG;
and also assuming that you are running command
perl2exe c:\somepath\somescript.pl -o somescript.exe
The answer from #James Green is correct to an extent, however its incomplete (as in fails to explain his second bullet point).
You need to install "Image::Info" and any other modules that you are using (Use the answer from #James Green).
After installation, Open to windows explorer and locate the module that you just installed,
It will normally be in the following folders
"PERL_PATH\perl\lib"
"PERL_PATH\perl\site\lib"
"PERL_PATH\perl\vendor\lib"
Once you locate the module is installed in the one of the 3 locations above. Navigate to the location where Perl2EXE is installed.
PERL2EXE_PATH\perl2exe-XX.xx-Win\
Locate the folder with the current version of perl you are using. In your case the folder name should be
Win32-5.16.3 or Win64-5.16.3
Open the folder and locate the .conf file.
Edit the line with header libdir.
libdir=perl-Win32/site/lib;perl-Win32/lib;perl-Win32/vendor/lib;.
Ensure all the perl/lib directories are included in the search path.
Save it and rerun your command. This should work.
Sometimes even after all this the perl2exe command fails, this is due to the limitation of the program being able to decipher the qw command.
So to avoid this directly call the module (ex: use Module::Name;) in your code instead of using the qw.
You need to ensure you've done two things:
install the Image::Info module
make sure #INC includes the path to wherever you installed the module
I see you're on Windows, which means you're likely using either Strawberry Perl, or ActiveState's Perl. If you're using Strawberry Perl you should have some success following the directions on http://www.cpan.org/modules/INSTALL.html -- I believe ActiveState has its own built-in package manager, ppm, and to get started with that you'll want to look here: http://www.activestate.com/activeperl/ppm-perl-modules