SitePoint Sponsor

User Tag List

Results 1 to 7 of 7
  1. #1
    SitePoint Member
    Join Date
    Jun 2010
    Location
    Canada
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)

    Can't call method "output" on an undefined value

    This is a small part of code from a larger script, but is the main part. I get the same err msg (Can't call method "output" on an undefined value) in a browser and from the shell command line (Can't call method "output" on an undefined value at ./temp.cgi line 11.). I know Text::FastTemplate is working in general b/c it works on all my PHP scripts. Just this one Perl script it does not like for some reason. Running Perl 5.8.8 on centos.

    Suggestions?


    Code:
    #!/usr/bin/perl
    
    use Text::FastTemplate;
    
    $templatedir = '/home/virtual/site/data/cgi-templates';
    $filename    = 'customer.tpl.html';
    
    print "Content-type: text/html\n\n";
    
    $template = new Text::FastTemplate(file=>$filename, path=>$templatedir);
    print $template->output();  <-- the line giving the err msg
    
    exit;

  2. #2
    SitePoint Enthusiast
    Join Date
    Oct 2005
    Posts
    33
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Text::FastTemplate->new() is returning an undefined value.

    Probably due to it not liking something in the constructor, I'd check to make sure the files are readable, and whether it's using some sort of cache directory that isn't accessible? (One would have to inspect Text/FastTemplate.pm, tracing through 'new' to see what it's doing, or, maybe look in the docs for some kind of error variable)

    Have a look in $! (not always useful)

  3. #3
    SitePoint Evangelist
    Join Date
    Jun 2007
    Location
    North Yorkshire, UK
    Posts
    483
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Haven't used FastTemplate myself but the documentation says that "path" needs to be an array ref.

    This is a list of directories to be searched when a file is specified with a relative pathname. The list of paths is passed in an ARRAY-REF.
    Try

    Code:
    $template = new Text::FastTemplate(file=>$filename, path=> [ $templatedir ]);

  4. #4
    SitePoint Member
    Join Date
    Jun 2010
    Location
    Canada
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Tried the example. Exact same err msg.

  5. #5
    SitePoint Member
    Join Date
    Jun 2010
    Location
    Canada
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    This script worked perfectly before changing to a new server.

  6. #6
    SitePoint Member
    Join Date
    Jun 2010
    Location
    Canada
    Posts
    18
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Man, can't believe something so simple took so long to find. It was the actual template files causing the prob. They had an #include to old non-existent template footer file.

  7. #7
    SitePoint Enthusiast
    Join Date
    Oct 2007
    Posts
    34
    Mentioned
    0 Post(s)
    Tagged
    0 Thread(s)
    Catching up four days late ....... and only a tip for the future ...

    Didn't see any use strict; use warnings; in your code excerpt.
    They are both useful when trying to isolate a problem.

    Regards

    Lesley


Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •