SQL::OrderBy - Perl exstension to transform an SQL ORDER BY clause. use SQL::OrderBy; my $order = resort( order_by => 'name, artist, album', selected => 'artist', ); # artist asc, name asc, album asc print resort( order_by => resort( order_by => resort( order_by => 'name, artist, album', selected => 'artist', ), selected => 'artist', ), selected => 'time', ), "\n"; # artist desc, name asc, album asc, time asc Resort and toggle (ascending/descending) table columns given an SQL ORDER BY clause. This package simply transforms an SQL ORDER BY clause by moving a selected column name to the beginning of the clause and toggling its ascending/descending state based on whether it is already first in the clause.

resort()
resort( order_by => $order_by_string, selected => $selected_column_name, ) This is the sole function of this package. It takes only a (hopefully) well formed, SQL "ORDER BY" clause as a simple string, and a selected column name. These must be provided as named parameters. This selected column name is moved or added to the beginning of the clause with its sort direction (ascending or descending). If this selected clause is the first column of the list, its sort direction is flipped. Note that the state of the sort is maintained, since the selected column name is the only one that is fondled. This implements a feature is essential for GUI environments, where the user interacts with a table by sorting and resorting with a mouse and "toggle button" column names. * If you leave off the selected argument, this function will simply return the clause with sort directions for each column name. That is, no "toggling" or moving is done. Gene Boggs, <cpan@ology.net> Copyright 2003 by Gene Boggs This library is free software; you can redistribute it and/or modify it under the same terms as Perl itself.