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

sartak at bestpractical.com sartak at bestpractical.com
Mon Jan 21 01:22:25 EST 2008


Author: sartak
Date: Mon Jan 21 01:22:25 2008
New Revision: 10404

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

Log:
 r50622 at onn:  sartak | 2008-01-21 01:22:22 -0500
 You can pass arguments to braindump. The "tokens" argument must now be passed
 in as a special option (tokens => 'foo'). The "returns" argument lets
 you control what information you get back.


Modified: Net-Hiveminder/Changes
==============================================================================
--- Net-Hiveminder/Changes	(original)
+++ Net-Hiveminder/Changes	Mon Jan 21 01:22:25 2008
@@ -5,6 +5,8 @@
         Add id2loc method
         You can pass arguments to display_tasks. See its POD for how, and what
         loc2id can now take task-hashes
+        You can pass arguments to braindump. The "tokens" argument must now be
+            passed in as a special option (tokens => 'foo')
 
 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:22:25 2008
@@ -253,21 +253,57 @@
     return $self->delete(Task => id => $id);
 }
 
-=head2 braindump TEXT[, TOKENS]
+=head2 braindump TEXT[, ARGS]
 
-Braindumps C<TEXT>. C<TOKENS> may be used to provide default attributes to all
-the braindumped tasks (this is part of what the filter feature of Hiveminder's
-IM bot does).
+Braindumps C<TEXT>.
+
+Optional arguments:
+
+=over 4
+
+=item tokens => string | arrayref
+
+tokens may be used to provide default attributes to all the braindumped tasks
+(this is part of what the filter feature of Hiveminder's IM bot does).
+
+=item returns => 'ids' | 'tasks'
+
+Return the affected task IDs, or the tasks themselves, instead of a summary of
+the changes made.
+
+=back
 
 =cut
 
 sub braindump {
     my $self = shift;
     my $text = shift;
-    my $tokens = shift || '';
 
-    return $self->act('ParseTasksMagically', text => $text, tokens => $tokens)
-                ->{message};
+    if (@_ == 1) {
+        Carp::carp("You must now pass in an explicit 'tokens => string|arrayref' to have default tokens in Net::Hiveminder->braindump");
+        unshift @_, 'tokens';
+    }
+
+    my %args = (
+        tokens  => '',
+        returns => 'summary',
+        @_,
+    );
+
+    my $tokens = $args{tokens};
+    if (ref($tokens) eq 'ARRAY') {
+        $tokens = join ' ', @$tokens;
+    }
+
+    my $ret = $self->act('ParseTasksMagically', text => $text, tokens => $tokens);
+    if ($args{returns} eq 'ids') {
+        return @{ $ret->{content}->{ids} || [] };
+    }
+    elsif ($args{returns} eq 'tasks') {
+        return @{ $ret->{content}->{created} || [] };
+    }
+
+    return $ret->{message};
 }
 
 =head2 upload_text TEXT



More information about the Bps-public-commit mailing list