Beefy Boxes and Bandwidth Generously Provided by pair Networks
Do you know where your variables are?
 
PerlMonks  

Error using HTML::Template

by Anneq (Vicar)
on Dec 11, 2003 at 05:27 UTC ( #313980=perlquestion: print w/ replies, xml ) Need Help??
Anneq has asked for the wisdom of the Perl Monks concerning the following question:

I am trying out HTML::Template for the first time and used the script and template given in it's POD.

Template from HTML::Template POD:

<html> <head> <title>Test Template</title> </head> <body> <p>My Home Directory is <TMPL_VAR NAME=HOME></p> <p>My Path is set to <TMPL_VAR NAME=PATH></p> </body> </html>

Accompanying Script:

#!/usr/bin/perl -wT use HTML::Template; # open the html template my $template = HTML::Template->new(filename => 'test.tmpl'); # fill in some parameters $template->param(HOME => $ENV{HOME}); $template->param(PATH => $ENV{PATH}); # send the obligatory Content-Type and print the template output print "Content-Type: text/html\n\n", $template->output;

This resulted in the following error:

Can't locate object method "isa" via package "Cwd" at base.pm line 56.

I'm using the latest ActivePerl core for Windows and publishing to a remote web server that requires me to upload all of the necessary modules and perl scripts to a directory "/cgi-bin". Since it works fine on my local server, my guess is that I am missing a module(s) on the remote web server.

Any help with this problem would be appreciated.

Thanks in advance for your help,

Anne

Anneq

Comment on Error using HTML::Template
Select or Download Code
Re: Error using HTML::Template
by BUU (Prior) on Dec 11, 2003 at 06:31 UTC
    output print "Content-Type: text/html\n\n", $template->output; Typo? New feature?

      i.e. Your comment should be on just the one line, anneq. This might have been a copy-and-paste error (from you local server to the remote, or from your local server to the Monastery, not sure which), which is why you should use <code> tags to include code in your posts.

      This also should have produced an error. Did you check for errors? Hint: run it from the console before you test it on the web.

      (I also recommend you use strict in all your scripts to make sure you're generally declaring your variables, etc. correctly. It's a bit of bondage that encourages good coding practices.)

      # send the obligatory Content-Type and print the template output print "Content-Type: text/html\n\n", $template->output;

      --
      Allolex

        Allolex,

        Thanks for your reply. My comment is on one line. I'll use code tags next time, though. Thanks for that tip. I didn't know about code.

        I ran it from the console and from my local web server and it ran just fine.

        I put use strict and -wT in all my scripts but I tried without them and it still didn't work.

        Thank you for your help,

        Anne

        Anneq

      This is taken right out of the documentation that comes with the module.

      Anne

      Anneq
Re: Error using HTML::Template
by seattlejohn (Deacon) on Dec 11, 2003 at 06:59 UTC
    Line 56 in base.pm reads:
    next if $pkg->isa($base);
    Based on the error message, it looks like the $pkg is Cwd. I'm guessing that perl can't find the object method because the class isn't loaded properly. Does the target Web server have Cwd.pm in an included directory?

            $perlmonks{seattlejohn} = 'John Clyman';

      John,

      Thank you for responding. The target web server has Cwd.pm so that is not my problem.

      Thanks,

      Anne

      Anneq
Re: Error using HTML::Template
by !1 (Hermit) on Dec 11, 2003 at 14:06 UTC

    The error message is quite puzzling. isa should be inherited from UNIVERSAL. I can't tell you how long UNIVERSAL has been around, but it's been there at least since 5.006. Could you possibly tell us which version of the interpreter your hosting provider uses?

      My remote server is Tripod and according to their on-line documentation, they are using version 5.8.0.

      Thanks for responding,

      Anne

      Anneq
        My remote server is Tripod
        There's your problem. Tripod severely crippled Perl when they upgraded to 5.8. Not even the standard modules are available. I wouldn't recommend Tripod to anyone.

        Try this minimal script:

        print "Content-Type: text/plain\n\n"; print "\@INC is:"; print join ":", @INC;

        It's empty! Bad Tripod!

        Here's another one to try, even more minimal:

        use strict;

        And the resulting error message1:

        Your script produced this error: Can't locate strict.pm in @INC (@INC contains: . /lib /site_perl) at n +ostrict.pl line 1. BEGIN failed--compilation aborted at nostrict.pl line 1.

        I tried to manually satisfy the requirements for a simple site for a friend, and ended up giving up on Tripod all together (I still remember the login info ;).

        1Note - in the second error message, @INC is populated. Not sure why...

Re: Error using HTML::Template
by swngnmonk (Pilgrim) on Dec 11, 2003 at 15:21 UTC

    I see two errors - one is an error in your code (copy/paste from improperly formatted POD on your end), the other is an actual typo in the POD.

    Looking at the POD on CPAN, the line reads:

    # send the obligatory Content-Type and print the template output print "Content-Type: text/html\n\n", $template->output;

    So it's "print", not "output print". But there is a typo in the POD - that comma before $template->output; should be a period (string concatenation).

    print "Content-Type: text/html\n\n". $template->output;

    Or, if you're familiar with C, you could also write it in a more recognizable form:

    print sprintf("Content-Type:text/html\n\n%s",$template->output);

    No difference, really, but sometimes people find it easier to read the latter.


    Update: Ok, so I'm wrong about the second bug - I'll plead ignorance to printing in LIST form. That being said, based on the original post, I think a code copy &paste went badly, and that's why you're getting the strange error messages.

    PS - and yes, you could just use printf, but you'll get far more use out of sprintf in the long run. :)

      But there is a typo in the POD - that comma before $template->output; should be a period (string concatenation).

      Why?

      #!/usr/bin/perl -l print 1,2,3; $,=$"; print "this","works"; __END__ 123 this works

      This is the print LIST form that is mentioned in perldoc -f print.

      I wouldn't bother with print sprintf(...).. just use printf.

      swngnmonk,

      The comment and line of code are correct in my script. It could be that it showed up incorrectly on the node because I didn't use code tages. Thanks to Allolex pointing that out. It looks fine on my screen because I am using small fonts in my CSS.

      I thought that the comma could be problem too, so I tried using the concatenation operator and also tried using two print statements but to no avail.

      I'm a newbie to programming and web pages so I think using C is out for me right now. Too steep a learning curve.

      Thank you for taking your valuable time to respond.

      Much appreciated,

      Anne

      Anneq
Re: Error using HTML::Template
by samtregar (Abbot) on Dec 11, 2003 at 18:33 UTC
    I suspect your problem has something to do with taint mode. You added a "T" to the first line of the script you copied from the POD. Try removing it and post your results.

    -sam

      samtregar,

      I originally used strict and -wT and then tried taking them out one at a time and then all combinations and it still didnt' work. Who knows?

      Thanks for your input,

      Anne

      Anneq

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: perlquestion [id://313980]
Approved by Enlil
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others romping around the Monastery: (14)
As of 2014-07-25 10:08 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    My favorite superfluous repetitious redundant duplicative phrase is:









    Results (170 votes), past polls