line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
#we need Event.pm |
2
|
1
|
|
|
1
|
|
1983
|
use Event; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
3
|
|
|
|
|
|
|
use IO::File; |
4
|
|
|
|
|
|
|
package Event::File; |
5
|
|
|
|
|
|
|
|
6
|
|
|
|
|
|
|
=head1 NAME |
7
|
|
|
|
|
|
|
|
8
|
|
|
|
|
|
|
Event::File is a wrapper module to write perl modules that deal with Files thru Event. |
9
|
|
|
|
|
|
|
It tries to mimics Event.pm model. |
10
|
|
|
|
|
|
|
|
11
|
|
|
|
|
|
|
=cut |
12
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
use strict; |
14
|
|
|
|
|
|
|
use vars qw($VERSION); |
15
|
|
|
|
|
|
|
$VERSION = '0.1.1'; |
16
|
|
|
|
|
|
|
|
17
|
|
|
|
|
|
|
#we clone this from Event |
18
|
|
|
|
|
|
|
sub _load_watcher { |
19
|
|
|
|
|
|
|
my $sub = shift; |
20
|
|
|
|
|
|
|
eval { require "Event/File/$sub.pm" }; |
21
|
|
|
|
|
|
|
die if $@; |
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
croak ("Event/File/$sub.pm did not define Event::File::$sub::new") |
24
|
|
|
|
|
|
|
unless defined &$sub; |
25
|
|
|
|
|
|
|
1; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
#we clone AUTOLOAD style from Event.pm |
29
|
|
|
|
|
|
|
sub AUTOLOAD { |
30
|
|
|
|
|
|
|
my $sub = ($Event::File::AUTOLOAD =~ /(\w+)$/)[0]; |
31
|
|
|
|
|
|
|
_load_watcher($sub) or croak $@ . ', Undefined subroutine &' . $sub; |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
goto &$sub; |
34
|
|
|
|
|
|
|
} |
35
|
|
|
|
|
|
|
|
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
#The register routine |
38
|
|
|
|
|
|
|
#this will turn Event::File::foo into Event::File->foo() == Event::File::foo->new(); |
39
|
|
|
|
|
|
|
sub register { |
40
|
|
|
|
|
|
|
no strict 'refs'; |
41
|
|
|
|
|
|
|
my $package = caller; |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
my $name = $package; |
44
|
|
|
|
|
|
|
$name =~ s/Event::File:://; |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
my $sub = \&{"$package\::new"}; |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
die "can't find $package\::new" |
49
|
|
|
|
|
|
|
if !$sub; |
50
|
|
|
|
|
|
|
*{"Event::File::".$name} = sub { |
51
|
|
|
|
|
|
|
shift; |
52
|
|
|
|
|
|
|
$sub->("Event::File::".$name, @_); |
53
|
|
|
|
|
|
|
}; |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
#no hooks |
56
|
|
|
|
|
|
|
#&Event::add_hooks if @_; |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
1; |
61
|
|
|
|
|
|
|
__END__ |