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

sartak at bestpractical.com sartak at bestpractical.com
Mon Jan 21 01:06:28 EST 2008


Author: sartak
Date: Mon Jan 21 01:06:27 2008
New Revision: 10402

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

Log:
 r50618 at onn:  sartak | 2008-01-21 01:06:26 -0500
 Let the caller pass arguments into display_tasks, and add a linkify_locator option


Modified: Net-Hiveminder/Changes
==============================================================================
--- Net-Hiveminder/Changes	(original)
+++ Net-Hiveminder/Changes	Mon Jan 21 01:06:27 2008
@@ -3,6 +3,7 @@
 0.03
         Rename tasks2ids to loc2id
         Add id2loc method
+        You can pass arguments to display_tasks. See its POD for how, and what
 
 0.02    Sat Jan 12 08 22:48:24
         Remove canonicalize_priority, Hiveminder does it for us.

Modified: Net-Hiveminder/lib/Net/Hiveminder.pm
==============================================================================
--- Net-Hiveminder/lib/Net/Hiveminder.pm	(original)
+++ Net-Hiveminder/lib/Net/Hiveminder.pm	Mon Jan 21 01:06:27 2008
@@ -53,7 +53,7 @@
     default => "$ENV{HOME}/.hiveminder",
 );
 
-=head2 display_tasks TASKS
+=head2 display_tasks [ARGS], TASKS
 
 This will take a list of hash references, C<TASKS>, and convert each to a
 human-readable form.
@@ -61,6 +61,22 @@
 In scalar context it will return the readable forms of these tasks joined by
 newlines.
 
+Passing options into this is somewhat tricky, because tasks are currently
+regular hashes. You may pass arguments to this method as such:
+
+    $hm->display_tasks([arg1 => 'val1', arg2 => 'val2'], @tasks)
+
+The arguments currently respected are:
+
+=over 4
+
+=item linkify_locator
+
+Make the record locator (C<#foo>) into an HTML link, pointing to the task on
+C<site>.
+
+=back
+
 =cut
 
 sub display_tasks {
@@ -70,9 +86,24 @@
     my $now = DateTime->now;
     my %email_of;
 
+    my %args;
+    if (ref($_[0]) eq 'ARRAY') {
+        %args = @{ shift(@_) };
+    }
+
     for my $task (@_) {
         my $locator = $self->id2loc($task->{id});
-        my $display = "#$locator: $task->{summary}";
+        my $display;
+        if ($args{linkify_locator}) {
+            $display = sprintf '<a href="%s/task/%s">#%s</a>: %s',
+                $self->site,
+                $locator,
+                $locator,
+                $task->{summary};
+        }
+        else {
+            $display = "#$locator: $task->{summary}";
+        }
 
         # don't display start date if it's <= today
         delete $task->{starts}



More information about the Bps-public-commit mailing list