+
+ my $sort_order = ($form->{revers} ? ' DESC' : ' ASC');
+
+ # special case: sorting by partnumber
+ # since partnumbers are expected to be prefixed integers, a special sorting is implemented sorting first lexically by prefix and then by suffix.
+ # and yes, that expression is designed to hold that array of regexes only once, so the map is kinda messy, sorry about that.
+ # ToDO: implement proper functional sorting
+ $form->{sort} = join ', ', map { push @select_tokens, $_; ($table_prefix{$_} = "substring(partnumber,'[") . $_ } qw|^[:digit:]]+') [:digit:]]+')::INTEGER|
+ if $form->{sort} eq 'partnumber';
+
+ my $order_clause = " ORDER BY $form->{sort} $sort_order";