summaryrefslogtreecommitdiff
path: root/lib/Event/File.pm
blob: f5f7ad5cc0d709bd499d167407d9a3caf1edd7a0 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
#we need Event.pm
use Event;
use IO::File;
package Event::File;

=head1 NAME

Event::File is a wrapper module to write perl modules that deal with Files thru Event.
It tries to mimics Event.pm model.

=cut

use strict;
use vars qw($VERSION);
$VERSION = '0.1.1';

#we clone this from Event
sub _load_watcher {
  my $sub = shift;
  eval { require "Event/File/$sub.pm" };
  die if $@;

  croak ("Event/File/$sub.pm did not define Event::File::$sub::new")  
    unless defined &$sub;
  1;
}

#we clone AUTOLOAD style from Event.pm
sub AUTOLOAD {
  my $sub = ($Event::File::AUTOLOAD =~ /(\w+)$/)[0];    
  _load_watcher($sub) or croak $@ . ', Undefined subroutine &' . $sub;
  
  goto &$sub;
}


#The register routine
#this will turn Event::File::foo into  Event::File->foo() == Event::File::foo->new();
sub register {
  no strict 'refs';
  my $package = caller;
  
  my $name = $package;
  $name =~ s/Event::File:://;

  my $sub = \&{"$package\::new"};

  die "can't find $package\::new"
    if !$sub;
  *{"Event::File::".$name} = sub {
    shift;
    $sub->("Event::File::".$name, @_);
  };

  #no hooks
  #&Event::add_hooks if @_;
}


1;
__END__

=head1 Supported Events

Right now only Event::File->tail is supported.
For more information on it please refere to the Event::File::tail man page.

=head1 External Modules

This module makes use of 

=over

=item *

Event >= 0.80

=item *

IO::File

=back

=head1 SEE ALSO

Event(3), File::File::tail(3), cmc

=head1 AUTHOR

Raul Dias, <raul@dias.com.br>

=cut