line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package File::Monitor::Base; |
2
|
6
|
|
|
6
|
|
36
|
use strict; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
182
|
|
3
|
6
|
|
|
6
|
|
31
|
use warnings; |
|
6
|
|
|
|
|
11
|
|
|
6
|
|
|
|
|
136
|
|
4
|
6
|
|
|
6
|
|
30
|
use Carp; |
|
6
|
|
|
|
|
128
|
|
|
6
|
|
|
|
|
579
|
|
5
|
6
|
|
|
6
|
|
33
|
use File::Spec; |
|
6
|
|
|
|
|
9
|
|
|
6
|
|
|
|
|
2800
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our $VERSION = '1.00'; |
8
|
|
|
|
|
|
|
|
9
|
|
|
|
|
|
|
sub new { |
10
|
369
|
|
|
369
|
0
|
19921
|
my $class = shift; |
11
|
369
|
|
|
|
|
975
|
my $self = bless {}, $class; |
12
|
369
|
|
|
|
|
1553
|
$self->_initialize( @_ ); |
13
|
367
|
|
|
|
|
27746
|
return $self; |
14
|
|
|
|
|
|
|
} |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub _report_extra { |
17
|
367
|
|
|
367
|
|
667
|
my $self = shift; |
18
|
367
|
|
|
|
|
417
|
my $args = shift; |
19
|
367
|
|
|
|
|
825
|
my @extra = keys %$args; |
20
|
367
|
50
|
|
|
|
1597
|
croak "The following options are not recognised: ", |
21
|
|
|
|
|
|
|
join( ' ', sort @extra ) |
22
|
|
|
|
|
|
|
if @extra; |
23
|
|
|
|
|
|
|
} |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
sub _initialize { |
26
|
369
|
|
|
369
|
|
850
|
my $self = shift; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
sub _install_callbacks { |
30
|
36
|
|
|
36
|
|
203
|
my $self = shift; |
31
|
36
|
|
|
|
|
62
|
my $args = shift; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
# Install callbacks |
34
|
36
|
100
|
|
|
|
394
|
if ( my $callback = delete $args->{callback} ) { |
35
|
14
|
50
|
|
|
|
48
|
if ( ref $callback eq 'CODE' ) { |
|
|
50
|
|
|
|
|
|
36
|
0
|
|
|
|
|
0
|
$self->callback( 'change', $callback ); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
elsif ( ref $callback eq 'HASH' ) { |
39
|
14
|
|
|
|
|
61
|
while ( my ( $event, $cb ) = each %$callback ) { |
40
|
210
|
|
|
|
|
409
|
$self->callback( $event, $cb ); |
41
|
|
|
|
|
|
|
} |
42
|
|
|
|
|
|
|
} |
43
|
|
|
|
|
|
|
else { |
44
|
0
|
|
|
|
|
0
|
croak "A callback must be a code reference " |
45
|
|
|
|
|
|
|
. "or a hash of code references"; |
46
|
|
|
|
|
|
|
} |
47
|
|
|
|
|
|
|
} |
48
|
|
|
|
|
|
|
} |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
sub _make_callbacks { |
51
|
84
|
|
|
84
|
|
160
|
my $self = shift; |
52
|
84
|
|
|
|
|
103
|
my $change = shift; |
53
|
84
|
|
|
|
|
355
|
$change->_trigger_callbacks( $self->{_callbacks} ); |
54
|
|
|
|
|
|
|
} |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
sub callback { |
57
|
210
|
|
|
210
|
0
|
224
|
my $self = shift; |
58
|
210
|
|
|
|
|
224
|
my $event = shift; |
59
|
210
|
|
|
|
|
261
|
my $code = shift; |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
# Allow event to be omitted |
62
|
210
|
50
|
33
|
|
|
11456
|
if ( ref $event eq 'CODE' && !defined $code ) { |
63
|
0
|
|
|
|
|
0
|
( $code, $event ) = ( $event, 'changed' ); |
64
|
|
|
|
|
|
|
} |
65
|
|
|
|
|
|
|
|
66
|
210
|
50
|
|
|
|
420
|
croak "Callback must be a code references" |
67
|
|
|
|
|
|
|
unless ref $code eq 'CODE'; |
68
|
|
|
|
|
|
|
|
69
|
210
|
|
|
|
|
1346
|
$self->{_callbacks}->{$event} = $code; |
70
|
|
|
|
|
|
|
} |
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
1; |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
=head1 NAME |
75
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
File::Monitor::Base - Common base class for file monitoring. |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
=head1 VERSION |
79
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
This document describes File::Monitor::Base version 1.00 |
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
=head1 DESCRIPTION |
83
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
Don't use this class directly. See L and |
85
|
|
|
|
|
|
|
L for the public interface. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
=head1 AUTHOR |
88
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
Andy Armstrong C<< >> |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
Faycal Chraibi originally registered the File::Monitor namespace and |
92
|
|
|
|
|
|
|
then kindly handed it to me. |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 LICENCE AND COPYRIGHT |
95
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
Copyright (c) 2007, Andy Armstrong C<< >>. All rights reserved. |
97
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
This module is free software; you can redistribute it and/or |
99
|
|
|
|
|
|
|
modify it under the same terms as Perl itself. See L. |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=head1 DISCLAIMER OF WARRANTY |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
BECAUSE THIS SOFTWARE IS LICENSED FREE OF CHARGE, THERE IS NO WARRANTY |
104
|
|
|
|
|
|
|
FOR THE SOFTWARE, TO THE EXTENT PERMITTED BY APPLICABLE LAW. EXCEPT WHEN |
105
|
|
|
|
|
|
|
OTHERWISE STATED IN WRITING THE COPYRIGHT HOLDERS AND/OR OTHER PARTIES |
106
|
|
|
|
|
|
|
PROVIDE THE SOFTWARE "AS IS" WITHOUT WARRANTY OF ANY KIND, EITHER |
107
|
|
|
|
|
|
|
EXPRESSED OR IMPLIED, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED |
108
|
|
|
|
|
|
|
WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. THE |
109
|
|
|
|
|
|
|
ENTIRE RISK AS TO THE QUALITY AND PERFORMANCE OF THE SOFTWARE IS WITH |
110
|
|
|
|
|
|
|
YOU. SHOULD THE SOFTWARE PROVE DEFECTIVE, YOU ASSUME THE COST OF ALL |
111
|
|
|
|
|
|
|
NECESSARY SERVICING, REPAIR, OR CORRECTION. |
112
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
IN NO EVENT UNLESS REQUIRED BY APPLICABLE LAW OR AGREED TO IN WRITING |
114
|
|
|
|
|
|
|
WILL ANY COPYRIGHT HOLDER, OR ANY OTHER PARTY WHO MAY MODIFY AND/OR |
115
|
|
|
|
|
|
|
REDISTRIBUTE THE SOFTWARE AS PERMITTED BY THE ABOVE LICENCE, BE |
116
|
|
|
|
|
|
|
LIABLE TO YOU FOR DAMAGES, INCLUDING ANY GENERAL, SPECIAL, INCIDENTAL, |
117
|
|
|
|
|
|
|
OR CONSEQUENTIAL DAMAGES ARISING OUT OF THE USE OR INABILITY TO USE |
118
|
|
|
|
|
|
|
THE SOFTWARE (INCLUDING BUT NOT LIMITED TO LOSS OF DATA OR DATA BEING |
119
|
|
|
|
|
|
|
RENDERED INACCURATE OR LOSSES SUSTAINED BY YOU OR THIRD PARTIES OR A |
120
|
|
|
|
|
|
|
FAILURE OF THE SOFTWARE TO OPERATE WITH ANY OTHER SOFTWARE), EVEN IF |
121
|
|
|
|
|
|
|
SUCH HOLDER OR OTHER PARTY HAS BEEN ADVISED OF THE POSSIBILITY OF |
122
|
|
|
|
|
|
|
SUCH DAMAGES. |