Looking at the source code of Sort::Maker makes my eyes bleed, but it also seems that Sort::Maker uses a weird way of communicating errors - it sets $@ but doesn't die. So you could maybe change your error checking as follows:
die "No sort made: $@"
if ! $sf;
When I do that with your code, I get the following "error":
make_sorter: Unknown option or key 'code'
which I consider to be fatal instead of to be the kind of warning people would prefer to hide. Also code is documented to be valid - maybe it depends on the order of arguments, as Sort::Maker really employs some nonstandard argument parsing. Maybe this also is another Perl "Best Practice" that is more a TheDamian Best Practice and should be avoided in general use.
Reading the documentation some more, it seems you have to give it some more arguments for sorting strings and/or numbers. The following code works for me:
#!/usr/bin/perl
# foo.pl - This is just a test
use strict;
use warnings;
use Sort::Maker;
make_sorter( string => { code => sub { length } }, ST => 1, name => 's
+ort_len', )
or die "$@";
my ( $foo, $bar ) = (qw/very_long short/);
my @order = sort_len( $foo, $bar );
print @order;
Here I've wrapped the code => sub { length } in string => {...} - you should read the documentation if that is what you need or not, while I wash my eyes from looking at the code, the interface and the documentation. |