1

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

simnom
  • 2,590
  • 1
  • 24
  • 34

2 Answers2

7

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...".

David Precious
  • 6,544
  • 1
  • 24
  • 31
  • Hi David, Thanks for the response. I've added use Template; to the head of the script concerned before posting without any luck. The head of the script is as follows: use strict; use warnings; package KPS::TemplateToolkit; use Template; use KPS::Config; use KPS::Globals; Thanks – simnom Apr 12 '10 at 09:39
  • Out of interest, from a console, run something like: perl -MTemplate -e0 - does it give you any error? – David Precious Apr 12 '10 at 09:44
  • By the way, I believe that TT's new() method expects a hashref of params, so your invocation should look like Template->new({ ... }) - that should not cause the error you're seeing, though. – David Precious Apr 12 '10 at 09:49
  • Thanks a million, this gives me some more ammo to hunt with. Thanks – simnom Apr 12 '10 at 09:49
0

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;
demongolem
  • 9,474
  • 36
  • 90
  • 105