File Coverage

blib/lib/Linux/Inotify/Event.pm
Criterion Covered Total %
statement 27 32 84.3
branch 1 2 50.0
condition n/a
subroutine 7 9 77.7
pod 0 4 0.0
total 35 47 74.4


line stmt bran cond sub pod time code
1             package Linux::Inotify::Event;
2              
3 1     1   4 use strict;
  1         1  
  1         24  
4 1     1   4 use warnings;
  1         1  
  1         110  
5              
6             sub new($$$) {
7 3     3 0 4 my $class = shift;
8 3         4 my $notifier = shift;
9 3         5 my $raw_event = shift;
10 3         7 my $self = { notifier => $notifier };
11 3         17 (my $wd, $self->{mask}, $self->{cookie}, $self->{len}) =
12             unpack 'iIII', $raw_event;
13 3         13 $self->{watch} = $notifier->find($wd);
14 3         18 $self->{name} = unpack 'Z*', substr($raw_event, 16, $self->{len});
15 1     1   4 use Linux::Inotify;
  1         1  
  1         188  
16 3 50       11 if ($self->{mask} & Linux::Inotify::DELETE_SELF) {
17 0         0 $self->{watch}->invalidate();
18             }
19 3         12 return bless $self, $class;
20             }
21              
22             sub fullname($) {
23 3     3 0 895 my $self = shift;
24 3         16 return $self->{watch}->{name} . '/' . $self->{name};
25             }
26              
27             sub add_watch($) {
28 0     0 0   my $self = shift;
29 0           return $self->{watch}->clone($self->fullname());
30             }
31              
32             my %reverse;
33              
34             INIT {
35 1     1   21 %reverse = (
36             0x00000001 => 'access',
37             0x00000002 => 'modify',
38             0x00000004 => 'attrib',
39             0x00000008 => 'close_write',
40             0x00000010 => 'close_nowrite',
41             0x00000020 => 'open',
42             0x00000040 => 'moved_from',
43             0x00000080 => 'moved_to',
44             0x00000100 => 'create',
45             0x00000200 => 'delete',
46             0x00000400 => 'delete_self',
47             0x00002000 => 'unmount',
48             0x00004000 => 'q_overflow',
49             0x00008000 => 'ignored',
50             );
51 1         8 my %reverse_copy = %reverse;
52 1         7 while(my ($key, $value) = each %reverse_copy) {
53 1     1   4 use Linux::Inotify;
  1         3  
  1         117  
54 14         66 $reverse{Linux::Inotify::ISDIR | $key} = "isdir | $value";
55             }
56             }
57              
58             sub print(%) {
59 0     0 0   my $self = shift;
60 0           printf "fd: %d, wd: %d, %21s, cookie: 0x%08x, len: %3d, name: '%s'\n",
61             $self->{notifier}->{fd}, $self->{watch}->{wd}, $reverse{$self->{mask}},
62             $self->{cookie}, $self->{len}, $self->fullname();
63             }
64              
65             1;
66