Skip to content

Instantly share code, notes, and snippets.

@rohandalvi
Last active August 29, 2015 14:11
Show Gist options
  • Save rohandalvi/e0974462af3f6cdd4005 to your computer and use it in GitHub Desktop.
Save rohandalvi/e0974462af3f6cdd4005 to your computer and use it in GitHub Desktop.
Can't locate object method "params"
The error:
Rohans-MacBook-Pro-164:Bugzilla rohandalvi$ perl test_email.pm
Can't locate object method "params" via package "Bugzilla" at /Users/rohandalvi/Documents/open_source_stuff/bugzilla/bugzilla/Bugzilla/Mailer.pm line 33.
The module "Token.pm" makes use of the subroutine MessageToMTA to send email which I am trying to use here. . What am I doing wrong? Is this a import issue? However, In the code below, it uses the format MessageToMTA($message) without generating any error
Code from token.pm that also makes call to MessageToMTA subroutine in Mailer.pm
my ($token, $token_ts) = _create_token(undef, 'account', $login_name);
$vars->{'email'} = $login_name . Bugzilla->params->{'emailsuffix'};
$vars->{'expiration_ts'} = ctime($token_ts + MAX_TOKEN_AGE * 86400);
$vars->{'token'} = $token;
my $message;
$template->process('account/email/request-new.txt.tmpl', $vars, \$message)
|| ThrowTemplateError($template->error());
# In 99% of cases, the user getting the confirmation email is the same one
# who made the request, and so it is reasonable to send the email in the same
# language used to view the "Create a New Account" page (we cannot use their
# user prefs as the user has no account yet!).
MessageToMTA($message);
My code:
#! /usr/bin/perl -I/Users/rohandalvi/Documents/open_source_stuff/bugzilla/bugzilla
#s Source Code Form is subject to the terms of the Mozilla Public
# License, v. 2.0. If a copy of the MPL was not distributed with this
# file, You can obtain one at http://mozilla.org/MPL/2.0/.
#
# This Source Code Form is "Incompatible With Secondary Licenses", as
# defined by the Mozilla Public License, v. 2.0.
package Bugzilla::Mailer;
use 5.10.1;
use strict;
use warnings;
use Bugzilla::Mailer;
use Bugzilla::Constants;
use Bugzilla::Error;
use Bugzilla::Hook;
use Bugzilla::Util;
sub main{
my ($msg, $send_now);
MessageToMTA($msg => "Sample message", $send_now => 1);
}
main();
#end of code.
the file test_mail.pm is in the same directory as Bugzilla::Mailer.pm
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment