line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package File::Monitor::Lite; |
2
|
|
|
|
|
|
|
|
3
|
3
|
|
|
3
|
|
70443
|
use 5.8.6; |
|
3
|
|
|
|
|
12
|
|
|
3
|
|
|
|
|
186
|
|
4
|
|
|
|
|
|
|
our $VERSION = '0.652003'; |
5
|
3
|
|
|
3
|
|
18
|
use strict; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
108
|
|
6
|
3
|
|
|
3
|
|
24
|
use warnings; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
114
|
|
7
|
3
|
|
|
3
|
|
3313
|
use File::Spec::Functions ':ALL'; |
|
3
|
|
|
|
|
3164
|
|
|
3
|
|
|
|
|
1233
|
|
8
|
3
|
|
|
3
|
|
3545
|
use File::Find::Rule; |
|
3
|
|
|
|
|
33687
|
|
|
3
|
|
|
|
|
32
|
|
9
|
3
|
|
|
3
|
|
4257
|
use File::Monitor; |
|
3
|
|
|
|
|
45950
|
|
|
3
|
|
|
|
|
104
|
|
10
|
3
|
|
|
3
|
|
34
|
use base 'Class::Accessor::Fast'; |
|
3
|
|
|
|
|
6
|
|
|
3
|
|
|
|
|
3350
|
|
11
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors( |
12
|
|
|
|
|
|
|
qw( |
13
|
|
|
|
|
|
|
monitor |
14
|
|
|
|
|
|
|
watch_list |
15
|
|
|
|
|
|
|
)); |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
sub new { |
19
|
6
|
|
|
6
|
1
|
3614
|
my $class = shift; |
20
|
6
|
|
|
|
|
26
|
my $self = {@_}; |
21
|
6
|
|
|
|
|
18
|
bless $self, $class; |
22
|
6
|
|
|
|
|
21
|
$self->_init; |
23
|
6
|
|
|
|
|
22
|
return $self; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
sub _init{ |
27
|
6
|
|
|
6
|
|
11
|
my $self = shift; |
28
|
6
|
50
|
|
|
|
125
|
-d $self->{in} or die "invalid director\n"; |
29
|
6
|
|
|
|
|
34
|
$self->{in}=rel2abs($self->{in}); |
30
|
0
|
|
|
|
|
0
|
my %w_list = |
31
|
6
|
|
|
|
|
470
|
map{$_ => 1} |
32
|
|
|
|
|
|
|
File::Find::Rule |
33
|
|
|
|
|
|
|
->file() |
34
|
|
|
|
|
|
|
->name($self->{name}) |
35
|
|
|
|
|
|
|
->in($self->{in}); |
36
|
6
|
|
|
|
|
24646
|
$self->watch_list(\%w_list); |
37
|
6
|
|
|
|
|
117
|
$self->monitor(new File::Monitor); |
38
|
6
|
|
|
|
|
331
|
$self->monitor->watch($_)for keys %w_list; |
39
|
6
|
|
|
|
|
25
|
$self->monitor->scan; |
40
|
6
|
|
|
|
|
216
|
$self->{observed}=[keys %w_list]; |
41
|
6
|
|
|
|
|
17
|
$self->{created}=[]; |
42
|
6
|
|
|
|
|
16
|
$self->{deleted}=[]; |
43
|
6
|
|
|
|
|
20
|
$self->{modified}=[]; |
44
|
6
|
|
|
|
|
18
|
1; |
45
|
|
|
|
|
|
|
} |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
sub check { |
50
|
7
|
|
|
7
|
1
|
5678
|
my $self = shift; |
51
|
7
|
|
|
|
|
32
|
my $w_list=$self->watch_list; |
52
|
7
|
|
|
|
|
357
|
my @new_file_list = |
53
|
|
|
|
|
|
|
File::Find::Rule |
54
|
|
|
|
|
|
|
->file() |
55
|
|
|
|
|
|
|
->name($self->{name}) |
56
|
|
|
|
|
|
|
->in($self->{in}); |
57
|
7
|
|
|
|
|
39646
|
my @new_files = grep { not exists $$w_list{$_} } @new_file_list; |
|
7
|
|
|
|
|
31
|
|
58
|
7
|
|
|
|
|
276
|
my @changes = $self->monitor->scan; |
59
|
4
|
|
|
|
|
58
|
my @deleted_files = |
60
|
6
|
|
|
|
|
32
|
map{$_->name} |
61
|
7
|
|
|
|
|
12468
|
grep{$_->deleted} @changes; |
62
|
2
|
|
|
|
|
20
|
my @modified_files = |
63
|
6
|
|
|
|
|
23
|
map{$_->name} |
64
|
7
|
|
|
|
|
88
|
grep{not $_->deleted} @changes; |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
# update waching list |
67
|
7
|
|
|
|
|
80
|
foreach(@new_files){ |
68
|
4
|
|
|
|
|
138
|
$$w_list{$_}=1; |
69
|
4
|
|
|
|
|
15
|
$self->monitor->watch($_); |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
# unwatch deleted files |
72
|
7
|
|
|
|
|
453
|
foreach(@deleted_files){ |
73
|
4
|
|
|
|
|
23
|
$self->monitor->unwatch($_); |
74
|
4
|
|
|
|
|
211
|
delete $$w_list{$_}; |
75
|
|
|
|
|
|
|
} |
76
|
7
|
|
|
|
|
26
|
$self->monitor->scan; |
77
|
|
|
|
|
|
|
# do a scan first before next check |
78
|
|
|
|
|
|
|
# else next check $self->monitor cannot find differences |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
81
|
7
|
|
|
|
|
1240
|
$self->{watch_list}=($w_list); |
82
|
7
|
|
|
|
|
24
|
$self->{created}= [@new_files]; |
83
|
7
|
|
|
|
|
22
|
$self->{modified}=[@modified_files]; |
84
|
7
|
|
|
|
|
65
|
$self->{observed}=[ keys %$w_list]; |
85
|
7
|
|
|
|
|
69
|
$self->{deleted}= [@deleted_files]; |
86
|
7
|
50
|
|
|
|
53
|
$self->{anychange}= ( |
87
|
|
|
|
|
|
|
scalar(@new_files)+ |
88
|
|
|
|
|
|
|
scalar(@modified_files)+ |
89
|
|
|
|
|
|
|
scalar(@deleted_files)) ? 1 : 0; |
90
|
|
|
|
|
|
|
|
91
|
7
|
|
|
|
|
158
|
1; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
sub created { |
94
|
7
|
|
|
7
|
1
|
17
|
my $self = shift; |
95
|
|
|
|
|
|
|
#return () unless @{$self->{created}}; |
96
|
7
|
|
|
|
|
12
|
return sort @{$self->{created}}; |
|
7
|
|
|
|
|
62
|
|
97
|
|
|
|
|
|
|
} |
98
|
|
|
|
|
|
|
sub modified { |
99
|
7
|
|
|
7
|
1
|
2258
|
my $self = shift; |
100
|
7
|
|
|
|
|
13
|
return sort @{$self->{modified}}; |
|
7
|
|
|
|
|
43
|
|
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
sub observed { |
103
|
7
|
|
|
7
|
1
|
2978
|
my $self = shift; |
104
|
7
|
|
|
|
|
17
|
return sort @{$self->{observed}}; |
|
7
|
|
|
|
|
65
|
|
105
|
|
|
|
|
|
|
} |
106
|
|
|
|
|
|
|
sub deleted { |
107
|
7
|
|
|
7
|
1
|
2337
|
my $self = shift; |
108
|
7
|
|
|
|
|
11
|
return sort @{$self->{deleted}}; |
|
7
|
|
|
|
|
64
|
|
109
|
|
|
|
|
|
|
} |
110
|
|
|
|
|
|
|
sub anychange{ |
111
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
112
|
0
|
|
|
|
|
|
return $self->{anychange}; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
# Preloaded methods go here. |
116
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
1; |
118
|
|
|
|
|
|
|
__END__ |