]> Sergey Matveev's repositories - public-inbox.git/blob - lib/PublicInbox/In2Tie.pm
7dee362724ea3002b500cc19a43a12b5bafe50e7
[public-inbox.git] / lib / PublicInbox / In2Tie.pm
1 # Copyright (C) 2020 all contributors <meta@public-inbox.org>
2 # License: AGPL-3.0+ <https://www.gnu.org/licenses/agpl-3.0.txt>
3
4 # used to ensure PublicInbox::DS can call fileno() as a function
5 # on Linux::Inotify2 objects
6 package PublicInbox::In2Tie;
7 use strict;
8 use Symbol qw(gensym);
9
10 sub io {
11         my $in2 = $_[0];
12         $in2->blocking(0);
13         if ($in2->can('on_overflow')) {
14                 # broadcasts everything on overflow
15                 $in2->on_overflow(undef);
16         }
17         my $io = gensym;
18         tie *$io, __PACKAGE__, $in2;
19         $io;
20 }
21
22 sub TIEHANDLE {
23         my ($class, $in2) = @_;
24         bless \$in2, $class; # a scalar reference to an existing reference
25 }
26
27 # this calls Linux::Inotify2::fileno
28 sub FILENO { ${$_[0]}->fileno }
29
30 1;