File Coverage

blib/lib/Linux/Inotify/Watch.pm
Criterion Covered Total %
statement 23 35 65.7
branch 1 8 12.5
condition n/a
subroutine 7 10 70.0
pod 0 4 0.0
total 31 57 54.3


line stmt bran cond sub pod time code
1             package Linux::Inotify::Watch;
2              
3 1     1   5 use strict;
  1         2  
  1         42  
4 1     1   5 use warnings;
  1         3  
  1         26  
5 1     1   4 use Carp;
  1         1  
  1         90  
6              
7             push our @CARP_NOT, 'Linux::Inotify';
8              
9             sub new($$$$) {
10 1     1 0 2 my $class = shift;
11 1         6 my $self = {
12             notifier => shift,
13             name => shift,
14             mask => shift,
15             valid => 1
16             };
17 1     1   5 use Linux::Inotify;
  1         1  
  1         109  
18 1         12 $self->{wd} = Linux::Inotify::syscall_add_watch($self->{notifier}->{fd},
19             $self->{name}, $self->{mask});
20 1 50       5 croak "Linux::Inotify::Watch::new() failed: $!" if $self->{wd} == -1;
21 1         5 return bless $self, $class;
22             }
23              
24             sub clone($$) {
25 0     0 0   my $source = shift;
26 0           my $target = {
27             notifier => $source->{notifier},
28             name => shift,
29             mask => $source->{mask},
30             valid => 1
31             };
32 1     1   5 use Linux::Inotify;
  1         1  
  1         146  
33 0           $target->{wd} = Linux::Inotify::syscall_add_watch($target->{notifier}->{fd},
34             $target->{name}, $target->{mask});
35 0 0         croak "Linux::Inotify::Watch::new() failed: $!" if $target->{wd} == -1;
36 0           return bless $target, ref($source);
37             }
38              
39             sub invalidate($) {
40 0     0 0   my $self = shift;
41 0           $self->{valid} = 0;
42             }
43              
44             sub remove($) {
45 0     0 0   my $self = shift;
46 0 0         if ($self->{valid}) {
47 0           $self->invalidate;
48 1     1   4 use Linux::Inotify;
  1         2  
  1         77  
49 0           my $ret = Linux::Inotify::syscall_rm_watch($self->{notifier}->{fd},
50             $self->{wd});
51 0 0         croak "Linux::Inotify::Watch::remove(wd = $self->{wd}) failed: $!" if
52             $ret == -1;
53             }
54             }
55              
56             1;
57