Reputation: 4266
I'm doing some template programming in RT (http://bestpractical.com/rt), and it uses Perl. Unfortunately, I've only dallied with Perl very occasionally.
I'm trying to call a sub procedure that starts off with:
sub PrepareEmailUsingTemplate {
my %args = (
Template => '',
Arguments => {},
@_
);
Since this is a part of the lib, I don't get to change it.
The call I'm making to it is:
my ($template, $msg) = RT::Interface::Email->PrepareEmailUsingTemplate(
Template => 'CCReplyFirstMessage' );
return (0, $msg) unless $template;
And I'm getting "Odd number of elements in hash assignment at /opt/rt4/sbin/../lib/RT/Interface/Email.pm line 552. (/opt/rt4/sbin/../lib/RT/Interface/Email.pm:552), with is the first line of the sub.
I know I'm doing something whacky in passing the parameter. How should I be passing it?
Upvotes: 3
Views: 6074
Reputation: 98398
If you are going to call the sub as a class method, you need to expect the additional implicit class argument:
my $class = shift;
my %args = ( ..., @_ );
Upvotes: 0
Reputation: 434685
PrepareEmailUsingTemplate
is not a class method, it is a simple function. You want to call it like this:
my ($template, $msg) = RT::Interface::Email::PrepareEmailUsingTemplate(
Template => 'CCReplyFirstMessage' );
return (0, $msg) unless $template;
When you call it with the ->
, your @_
will end up with three values: your two for the hash and the class name at the beginning. The result of calling it as a class method will be something like this:
my %args = (
Template => '',
Arguments => {},
'RT::Interface::Email::PrepareEmailUsingTemplate',
Template => 'CCReplyFirstMessage'
);
And that's where your "odd number of elements in hash assignment" error comes from.
Upvotes: 11
Reputation:
Try:
my ($template, $msg) = RT::Interface::Email::PrepareEmailUsingTemplate(Template => 'CCReplyFirstMessage');
The function isn't written to be called with ->
.
Upvotes: 8