[Bps-public-commit] r12146 - in Net-Hiveminder: lib/Net

sartak at bestpractical.com sartak at bestpractical.com
Wed May 7 23:03:06 EDT 2008


Author: sartak
Date: Wed May  7 23:03:02 2008
New Revision: 12146

Modified:
   Net-Hiveminder/   (props changed)
   Net-Hiveminder/lib/Net/Hiveminder.pm

Log:
 r55407 at onn:  sartak | 2008-05-07 23:02:55 -0400
 Populate Net::Hiveminder::Task's attributes and return objects instead of plain hashrefs


Modified: Net-Hiveminder/lib/Net/Hiveminder.pm
==============================================================================
--- Net-Hiveminder/lib/Net/Hiveminder.pm	(original)
+++ Net-Hiveminder/lib/Net/Hiveminder.pm	Wed May  7 23:03:02 2008
@@ -90,9 +90,7 @@
 
 sub display_tasks {
     my $self = shift;
-    my @out;
 
-    my $now = DateTime->now;
     my %email_of;
 
     my %args;
@@ -100,70 +98,7 @@
         %args = @{ shift(@_) };
     }
 
-    for my $task (@_) {
-        my $locator = $self->id2loc($task->{id});
-        my $display;
-
-        if ($task->{complete}) {
-            $display .= '* ';
-        }
-
-        my $loc_display = "#$locator";
-        if ($args{color}) {
-            my $color = $task->{priority} >= 5 ? "\e[31m" # red
-                      : $task->{priority} == 4 ? "\e[33m" # yellow
-                      : $task->{priority} == 2 ? "\e[36m" # cyan
-                      : $task->{priority} <= 1 ? "\e[34m" # blue
-                      : "";
-            $loc_display = "$color$loc_display\e[m" if $color;
-        }
-
-        if ($args{linkify_locator}) {
-            $display .= sprintf '<a href="%s/task/%s">%s</a>: %s',
-                $self->site,
-                $locator,
-                $loc_display,
-                $task->{summary};
-        }
-        else {
-            $display .= "$loc_display: $task->{summary}";
-        }
-
-        # don't display start date if it's <= today
-        delete $task->{starts}
-            if $task->{starts}
-            && $self->load_date($task->{starts}) < $now;
-
-        $display .= " [$task->{tags}]" if $task->{tags};
-        for my $field (qw/due starts group/) {
-            $display .= " [$field: $task->{$field}]"
-                if $task->{$field};
-        }
-
-        $display .= " [priority: " . $self->priority($task->{priority}) . "]"
-            if $task->{priority} != 3;
-
-        my $helper = sub {
-            my ($field, $name) = @_;
-
-            my $id = $task->{$field}
-                or return;
-
-            # this wants to be //=. oh well
-            my $email = $email_of{$id} ||= $self->email_of($id)
-                or return;
-
-            $self->is_me($email)
-                and return;
-
-            $display .= " [$name: $email]";
-        };
-
-        $helper->('requestor_id', 'for');
-        $helper->('owner_id', 'by');
-
-        push @out, $display;
-    }
+    my @out = map { $_->display } @_;
 
     return wantarray ? @out : join "\n", @out;
 }
@@ -183,7 +118,10 @@
     my @args = @_;
     unshift @args, "tokens" if @args == 1;
 
-    return @{ $self->act('TaskSearch', @args)->{content}{tasks} };
+    $self->create_model_class('Task');
+
+    return map { Net::Hiveminder::Task->new(_interface => $self, %$_) }
+           @{ $self->act('TaskSearch', @args)->{content}{tasks} };
 }
 
 =head2 todo_tasks [ARGS]
@@ -268,7 +206,8 @@
     my $loc   = shift;
     my $id    = $self->loc2id($loc);
 
-    return $self->read(Task => id => $id);
+    $self->create_model_class('Task');
+    return Net::Hiveminder::Task->load($self, $id);
 }
 
 =head2 update_task LOCATOR, ARGS
@@ -413,7 +352,9 @@
         return @{ $ret->{content}->{ids} || [] };
     }
     elsif ($args{returns} eq 'tasks') {
-        return @{ $ret->{content}->{created} || [] };
+        $self->create_model_class('Task');
+        return map { Net::Hiveminder::Task->new(_interface => $self, %$_) }
+               @{ $ret->{content}->{created} || [] };
     }
 
     return $ret->{message};



More information about the Bps-public-commit mailing list