File Coverage

blib/lib/AnyEvent/Filesys/Watcher/Event.pm
Criterion Covered Total %
statement 23 35 65.7
branch 2 6 33.3
condition 6 12 50.0
subroutine 8 13 61.5
pod 10 10 100.0
total 49 76 64.4


line stmt bran cond sub pod time code
1             package AnyEvent::Filesys::Watcher::Event;
2              
3 18     18   148373 use strict;
  18         43  
  18         1257  
4              
5             our $VERSION = 'v0.1.1'; # VERSION
6              
7 18     18   776 use Locale::TextDomain ('AnyEvent-Filesys-Watcher');
  18         35348  
  18         182  
8              
9 18     18   45290 use Time::HiRes;
  18         39  
  18         187  
10              
11             sub new {
12 84     84 1 234621 my ($class, %args) = @_;
13              
14 84         334 my @required = qw(path type);
15 84         312 foreach my $required (@required) {
16 168 50       596 if (!exists $args{$required}) {
17 0         0 require Carp;
18 0         0 Carp::croak(
19             __x("Mandatory argument '{arg}' missing",
20             arg => $required)
21             );
22             }
23             }
24              
25 84 50 100     557 if ($args{type} ne 'created'
      66        
26             && $args{type} ne 'modified'
27             && $args{type} ne 'deleted') {
28 0         0 require Carp;
29             Carp::croak(
30             __x("Type must be one of 'created', 'modified', 'deleted' but"
31             . " not {type}",
32             type => $args{type})
33 0         0 );
34             }
35              
36 84   33     885 $args{timestamp} ||= Time::HiRes::gettimeofday();
37              
38 84         217 my $self = {};
39 84         340 foreach my $arg (keys %args) {
40 336         1061 $self->{'__' . $arg} = $args{$arg};
41             }
42              
43 84         578 bless $self, $class;
44             }
45              
46             sub path {
47 122     122 1 1787663 shift->{__path};
48             }
49              
50             sub type {
51 69     69 1 17119 shift->{__type};
52             }
53              
54             sub isDirectory {
55 123     123 1 1255 shift->{__is_directory};
56             }
57              
58             sub isCreated {
59 21     21 1 114 return 'created' eq shift->{__type};
60             }
61              
62             sub isModified {
63 0     0 1   return 'modified' eq shift->{__type};
64             }
65              
66             sub isDeleted {
67 0     0 1   return 'deleted' eq shift->{__type};
68             }
69              
70             sub id {
71 0     0 1   return shift->{__id};
72             }
73              
74             sub timestamp {
75 0     0 1   return shift->{__timestamp};
76             }
77              
78             sub cmp {
79 0     0 1   my ($self, $other) = @_;
80              
81 0 0         if (defined $self->{__id}) {
82             return $self->{__id} <=> $other->{__id}
83 0           }
84              
85             return ($self->{__timestamp}->[0] <=> $self->{__timestamp}->[1])
86 0   0       || ($self->{__timestamp}->[1] <=> $self->{__timestamp}->[1]);
87             }
88             1;