in reply to relaying sort's code block

You've probably be given the solution, but just a couple of comments.

Although it might work and this is unlikely to be the cause of your problem, I do not think that naming your own function or method with the name of a built-in function is very good practice. It might obscure any issue. An additional comment is why are you doing this:

my $code = \&{shift @_};
The argument should presumably be a sub ref. And, in the case of your code, it is (thanks to the prototype). So you could have simply:
my $code = shift;