BUU has asked for the wisdom of the Perl Monks concerning the following question:

My problem is basically that the following script appears to be executing twice, as i get two warnings (_____INDEX.PL______) in my apache error log every time i view a page. This was causing some interesting problems. I tried to narrow down the script to produce a small test case illustrating it, but quite frankly I've had absolutely no luck. So i turn to you fine monks.
Here is the script itself:
#!/usr/bin/perl use strict; use CGI::Carp qw/fatalsToBrowser/; binmode STDIN; use lib 'mods'; require CGI::Lite; require HTML::Template; require DBI; require User; $::dbh=DBI->connect('dbi:mysql:movies','name'); $::ht=new HTML::Template(filename => 'tmpl/default.tmpl'); $::c=new CGI::Lite; $::c->set_directory('uploads'); $::c->set_file_type('file'); %::f=$::c->parse_form_data('GET'); $::f{f}=shift if(~~@ARGV); $::user=new User; my %dispatch= ( news => 'news', add_news => 'add_news', add_news_submit => 'add_news_submit', login => 'login', login_submit => 'login_submit', movie => 'movie', me => 'me', ); if(not $::f{o}) {$::f{o}='news';} warn "_____INDEX.PL______"; #do "subs/$dispatch{$::f{o}}.pl" if($dispatch{$::f{o}}); defaultTmplData(); print "Content-type: text/html\n\n"; print "name: ",$::user->name,' uid: ',$::user->{data}{uid}; print $::ht->output; sub defaultTmplData { my $sql="SELECT mid,tinythumb FROM movies ORDER BY rank DESC limit + 0,5"; my $pn=$::dbh->prepare($sql); $pn->execute; $pn->bind_columns(\my($mid,$thumb)); my @thumbs; while($pn->fetch) { push @thumbs,{thumb_id=>$mid,thumb_url=>$thumb}; } #$::ht->param(thumb_loop=>[@thumbs]); $::ht->param(thumb_loop=>[{}]); }
Note, if you comment out the second to the last line $::ht->param(thumb_loop=>[{}]); You no longer get two warnings.

And here is the template it uses:
<html> <head> <style> @import "css/default.css"; <tmpl_loop name='css_import'> @import "css/<tmpl_var name='css_file'>"; </tmpl_loop> </style> <script> </script> </head> <body> <div id='menu'> <br><br><br><br> <br> <h1>Movies</h1> <ul> <li> <a href='?o=movie&p=top10'>Top 10</a> < +/li> <li> <a href='?o=movie&p=browse'>Browse</a> </li +> <li> <a href='?o=movie&p=random1'>Random</a> </l +i> <li> <a href='?o=movie&p=submit'>Submit</a> </li +> <li> <a href='?o=movie&p=search'>Search</a> </li +> </ul> <h1>News</h1> <ul> <li> <a href='?o=news'>News</a> +</li> <li> <a href='?o=add_news'>Add News</a> </li> </ul> <h1>Movie Editing</h1> <ul> <li> <a href='?o=me'>Front Page</a> + </li> <li> <a href='?o=me&p=newest'>Newest Nodes</a> + </li> <li> <a href='?o=me&p=cat&c=question'>Questions</a> + </li> <li> <a href='?o=me&p=cat&c=theory'>Theories</a> + </li> </ul> </div> <div id='title'> <h1>Title!</h1> </div> <div id='main'> <tmpl_var name='main_content'> </div> <div id='thumbs'> <h1>Thumbs</h1> <ul> <tmpl_loop name='thumb_loop'> <li><a href='?o=movie&p=view&id=<tmpl_var name="thumb_ +id">'><img src='<tmpl_var name="thumb_url">'></a></li> </tmpl_loop> </ul> </div> </body> </html>
Help..

Replies are listed 'Best First'.
Re: HTML::Template, apache, two warnings
by dws (Chancellor) on Apr 15, 2003 at 05:26 UTC
    My problem is basically that the following script appears to be executing twice, as i get two warnings (_____INDEX.PL______) in my apache error log every time i view a page.

    Wild speculation: What you're seeing sound like what might happen if, somehow, warn() got overloaded twice. Is it possible that CGI::Lite does that, perhaps to duplicate CGI::Carp functionality?

      Eh, I suppose that might be happening, but this seems to be the source of the problem I was complaining about last night, namely my database query being executed twice.

      Also when you comment out the last line, which is a HTML::Template->param(); call, I no longer receive two warnings. I also no longer receive two warnings if i change the param call to one with no params, eg $::ht->param([{}]); to $::ht->param(); that also only gives me one warning.