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