line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Script::Nohup; |
2
|
3
|
|
|
3
|
|
5794
|
use Mouse; |
|
3
|
|
|
|
|
65410
|
|
|
3
|
|
|
|
|
12
|
|
3
|
3
|
|
|
3
|
|
833
|
use Mouse::Util::TypeConstraints; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
11
|
|
4
|
|
|
|
|
|
|
|
5
|
3
|
|
|
3
|
|
251
|
use 5.008001; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
81
|
|
6
|
3
|
|
|
3
|
|
1690
|
use utf8; |
|
3
|
|
|
|
|
25
|
|
|
3
|
|
|
|
|
16
|
|
7
|
3
|
|
|
3
|
|
1437
|
use POSIX qw/setsid/; |
|
3
|
|
|
|
|
11315
|
|
|
3
|
|
|
|
|
19
|
|
8
|
3
|
|
|
3
|
|
2939
|
use Path::Class::File; |
|
3
|
|
|
|
|
34565
|
|
|
3
|
|
|
|
|
79
|
|
9
|
3
|
|
|
3
|
|
1703
|
use Time::Piece; |
|
3
|
|
|
|
|
26553
|
|
|
3
|
|
|
|
|
15
|
|
10
|
3
|
|
|
3
|
|
202
|
use IO::Handle; |
|
3
|
|
|
|
|
8
|
|
|
3
|
|
|
|
|
1224
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
sub import { |
13
|
1
|
|
|
1
|
|
2
|
my $pkg = shift; |
14
|
|
|
|
|
|
|
|
15
|
1
|
|
|
|
|
10
|
$pkg->_fork; |
16
|
|
|
|
|
|
|
|
17
|
1
|
|
|
|
|
79
|
my $script_nohup = $pkg->new(@_); |
18
|
|
|
|
|
|
|
|
19
|
1
|
|
|
|
|
300
|
$SIG{HUP} = 'IGNORE'; |
20
|
1
|
|
|
|
|
48
|
print "start : ".$script_nohup->basename."\n"; |
21
|
1
|
|
|
|
|
6
|
print "create : ".$script_nohup->filename."\n"; |
22
|
|
|
|
|
|
|
|
23
|
1
|
|
|
|
|
2
|
$script_nohup->_logger(); |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
our $VERSION = "0.01"; |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
subtype "Path::Class::File" => as Object => where { $_->isa("Path::Class::File") }; |
29
|
|
|
|
|
|
|
coerce "Path::Class::File" |
30
|
|
|
|
|
|
|
=> from "Str", |
31
|
|
|
|
|
|
|
=> via { Path::Class::File->new($_) }; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
has script => ( |
34
|
|
|
|
|
|
|
is => "ro", |
35
|
|
|
|
|
|
|
isa => "Path::Class::File", |
36
|
|
|
|
|
|
|
coerce => 1, |
37
|
|
|
|
|
|
|
default => sub { $0 }, |
38
|
|
|
|
|
|
|
); |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
has basename => ( |
41
|
|
|
|
|
|
|
is => "ro", |
42
|
|
|
|
|
|
|
isa => "Str", |
43
|
|
|
|
|
|
|
default => sub { |
44
|
|
|
|
|
|
|
my $self = shift; |
45
|
|
|
|
|
|
|
$self->script->basename |
46
|
|
|
|
|
|
|
}, |
47
|
|
|
|
|
|
|
); |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
has filename => ( |
50
|
|
|
|
|
|
|
is => "ro", |
51
|
|
|
|
|
|
|
isa => "Str", |
52
|
|
|
|
|
|
|
lazy => 1, |
53
|
|
|
|
|
|
|
default => sub { |
54
|
|
|
|
|
|
|
my $self = shift; |
55
|
|
|
|
|
|
|
$self->basename.'_'.$self->exec_date.$self->file_extention; |
56
|
|
|
|
|
|
|
}, |
57
|
|
|
|
|
|
|
); |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
has file_extention => ( |
60
|
|
|
|
|
|
|
is => "ro", |
61
|
|
|
|
|
|
|
isa => "Str", |
62
|
|
|
|
|
|
|
default => ".log" |
63
|
|
|
|
|
|
|
); |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
has exec_date => ( |
66
|
|
|
|
|
|
|
is => "ro", |
67
|
|
|
|
|
|
|
default => sub { localtime->ymd } |
68
|
|
|
|
|
|
|
); |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
has file => ( |
71
|
|
|
|
|
|
|
is => "ro", |
72
|
|
|
|
|
|
|
isa => "Path::Class::File", |
73
|
|
|
|
|
|
|
lazy => 1, |
74
|
|
|
|
|
|
|
coerce => 1, |
75
|
|
|
|
|
|
|
default => sub { |
76
|
|
|
|
|
|
|
my $self = shift; |
77
|
|
|
|
|
|
|
$self->script->dir->file($self->filename); |
78
|
|
|
|
|
|
|
}, |
79
|
|
|
|
|
|
|
); |
80
|
|
|
|
|
|
|
|
81
|
3
|
|
|
3
|
|
16
|
no Mouse; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
21
|
|
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
sub _fork { |
85
|
0
|
|
|
0
|
|
0
|
my $pid = fork(); |
86
|
0
|
0
|
|
|
|
0
|
die "can't fork: $!" unless defined $pid; |
87
|
0
|
0
|
|
|
|
0
|
exit 0 if $pid; |
88
|
0
|
|
|
|
|
0
|
setsid(); |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub _logger { |
92
|
1
|
|
|
1
|
|
1
|
my $self = shift; |
93
|
|
|
|
|
|
|
|
94
|
1
|
|
|
|
|
21
|
STDOUT->autoflush; |
95
|
1
|
|
|
|
|
121
|
STDERR->autoflush; |
96
|
|
|
|
|
|
|
|
97
|
1
|
|
|
|
|
37
|
$self->_add_log; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub _add_log { |
101
|
1
|
|
|
1
|
|
2
|
my $self = shift; |
102
|
1
|
|
|
|
|
3
|
open(STDOUT,'>>',$self->file); |
103
|
1
|
|
|
|
|
273
|
open(STDERR,'>>',$self->file); |
104
|
|
|
|
|
|
|
} |
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
1; |
107
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
__END__ |