[rt-users] Couldn't compile CustomCommitCode codeblock ... panic: sv_setpvn called with negative strlen -2 at /usr/share/perl5/Devel/StackTrace.pm line 53.
mikemol at gmail.com
Wed Aug 6 14:39:06 EDT 2014
On Wed, Aug 6, 2014 at 2:13 PM, Michael Mol <mikemol at gmail.com> wrote:
> On Wed, Aug 6, 2014 at 1:04 PM, Kevin Falcone <falcone at bestpractical.com> wrote:
>> On Wed, Aug 06, 2014 at 12:46:17PM -0400, Michael Mol wrote:
>>> First attempt at writing an RT scrip, and I'm getting a compile error
>>> I can't easily identify as a problem with my code. Googling around
>>> finds "sv_setpvn called with negative strlen -2" in multiple results,
>>> but none of them in StackTrace.pm, mostly a lot of stuff surrounding
>> You've panic'ed perl.
>> I assume you're on mod_perl.
> I take that as an instruction to switch away from mod_perl. OK, fine.
I've switched to fcgid, even ensured mod_perl was not being loaded by
apache. No change in error message.
>>> ## Begin code snippet
>>> # Find the message from transactionobj->content
>>> # Set the subject to the message by using ticketobj->SetSubject
>>> my $body = $self->TransactionObj->Content;
>>> open my $fh '<', \$body or return 0;
>>> my $trapID = <$fh>; chomp $trapID;
>>> my $messageLine = <$fh>; chomp $messageLine;
>>> $self->TicketObj->SetSubject("$trapID -- $messageLine);
>>> close $fh;
>> Why are you turning a perfectly good string into a file handle just to
>> read three lines?
> Well, frankly, I only want lines 1 and 3, and don't care about line 2.
> And I haven't written any perl code in about six years. I remembered
> the <> mechanism for reading lines, and that was simple enough.
>> Split it on newlines or write a regexp.
> Is there a significant efficiency benefit, or is it a particular
> question of idiomatic or stylistic code?
Code snippet is now:
### Begin snippet
# Find the message from transactionobj->content
# Set the subject to the message by using ticketobj->SetSubject
my $body = $self->TransactionObj->Content;
my @lines = split(m/\n/, $body);
my $trapID = $lines;
my $message = $lines;
$self->TicketObj->SetSubject("$trapID -- $message);
### End snippet
No change in error message. (Whether using mod_perl or mod_fcgid.)
(Code is still readable, and more compact, so I suppose that's nice.)
More information about the rt-users