File Coverage

blib/lib/Util/Task/Simple.pm
Criterion Covered Total %
statement 9 15 60.0
branch n/a
condition n/a
subroutine 3 5 60.0
pod 1 2 50.0
total 13 22 59.0


line stmt bran cond sub pod time code
1              
2             =head1 NAME
3              
4             Util::Task::Simple - A completely uncoalescable, stupid implementation of Util::Task that just runs a closure.
5              
6             =head1 SYNOPSIS
7              
8             my $task = Util::Task::Simple->new(\&some_sub);
9              
10             =head1 DESCRIPTION
11              
12             This Task implementation is about as stupid as they get, just running a given bit of code with no special magic.
13             Consequently it can't coalesce, and runs all of its tasks sequentially. It also can't be remoted.
14              
15             It should only be used for quick prototyping, and any uses of it should be replaced with a more sensible
16             L subclass before long.
17              
18             =cut
19              
20             package Util::Task::Simple;
21              
22 1     1   1079 use strict;
  1         1  
  1         34  
23 1     1   6 use warnings;
  1         2  
  1         31  
24 1     1   6 use base qw(Util::Task);
  1         2  
  1         165  
25              
26             sub new {
27 0     0 0   my ($class, $code) = @_;
28              
29 0           return bless $code, $class;
30             }
31              
32             sub execute_multi {
33 0     0 1   my ($class, $batching_key, $tasks, $results) = @_;
34              
35 0           foreach my $k (keys %$tasks) {
36 0           my $task = $tasks->{$k};
37 0           $results->{$k} = $task->();
38             }
39             }
40              
41             1;