ChangeNotify/Watcher/Default.pm

filter: Statementstmt 98.2% 57 / 58 Branchbran 91.6% 11 / 12 Conditioncond 83.3% 5 / 6 MC/DCmcdc 66.6% 2 / 3 Subroutinesub 100% 11 / 11 Podpod 0.0% 0 / 3 totaltotal 92.4% 86 / 93 CC 11 SCAR 12.5
CC
11
Cov
96%
_interesting_events
6.0
_path_was_modified
5.0
wait_for_events
2.1
CRAP 3.5
« ChangeNotify/Watcher.pm ↑ Summary ChangeNotify.pm »
1 package File::ChangeNotify::Watcher::Default;
2  
3 3 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 3 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 3 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 3 our $VERSION = '0.31';
8  
9 3 ▶use Time::HiRes qw( sleep );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 3 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 3 with 'File::ChangeNotify::Watcher';
14  
15 4 ▶sub sees_all_events {0}
Subroutine sees_all_events: called CC=1 SCAR=0.0
Pod undocumented
16  
17 ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines)
18 138 ▶sub _always_requires_mtime {1}
Subroutine _always_requires_mtime: called CC=1 SCAR=0.0
19 ## use critic
20  
21 25 ▶sub BUILD {
Subroutine BUILD: called CC=1 SCAR=0.0
Pod undocumented
22 25 my $self = shift;
23  
24 25 $self->_set_map( $self->_current_map );
25  
26 25 return;
27 }
28  
29 12 ▶sub wait_for_events {
Subroutine wait_for_events: called CC=2 SCAR=7.4
Pod undocumented
30 12 my $self = shift;
31  
32 12 while (1) {
33 12 my @events = $self->_interesting_events;
34 12 ▶ return @events if @events;
Branch: 1 branch
BranchTrueFalseTotal
if @events 12 0 12
35  
36 0 sleep $self->sleep_interval;
37 }
38 }
39  
40 29 ▶sub _interesting_events {
Subroutine _interesting_events: called CC=6 SCAR=17.9
41 29 my $self = shift;
42  
43 29 my @interesting;
44  
45 29 my $old_map = $self->_map;
46 29 my $new_map = $self->_current_map;
47  
48 29 for my $path ( sort keys %{$old_map} ) {
49 63 ▶ if ( !exists $new_map->{$path} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not exists $new_map->{$path}) { } 6 57 63
50 6 ▶ if ( $old_map->{$path}{is_dir} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($old_map->{$path}{"is_dir"}) 2 4 6
51 2 $self->_remove_directory($path);
52 }
53  
54 6 push @interesting, $self->event_class->new(
55 path => $path,
56 type => 'delete',
57 );
58 }
59 else {
60 # If we're tracking stat info changes then we get the old & new
61 # stat info back in @extra. No need to stat the path _again_.
62 57 my ( $modified, @extra )
63 = $self->_path_was_modified( $path, $old_map, $new_map );
64 57 ▶ if ($modified) {
Branch: 1 branch
BranchTrueFalseTotal
if ($modified) 14 43 57
65 14 push @interesting, $self->event_class->new(
66 path => $path,
67 type => 'modify',
68 @extra,
69 $self->_modify_event_maybe_content_changes(
70 $path, $old_map, $new_map
71 ),
72 );
73 }
74 }
75 }
76  
77 29 for my $path ( sort grep { !exists $old_map->{$_} } keys %{$new_map} ) {
78 14 push @interesting, $self->event_class->new(
79 path => $path,
80 type => 'create',
81 );
82 }
83  
84 29 $self->_set_map($new_map);
85  
86 29 return @interesting;
87 }
88  
89 57 ▶sub _path_was_modified {
Subroutine _path_was_modified: called CC=5 SCAR=16.1
90 57 my $self = shift;
91 57 my $path = shift;
92 57 my $old_map = shift;
93 57 my $new_map = shift;
94  
95 57 my $old_entry = $old_map->{$path};
96 57 my $new_entry = $new_map->{$path};
97  
98 # If it's a file and the mtime or size changed we know it's been modified
99 # in some way.
100 return 1
101 if !$old_entry->{is_dir}
102 && ( $old_entry->{stat}{mtime} != $new_entry->{stat}{mtime}
103 57 ▶ || $old_entry->{size} != $new_entry->{size} );
Branch: 1 branch
BranchTrueFalseTotal
if not $old_entry->{"is_dir"} and $old_entry->{"stat"}{"mtime"} != $new_entry->{"stat"}{"mtime"} || $old_entry->{"size"} != $new_entry->{"size"} 10 47 57
Condition83%5/6
not $old_entry->{"is_dir"} and $old_entry->{"stat"}{"mtime"} != $new_entry->{"stat"}{"mtime"} || $old_entry->{"size"} != $new_entry->{"size"}
!ll&&!rl&&r
39810
$old_entry->{"stat"}{"mtime"} != $new_entry->{"stat"}{"mtime"} or $old_entry->{"size"} != $new_entry->{"size"}
l!l&&r!l&&!r
1008
MC/DC66%2/3
not $old_entry->{"is_dir"} and $old_entry->{"stat"}{"mtime"} != $new_entry->{"stat"}{"mtime"} || $old_entry->{"size"} != $new_entry->{"size"}
not $old_entry->{"is_dir"} $old_entry->{"stat"}{"mtime"} != $new_entry->{"stat"}{"mtime"} $old_entry->{"size"} != $new_entry->{"size"}
Truth table75%3/4
not(A) and B or C
A= not $old_entry->{"is_dir"}B= $old_entry->{"stat"}{"mtime"} != $new_entry->{"stat"}{"mtime"}C= $old_entry->{"size"} != $new_entry->{"size"}
ABCresult
0XX0
1000
11X1
1011
104  
105 47 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (my(@attrs) = $self->_modify_event_maybe_file_attribute_changes($path, $old_map, $new_map)) 4 43 47
106 my @attrs = $self->_modify_event_maybe_file_attribute_changes(
107 $path, $old_map, $new_map
108 )
109 ) {
110  
111 4 return ( 1, @attrs );
112 }
113  
114 43 return 0;
115 }
116  
117 3 __PACKAGE__->meta->make_immutable;
118  
119 3 1;
120  
121 # ABSTRACT: Fallback default watcher subclass
122  
123 __END__
« ChangeNotify/Watcher.pm ↑ Summary ChangeNotify.pm »