[Bps-public-commit] r14756 - in Prophet/trunk: .
spang at bestpractical.com
spang at bestpractical.com
Mon Aug 4 13:51:00 EDT 2008
Author: spang
Date: Mon Aug 4 13:50:49 2008
New Revision: 14756
Modified:
Prophet/trunk/ (props changed)
Prophet/trunk/lib/Prophet/CLI/Command/Search.pm
Log:
r47660 at loki: spang | 2008-08-04 18:47:08 +0100
implement support for arbitrary sort routines in the output of the search command (default still sorts on luid)
Modified: Prophet/trunk/lib/Prophet/CLI/Command/Search.pm
==============================================================================
--- Prophet/trunk/lib/Prophet/CLI/Command/Search.pm (original)
+++ Prophet/trunk/lib/Prophet/CLI/Command/Search.pm Mon Aug 4 13:50:49 2008
@@ -8,6 +8,18 @@
required => 0,
);
+has 'sort_routine' => (
+ is => 'rw',
+ isa => 'CodeRef',
+ required => 0,
+ # default subs are executed immediately, hence the weird syntax for coderefs
+ default => sub { sub {
+ my @records = @_;
+ return (sort { $a->luid <=> $b->luid } @records);
+ } },
+ documentation => 'A subroutine which takes a list of records and returns them sorted in some way.',
+);
+
sub get_search_callback {
my $self = shift;
@@ -82,11 +94,21 @@
$self->display_terminal($records);
}
+=head2 display_terminal $records
+
+Takes a collection of records, sorts it according to C<$sort_routine>,
+and then prints it to standard output using L<Prophet::Record->format_summary>
+as the format.
+
+=cut
+
sub display_terminal {
my $self = shift;
my $records = shift;
- for ( sort { $a->luid <=> $b->luid } $records->items ) {
+ my $sort_routine = $self->sort_routine;
+
+ for ( &$sort_routine($records->items) ) {
print $_->format_summary . "\n";
}
}
More information about the Bps-public-commit
mailing list