[Bps-public-commit] r15962 - in sd/trunk: . lib/App/SD/CLI

spang at bestpractical.com spang at bestpractical.com
Sat Sep 13 17:18:35 EDT 2008


Author: spang
Date: Sat Sep 13 17:18:35 2008
New Revision: 15962

Modified:
   sd/trunk/   (props changed)
   sd/trunk/lib/App/SD/CLI/Command.pm
   sd/trunk/lib/App/SD/CLI/Command/Ticket/Comments.pm
   sd/trunk/lib/App/SD/CLI/Command/Ticket/Search.pm

Log:
 r49786 at loki:  spang | 2008-09-13 16:16:17 -0400
 factor out sort_by_creation_date to App::SD::CLI::Command and fix some warnings noise


Modified: sd/trunk/lib/App/SD/CLI/Command.pm
==============================================================================
--- sd/trunk/lib/App/SD/CLI/Command.pm	(original)
+++ sd/trunk/lib/App/SD/CLI/Command.pm	Sat Sep 13 17:18:35 2008
@@ -65,6 +65,19 @@
     return $content;
 }
 
+=head2 sort_by_creation_date $records
+
+Given an arrayref to a list of records, returns a list of the records
+sorted by their C<created> property, in ascending order.
+
+=cut
+
+sub sort_by_creation_date {
+    my ($self, $records) = @_;
+
+    return (sort { $a->prop('created') cmp $b->prop('created') } @{$records});
+}
+
 no Moose::Role;
 
 1;

Modified: sd/trunk/lib/App/SD/CLI/Command/Ticket/Comments.pm
==============================================================================
--- sd/trunk/lib/App/SD/CLI/Command/Ticket/Comments.pm	(original)
+++ sd/trunk/lib/App/SD/CLI/Command/Ticket/Comments.pm	Sat Sep 13 17:18:35 2008
@@ -2,6 +2,7 @@
 use Moose;
 extends 'Prophet::CLI::Command';
 with 'Prophet::CLI::RecordCommand';
+with 'App::SD::CLI::Command';
 with 'App::SD::CLI::Model::Ticket';
 
 sub run {
@@ -10,16 +11,16 @@
 
     $self->require_uuid;
     $record->load( uuid => $self->uuid );
-    unless (@{$record->comments}) {
-        print "No comments found\n";
-    }
 
-    for my $entry (sort { $a->prop('created') cmp $b->prop('created') } @{$record->comments}) {
-         print "id: ".$entry->luid." (".$entry->uuid.")\n";
-        print "created: ".$entry->prop('created')."\n";
-        print $entry->prop('content')."\n";
+    if (@{$record->comments}) {
+        for my $entry ($self->sort_by_creation_date($record->comments)) {
+            print "id: ".$entry->luid." (".$entry->uuid.")\n";
+            print "created: ".$entry->prop('created')."\n";
+            print $entry->prop('content')."\n\n";
+        }
+    } else {
+        print "No comments found\n";
     }
-
 }
 
 __PACKAGE__->meta->make_immutable;

Modified: sd/trunk/lib/App/SD/CLI/Command/Ticket/Search.pm
==============================================================================
--- sd/trunk/lib/App/SD/CLI/Command/Ticket/Search.pm	(original)
+++ sd/trunk/lib/App/SD/CLI/Command/Ticket/Search.pm	Sat Sep 13 17:18:35 2008
@@ -1,6 +1,7 @@
 package App::SD::CLI::Command::Ticket::Search;
 use Moose;
 extends 'Prophet::CLI::Command::Search';
+with 'App::SD::CLI::Command';
 
 # frob the sort routine before running prophet's search command
 before run => sub {
@@ -10,12 +11,9 @@
     if ($self->has_arg('sort')) {
         # some records might not have creation dates
         no warnings 'uninitialized';
-        # sort by creation date
-        my $sort_routine = sub {
-            my @records = @_;
-            return (sort { $a->prop('created') cmp $b->prop('created') } @records);
-        };
-        $self->sort_routine($sort_routine);
+        $self->sort_routine( sub {
+                    my $records = shift;
+                    return $self->sort_by_creation_date($records) } );
     }
 };
 



More information about the Bps-public-commit mailing list