File Coverage

blib/lib/Pask.pm
Criterion Covered Total %
statement 7 9 77.7
branch n/a
condition n/a
subroutine 3 3 100.0
pod n/a
total 10 12 83.3


line stmt bran cond sub pod time code
1             package Pask;
2              
3 1     1   66501 use Carp;
  1         3  
  1         70  
4 1     1   408 use Time::HiRes qw(time);
  1         1441  
  1         7  
5              
6 1     1   565 use Pask::Config;
  0            
  0            
7             use Pask::Container;
8             use Pask::Storage;
9             use Pask::Command;
10             use Pask::Parameter;
11             use Pask::Task;
12              
13             sub parameter {
14             Pask::Parameter::add(@_);
15             }
16              
17             sub command {
18             Pask::Command::add(@_);
19             }
20              
21             sub task {
22             Pask::Task::add(@_);
23             }
24              
25             sub database {
26             if (scalar @_ == 2) {
27             Pask::Container::set_database(@_);
28             } else {
29             Pask::Container::get_database(@_);
30             }
31             }
32              
33             sub say {
34             Pask::Storage::say(@_);
35             }
36              
37             # list all tasks
38             sub list {
39             my $tasks = Pask::Container::get_tasks;
40             my $i = 0;
41             foreach (sort keys %$tasks) {
42             Pask::say {-title}, ++$i, ": ", $tasks->{$_}{"name"};
43             Pask::say {-description}, $tasks->{$_}{"description"};
44             print "\n";
45             }
46             }
47              
48             sub init {
49             my $config = shift;
50            
51             Pask::Container::set_base_path($config->{"base_path"});
52             Pask::Container::set_env_file($config->{"env_file"}) if $config->{"env_file"};
53             Pask::Container::set_env_config(Pask::Config::parse_env_file(Pask::Container::get_env_file));
54              
55             Pask::Storage::init_log_handle;
56              
57             Pask::Storage::register_all;
58              
59             require (Pask::Container::get_user_boot_file) if -e Pask::Container::get_user_boot_file;
60            
61             Pask::Task::register_all;
62             }
63              
64             sub fire {
65             if (@_) {
66             my $file_handle = Pask::Container::get_log_handle;
67            
68             my $task = Pask::Container::get_task $_[0];
69             Pask::Storage::error "Task name $_[0] is not exsit!" unless $task;
70             Pask::Parameter::init;
71             print $file_handle "--- Task [", $task->{"name"}, "] Begin ---\n";
72             my $timing = time;
73              
74             $task->{"command"}(Pask::Parameter::parse $task->{"parameter"});
75              
76             print $file_handle "--- Timing: ", sprintf("%0.3f", time - $timing) , "s ---\n";
77             print $file_handle "--- Task End ---\n\n";
78             } else {
79             list;
80             }
81             }
82              
83             1;
84              
85             =encoding utf8
86              
87             =head1 NAME
88              
89             Pask - A Micro Task Framework
90              
91             =head1 SYNOPSIS
92              
93             # create a new application
94             $> script/pask.pl Demo
95              
96             # show all task
97             $> perl Demo/pask
98              
99             # run task
100             perl Demo/pask TaskName --Parameter Arguments
101              
102             #=head1 TASK
103              
104             # look at demos in the examples directory
105             # create a task
106             my $pask = Pask::task "Foo";
107             # or
108             my $pask = Pask::task "Foo" => {
109             description = "my description",
110             parameter = {},
111             command = sub {}
112             };
113              
114             # set description
115             $pask->set_description = "";
116              
117             # set parameter
118             $pask->set_parameter({
119             "bar" => [],
120             "dep" => [{"dependency" => ["bar"]}]
121             });
122              
123             # set command
124             $pask->set_command(sub {
125             say "hello world!"
126             });