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

sartak at bestpractical.com sartak at bestpractical.com
Wed May 7 23:02:58 EDT 2008


Author: sartak
Date: Wed May  7 23:02:58 2008
New Revision: 12145

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

Log:
 r55406 at onn:  sartak | 2008-05-07 23:01:52 -0400
 Add a bunch of convenience methods to Net::Hiveminder::Task


Modified: Net-Hiveminder/lib/Net/Hiveminder/Task.pm
==============================================================================
--- Net-Hiveminder/lib/Net/Hiveminder/Task.pm	(original)
+++ Net-Hiveminder/lib/Net/Hiveminder/Task.pm	Wed May  7 23:02:58 2008
@@ -11,7 +11,91 @@
     return $LOCATOR->encode($self->id);
 }
 
-__PACKAGE__->meta->make_immutable;
+sub priority_word {
+    my $self = shift;
+    return (undef, qw/lowest low normal high highest/)[$self->priority];
+}
+
+# XXX: datetime and timestamp fields should already be DateTime
+sub starts_datetime {
+    my $self = shift;
+    return undef if !$self->starts;
+    $self->_interface->load_date($self->starts);
+}
+
+sub starts_after {
+    my $self = shift;
+    my $time = shift || time;
+
+    my $starts = $self->starts_datetime;
+    return 0 if !defined($starts);
+    return $starts >= $time if blessed($time);
+    return $starts->epoch >= $time;
+}
+
+sub display {
+    my $self = shift;
+    my %args = @_;
+
+    my $locator = $self->record_locator;
+    my $display;
+
+    if ($self->complete) {
+        $display .= '* ';
+    }
+
+    my $loc_display = "#$locator";
+    if ($args{color}) {
+        my $color = $self->priority >= 5 ? "\e[31m" # red
+                  : $self->priority == 4 ? "\e[33m" # yellow
+                  : $self->priority == 2 ? "\e[36m" # cyan
+                  : $self->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->_interface->site,
+            $locator,
+            $loc_display,
+            $self->summary;
+    }
+    else {
+        $display .= "$loc_display: " . $self->summary;
+    }
+
+    $display .= " [". $self->tags ."]" if $self->tags;
+    $display .= " [". $self->due ."]" if $self->due;
+
+    # display start date only if it's in the future
+    $display .= " [". $self->starts ."]"
+        if $self->starts_after(time);
+
+    $display .= " [priority: " . $self->priority_word . "]"
+        if $self->priority != 3;
+
+    my $helper = sub {
+        my ($field, $name) = @_;
+
+        my $id = $self->$field
+            or return;
+
+        my $email = $self->_interface->email_of($id)
+            or return;
+
+        $self->_interface->is_me($email)
+            and return;
+
+        $display .= " [$name: $email]";
+    };
+
+    $helper->('requestor_id', 'for');
+    $helper->('owner_id', 'by');
+
+    return $display;
+}
+
 no Moose;
 
 1;



More information about the Bps-public-commit mailing list