File Coverage

blib/lib/Linux/Inotify/Watch.pm
Criterion Covered Total %
statement 15 29 51.7
branch 1 8 12.5
condition n/a
subroutine 4 7 57.1
pod 0 4 0.0
total 20 48 41.6


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