File Coverage

blib/lib/Linux/Inotify/Event.pm
Criterion Covered Total %
statement 20 25 80.0
branch 1 2 50.0
condition n/a
subroutine 5 7 71.4
pod 0 4 0.0
total 26 38 68.4


line stmt bran cond sub pod time code
1             package Linux::Inotify::Event;
2              
3 1     1   9 use strict;
  1         2  
  1         41  
4 1     1   6 use warnings;
  1         2  
  1         56  
5 1     1   7 use Linux::Inotify;
  1         1  
  1         1246  
6              
7             # ABSTRACT: Event class for Linux::Inotify
8             our $VERSION = '0.06'; # VERSION
9              
10             sub new {
11 3     3 0 5 my $class = shift;
12 3         19 my $notifier = shift;
13 3         32 my $raw_event = shift;
14 3         10 my $self = { notifier => $notifier };
15 3         21 (my $wd, $self->{mask}, $self->{cookie}, $self->{len}) =
16             unpack 'iIII', $raw_event;
17 3         11 $self->{watch} = $notifier->find($wd);
18 3         16 $self->{name} = unpack 'Z*', substr($raw_event, 16, $self->{len});
19 3 50       12 if ($self->{mask} & Linux::Inotify::DELETE_SELF) {
20 0         0 $self->{watch}->invalidate();
21             }
22 3         10 return bless $self, $class;
23             }
24              
25             sub fullname {
26 3     3 0 1540 my $self = shift;
27 3         19 return $self->{watch}->{name} . '/' . $self->{name};
28             }
29              
30             sub add_watch {
31 0     0 0   my $self = shift;
32 0           return $self->{watch}->clone($self->fullname());
33             }
34              
35             my %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             my %reverse_copy = %reverse;
52             while(my ($key, $value) = each %reverse_copy) {
53             $reverse{Linux::Inotify::ISDIR | $key} = "isdir | $value";
54             }
55              
56             sub print {
57 0     0 0   my $self = shift;
58             printf "fd: %d, wd: %d, %21s, cookie: 0x%08x, len: %3d, name: '%s'\n",
59             $self->{notifier}->{fd}, $self->{watch}->{wd}, $reverse{$self->{mask}},
60 0           $self->{cookie}, $self->{len}, $self->fullname();
61             }
62              
63             1;
64              
65             __END__