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

Fellow Monks

Im having the following error, I know I can fix it my self but I cant get to the correct files I need till Monday, so just out of interest, I was wondering if anyone had any suggestions:

[Sat May 20 18:24:48 2006] [error] Mail/Template.pm did not return a t +rue value at /home/barrycar/public_html/jonbaglo/pl/perllib/Base.pm l +ine 11.\nBEGIN failed--compilation aborted at /home/barrycar/public_h +tml/jonbaglo/pl/perllib/Base.pm line 11.\nCompilation failed in requi +re at /usr/lib/perl5/site_perl/5.8.6/Apache/Reload.pm line 132.\n

package Mail::Template; use strict; use base qw(Template::Base); use Config; use Mail::Sendmail qw(sendmail); use Template::Base; use Template::Config; our $HOST = $Config::MAIL_HOST; our $PORT = $Config::MAIL_PORT; sub _init { my ($self, $config) = @_; $self->{HOST} = $config->{HOST} || $HOST; $self->{PORT} = $config->{PORT} || $PORT; # Set up a Template::Service instance $self->{SERVICE} = $config->{SERVICE} || Template::Config->service($config) || return $self->error(Template::Config->error); return $self; } sub process { my ($self, $input, $vars, $to, $from, $subject) = @_; my ($output, $mail, $error); my $service = $self->{SERVICE}; # return with an error if no recipient has been specified return $self->error("No recipient specified") unless $to; # process the template $output = $service->process($input, $vars); # send the mail and return or return with an error if (defined $output) { $mail->{To} = $to; $mail->{From} = $from; $mail->{Subject} = $subject; $mail->{Message} = $output; $mail->{Server} = $HOST; $mail->{Port} = $PORT; if (sendmail(%$mail)) { return 1; } else { return $self->error($Mail::Sendmail::error); } } else { return $self->error($service->error); } }
Barry Carlyon barry@barrycarlyon.co.uk

Replies are listed 'Best First'.
Re: Mail/Template.pm, what is true value?
by ikegami (Patriarch) on May 20, 2006 at 17:31 UTC
    Files included using require or use must return a true value. That's usually done by including a 1; at the bottom of the .pm.
Re: Mail/Template.pm, what is true value?
by GrandFather (Saint) on May 20, 2006 at 17:50 UTC

    Packages need to return true. If they don't it implies that some precondition for loading the package failed.

    In most cases that just means putting 1; at the end of the package:

    package Mail::Template; use strict; use base qw(Template::Base); use Config; use Mail::Sendmail qw(sendmail); use Template::Base; use Template::Config; ... # all the rest of the package 1; # The essential 'true'

    Some packages check their context in a BEGIN block and fail to load if it is not correct. That is fairly unusual, not least because the failure message is not wonderfully user friendly, as you have discovered.


    DWIM is Perl's answer to Gödel