Hook::LexWrap

One of the things I had to check when we upgraded was that the
MergeTicket functionality hadn’t changed significantly, as we’ve
overridden it locally.

When I talked to Jesse about this at Foo he suggested using
Hook::LexWrap instead. I’ve just spent a frustrating half hour or so
trying to find a way to get this to work. It appears that LexWrap
doesn’t like the way that the Ticket modules are evalled in, as it can’t
find the subref to wrap.

For now I’ve gone with rolling my own:

no warnings ‘redefine’;

our $orig = &RT::ticket::MergeInto or die “Can’t find original”;

*RT::ticket::MergeInto = sub {
my ($self, $MergeInto) = @_;

# Load up the new ticket.
my $NewTicket = RT::Ticket->new($RT::SystemUser);
$NewTicket->Load($MergeInto);

my $customer = $self->FirstCustomFieldValue('Customer')
  or return (0, "Can't merge customerless ticket");

my $customer2 = $NewTicket->FirstCustomFieldValue('Customer');
return (0, "Customer is different! ($customer vs $customer2)")
  unless $customer eq $customer2;
goto $orig;
};

This seems to work well enough, but I’d be keen to discover the mystical
incantation to get LexWrap to do it for me.

Thanks,

Tony