File Coverage

blib/lib/Task/Pluggable/AbstractTaskManager.pm
Criterion Covered Total %
statement 12 48 25.0
branch 0 8 0.0
condition n/a
subroutine 4 9 44.4
pod 1 5 20.0
total 17 70 24.2


line stmt bran cond sub pod time code
1             package Task::Pluggable::AbstractTaskManager;
2 1     1   8 use strict;
  1         3  
  1         47  
3 1     1   6 use warnings;
  1         2  
  1         36  
4 1     1   607 use Task::Pluggable::PluginManager;
  1         4  
  1         13  
5 1     1   41 use base qw(Class::Data::Inheritable Class::Accessor);
  1         2  
  1         643  
6             __PACKAGE__->mk_accessors(qw/config tasks args task_name/);
7              
8             sub new{
9 0     0 1   my $class = shift;
10 0           my $config = shift;
11 0           my $self = $class->SUPER::new();
12 0           $self->config($config);
13 0           $self->init();
14 0           return $self;
15             }
16              
17             sub init{
18 0     0 0   my $self = shift;
19 0           my $tasks = {};
20 0           foreach my $task (Task::Pluggable::PluginManager->tasks()){
21 0 0         die "task name repeat" if(exists $tasks->{$task->task_name});
22 0           $task->task_manager($self);
23 0           $tasks->{$task->task_name} = $task;
24             }
25 0           $self->tasks($tasks);
26             }
27              
28             sub load_args{
29 0     0 0   my $self = shift;
30 0           my @args = @_;
31 0           $self->task_name(shift @args);
32 0           $self->args(\@args);
33             }
34              
35             sub do_task{
36 0     0 0   my $self = shift;
37 0           eval{
38 0 0         die "task not exist" unless($self->task_name());
39 0 0         die "task not exist" unless(exists $self->tasks->{$self->task_name()});
40 0           print 'Task '.$self->task_name.'start'."\n";
41 0           print '-----------------------------------------------------------------------'."\n";
42 0           print 'Pre task excute'."\n";
43 0           $self->tasks->{$self->task_name()}->pre_execute($self);
44 0           print 'Task excute'."\n";
45 0           $self->tasks->{$self->task_name()}->execute($self);
46 0           print 'Post task excute'."\n";
47 0           $self->tasks->{$self->task_name()}->post_execute($self);
48 0           print 'Task finished'."\n";
49             };
50 0 0         if($@){
51 0           print '-----------------------------------------------------------------------'."\n";
52 0           print 'Task Execute Error: '.$@;
53 0           print '-----------------------------------------------------------------------'."\n";
54 0           $self->help();
55             }
56             }
57              
58             sub help{
59 0     0 0   my $self = shift;
60             }
61              
62              
63             1;