Hi, I'm getting a funny error and I can't quite determine if it's
something with Template or with my bad PERL programming with FORKs.
First I need some disclosure. My only other experience with FORK was
with MOO, no laughing please, good God if I told you how I even got INTO
MOO there'd be even more snickering...
So I have a lovely script which looks like this:
#!/usr/bin/perl
use strict;
use CGI;
use Template;
use OTHERSTUFF_BLAH_BLAH_BLAH;...
exit(&main);
sub main {
my $in = new CGI;
my $action = $in->param('action');
my $vars;
my $catNUM = $in->param('catNUM');
if ($action eq 'add') {
my $dlOBJ = new DATA::DOWNLOAD;
$dlOBJ->add_download($in);
$vars->{message} = 'La la la la message...';
}
# show all downloads and the message
print "Content-type: text/html\n\n";
my $dlsOBJ = new SQL2XML::DL_LIST('downloads', "WHERE catNUM =
'$catNUM' ORDER BY id");
my $dlsXML = $dlsOBJ->init();
my $xmlParser = new XML::Simple(forcearray => ['downloads'], keyattr =>
[], suppressempty => 1);
my $dlsOBJ =
$xmlParser->XMLin(&cfg('xml_header')."<outData>\n$dlsXML\n</outData>\n");
$vars->{downloadOBJ} = $dlsOBJ;
$vars->{catNUM} = $catNUM;
my $pageOBJ = Template->new( { ABSOLUTE => 1 } );
$pageOBJ->process(&cfg('admin_downloads'), $vars ) || die
$pageOBJ->error(), "\n";
return 0; # maybe this is needed by the fork in add_download, damn if
I know....
}
Now what "$dlOBJ->add_download($in);" should be doing is FORKing, adding
some entries to a dB table and emailing people. The dB part is working
fine, but the emailing isn't, my suspicions are because another FORK is
called with the piping to OPEN, but I don't really think so.
How this relates to Template is that the $dlsOBJ etc. is not being
created and so not getting processed by Template. Would this be because
of the "close(STDOUT);" which is in "$dlOBJ->add_download($in);", is
there too much strange FORK business going on? Maybe I will add that
code here too...
# this sub needs to update the database for everyone's download, and to
email people about the new item
sub add_download {
use DATA::DL_LIST;
use Template;
my ($self, $in) = @_;
my $output;
my $catNUM = $in->param('catNUM');
my $newDLOBJ = new DATA::DL_LIST($in->param('id'));
my $pageOBJ = Template->new({ABSOLUTE => 1, OUTPUT => \$output});
my $pid;
$pid = fork();
print "Content-type: text/html \n\n fork failed: $!" unless defined
$pid;
if ($pid) { #
return;
} elsif (defined $pid) {
close(STDOUT);
$self->{WHERE} = "WHERE catNUM = '$catNUM' GROUP BY serial";
$self->load('');
foreach my $dlOBJ (@{$self->{OBJECTS}}) {
my $serial = $dlOBJ->data('serial');
# add the download to the system...
$dlOBJ->{NEW} = 1;
$dlOBJ->data('id', undef);
$dlOBJ->data('catNUM', $newDLOBJ->data('catNUM'));
$dlOBJ->data('ISRC', $newDLOBJ->data('ISRC'));
$dlOBJ->data('serial', $serial);
$dlOBJ->data('downloadDESC', $newDLOBJ->data('downloadDESC'));
$dlOBJ->data('downloaded', 0);
$dlOBJ->data('IPAddress', undef);
$dlOBJ->commit;
# next try and create a userOBJ
my $sql = "select $DB_CFG{user}.userID from $DB_CFG{user},
$DB_CFG{serials} WHERE $DB_CFG{user}.userID = $DB_CFG{serials}.userID
AND $DB_CFG{serials}.serial = '$serial' AND $DB_CFG{serials}.userID";
my $sth = $self->{DBH}->prepare($sql);
my $rv = $sth->execute;
if ($rv > 0) {
my ($userID) = $sth->fetchrow_array;
my $userOBJ = new DATA::USER($userID);
# if we have a valid userOBJ then lets notify them
if (!$userOBJ->{NEW}) {
$pageOBJ->process(&cfg('add_download_mail'), {
userOBJ => $userOBJ,
download => $dlOBJ }) || die $pageOBJ->error(), "\n";
open(my $MAIL,"|".&cfg('email')." -t");
print $MAIL $output;
close($MAIL);
$output = ''; # reset output...
}
}
}
exit 0;
}
}
Is my understanding of FORK so utterly abysmal that I should go spend
some days reading and playing with it before bothering people here with
a vaguely related question, or am I missing just a small nuance?
Is it acceptable to get frustrated and kick the power cable out of the
wall and yell FORK-OFF!!!!!
Grrrr....
Tosh
;)
PS. You think this is think-headed, wait until I start asking the
questions about caching and the compile directory for TT... HA!!!
--
Twelve Hundred Group
http://www.1200group.com/
_______________________________________________
templates mailing list
[EMAIL PROTECTED]
http://lists.template-toolkit.org/mailman/listinfo/templates