Add built local::lib
[catagits/Gitalist.git] / local-lib5 / lib / perl5 / File / ChangeNotify.pm
CommitLineData
3fea05b9 1package File::ChangeNotify;
2
3use strict;
4use warnings;
5
6our $VERSION = '0.11';
7
8use Carp qw( confess );
9use Class::MOP;
10use Module::Pluggable::Object;
11
12sub instantiate_watcher {
13 my $class = shift;
14
15 for my $class ( $class->usable_classes() ) {
16 if ( _try_load($class) ) {
17 return $class->new(@_);
18 }
19 }
20
21 die
22 "Could not load a File::ChangeNotify::Watcher subclass (this should not happen, something is badly broken)";
23}
24
25{
26 my @usable_classes = ();
27
28 sub usable_classes {
29 my $class = shift;
30
31 return @usable_classes if @usable_classes;
32 return @usable_classes = grep { _try_load($_) } $class->_all_classes();
33 }
34}
35
36sub _try_load {
37 my $class = shift;
38
39 eval { Class::MOP::load_class($class) };
40
41 my $e = $@;
42 die $e if $e && $e !~ /Can\'t locate|did not return a true value/;
43
44 return $e ? 0 : 1;
45}
46
47my $finder = Module::Pluggable::Object->new(
48 search_path => 'File::ChangeNotify::Watcher' );
49
50sub _all_classes {
51 return sort _sort_classes $finder->plugins();
52}
53
54sub _sort_classes {
55 $a eq 'File::ChangeNotify::Watcher::Default' ? 1
56 : $b eq 'File::ChangeNotify::Watcher::Default' ? -1
57 : $a cmp $b;
58}
59
601;
61
62__END__
63
64=pod
65
66=head1 NAME
67
68File::ChangeNotify - Watch for changes to files, cross-platform style
69
70=head1 SYNOPSIS
71
72 use File::ChangeNotify;
73
74 my $watcher =
75 File::ChangeNotify->instantiate_watcher
76 ( directories => [ '/my/path', '/my/other' ],
77 filter => qr/\.(?:pm|conf|yml)$/,
78 );
79
80 if ( my @events = $watcher->new_events() ) { ... }
81
82 # blocking
83 while ( my @events = $watcher->wait_for_events() ) { ... }
84
85=head1 DESCRIPTION
86
87This module provides an API for creating a
88L<File::ChangeNotify::Watcher> subclass that will work on your
89platform.
90
91Most of the documentation for this distro is in
92L<File::ChangeNotify::Watcher>.
93
94=head1 METHODS
95
96This class provides the following methods:
97
98=head2 File::ChangeNotify->instantiate_watcher(...)
99
100This method looks at each available subclass of
101L<File::ChangeNotify::Watcher> and instantiates the first one it can
102load, using the arguments you provided.
103
104It always tries to use the L<File::ChangeNotify::Watcher::Default>
105class last, on the assumption that any other class that is available
106is a better option.
107
108=head2 File::ChangeNotify->usable_classes()
109
110Returns a list of all the loadable L<File::ChangeNotify::Watcher>
111subclasses.
112
113=head1 DONATIONS
114
115If you'd like to thank me for the work I've done on this module,
116please consider making a "donation" to me via PayPal. I spend a lot of
117free time creating free software, and would appreciate any support
118you'd care to offer.
119
120Please note that B<I am not suggesting that you must do this> in order
121for me to continue working on this particular software. I will
122continue to do so, inasmuch as I have in the past, for as long as it
123interests me.
124
125Similarly, a donation made in this way will probably not make me work
126on this software much more, unless I get so many donations that I can
127consider working on free software full time, which seems unlikely at
128best.
129
130To donate, log into PayPal and send money to autarch@urth.org or use
131the button on this page:
132L<http://www.urth.org/~autarch/fs-donation.html>
133
134=head1 AUTHOR
135
136Dave Rolsky, E<lt>autarch@urth.orgE<gt>
137
138=head1 BUGS
139
140Please report any bugs or feature requests to
141C<bug-file-changenotify@rt.cpan.org>, or through the web interface at
142L<http://rt.cpan.org>. I will be notified, and then you'll
143automatically be notified of progress on your bug as I make changes.
144
145=head1 COPYRIGHT & LICENSE
146
147Copyright 2009 Dave Rolsky, All Rights Reserved.
148
149This program is free software; you can redistribute it and/or modify
150it under the same terms as Perl itself.
151
152=cut