| 1 | package File::ChangeNotify::Watcher; | ||||||||||||||||||||||||||||
| 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 Fcntl qw( S_IMODE ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 3 | ▶ | use File::ChangeNotify::Event; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 11 | 3 | ▶ | use File::Find qw( find ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 12 | 3 | ▶ | use File::Spec; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 13 | 3 | ▶ | use Module::Runtime qw( use_module ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 14 | use Types::Standard | ||||||||||||||||||||||||||||
| 15 | 3 | ▶ | qw( ArrayRef Bool ClassName CodeRef HashRef Num RegexpRef Str ); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 16 | 3 | ▶ | use Type::Utils -all; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||
| 18 | # Trying to import this just blows up on Win32, and checking | ||||||||||||||||||||||||||||
| 19 | # Time::HiRes::d_hires_stat() _also_ blows up on Win32. | ||||||||||||||||||||||||||||
| 20 | 3 | ▶ | BEGIN { | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 21 | ## no critic (ErrorHandling::RequireCheckingReturnValueOfEval) | ||||||||||||||||||||||||||||
| 22 | 3 | eval { | |||||||||||||||||||||||||||
| 23 | 3 | require Time::HiRes; | |||||||||||||||||||||||||||
| 24 | 3 | Time::HiRes->import('stat'); | |||||||||||||||||||||||||||
| 25 | }; | ||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||
| 28 | 3 | ▶ | use Moo::Role; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | has filter => ( | ||||||||||||||||||||||||||||
| 31 | is => 'ro', | ||||||||||||||||||||||||||||
| 32 | isa => RegexpRef, | ||||||||||||||||||||||||||||
| 33 | 21 | ▶ | default => sub {qr/.*/}, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 34 | 3 | ); | |||||||||||||||||||||||||||
| 35 | |||||||||||||||||||||||||||||
| 36 | #<<< | ||||||||||||||||||||||||||||
| 37 | my $dir_t = subtype as Str, | ||||||||||||||||||||||||||||
| 38 | 25 | ▶ | where { -d $_ }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 39 | 0 | ▶ | message { "$_ is not a valid directory" }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||
| 41 | my $array_of_dirs_t = subtype as ArrayRef[Str], | ||||||||||||||||||||||||||||
| 42 | 29 | ▶ | where { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 43 | 29 | map {-d} @{$_}; | |||||||||||||||||||||||||||
| 44 | }, | ||||||||||||||||||||||||||||
| 45 | 0 | ▶ | message {"@{$_} is not a list of valid directories"}; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.6
| |||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||
| 47 | coerce $array_of_dirs_t, | ||||||||||||||||||||||||||||
| 48 | from $dir_t, | ||||||||||||||||||||||||||||
| 49 | 25 | ▶ | via { [$_] }; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 50 | #>>> | ||||||||||||||||||||||||||||
| 51 | |||||||||||||||||||||||||||||
| 52 | 3 | has directories => ( | |||||||||||||||||||||||||||
| 53 | is => 'ro', | ||||||||||||||||||||||||||||
| 54 | writer => '_set_directories', | ||||||||||||||||||||||||||||
| 55 | isa => $array_of_dirs_t, | ||||||||||||||||||||||||||||
| 56 | required => 1, | ||||||||||||||||||||||||||||
| 57 | coerce => 1, | ||||||||||||||||||||||||||||
| 58 | ); | ||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||
| 60 | 3 | has follow_symlinks => ( | |||||||||||||||||||||||||||
| 61 | is => 'ro', | ||||||||||||||||||||||||||||
| 62 | isa => Bool, | ||||||||||||||||||||||||||||
| 63 | default => 0, | ||||||||||||||||||||||||||||
| 64 | ); | ||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||
| 66 | 3 | has event_class => ( | |||||||||||||||||||||||||||
| 67 | is => 'ro', | ||||||||||||||||||||||||||||
| 68 | isa => ClassName, | ||||||||||||||||||||||||||||
| 69 | default => 'File::ChangeNotify::Event', | ||||||||||||||||||||||||||||
| 70 | ); | ||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||
| 72 | 3 | has sleep_interval => ( | |||||||||||||||||||||||||||
| 73 | is => 'ro', | ||||||||||||||||||||||||||||
| 74 | isa => Num, | ||||||||||||||||||||||||||||
| 75 | default => 2, | ||||||||||||||||||||||||||||
| 76 | ); | ||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||
| 78 | 3 | my $files_or_regexps_or_code_t | |||||||||||||||||||||||||||
| 79 | = subtype as ArrayRef [ Str | RegexpRef | CodeRef ]; | ||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||
| 81 | has exclude => ( | ||||||||||||||||||||||||||||
| 82 | is => 'ro', | ||||||||||||||||||||||||||||
| 83 | isa => $files_or_regexps_or_code_t, | ||||||||||||||||||||||||||||
| 84 | 23 | ▶ | default => sub { [] }, | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 85 | 3 | ); | |||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||
| 87 | 3 | has modify_includes_file_attributes => ( | |||||||||||||||||||||||||||
| 88 | is => 'ro', | ||||||||||||||||||||||||||||
| 89 | isa => Bool | $files_or_regexps_or_code_t, | ||||||||||||||||||||||||||||
| 90 | default => 0, | ||||||||||||||||||||||||||||
| 91 | ); | ||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||
| 93 | 3 | has modify_includes_content => ( | |||||||||||||||||||||||||||
| 94 | is => 'ro', | ||||||||||||||||||||||||||||
| 95 | isa => Bool | $files_or_regexps_or_code_t, | ||||||||||||||||||||||||||||
| 96 | default => 0, | ||||||||||||||||||||||||||||
| 97 | ); | ||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||
| 99 | 3 | has _map => ( | |||||||||||||||||||||||||||
| 100 | is => 'ro', | ||||||||||||||||||||||||||||
| 101 | writer => '_set_map', | ||||||||||||||||||||||||||||
| 102 | isa => HashRef, | ||||||||||||||||||||||||||||
| 103 | predicate => '_has_map', | ||||||||||||||||||||||||||||
| 104 | ); | ||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 0 | ▶ | sub BUILD { | ||||||||||||||||||||||||||
|
Subroutine
BUILD: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 107 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 0 | use_module( $self->event_class ); | |||||||||||||||||||||||||||
| 110 | } | ||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | ## no critic ( Subroutines::ProhibitUnusedPrivateSubroutines) | ||||||||||||||||||||||||||||
| 113 | 54 | ▶ | sub _current_map { | ||||||||||||||||||||||||||
|
Subroutine
_current_map: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 114 | 54 | my $self = shift; | |||||||||||||||||||||||||||
| 115 | |||||||||||||||||||||||||||||
| 116 | 54 | my %map; | |||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | find( | ||||||||||||||||||||||||||||
| 119 | { | ||||||||||||||||||||||||||||
| 120 | 144 | ▶ | wanted => sub { | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||
| 122 | # File::Find seems to use '/' as the path separator on Windows | ||||||||||||||||||||||||||||
| 123 | # for some odd reason. It really should be using File::Spec | ||||||||||||||||||||||||||||
| 124 | # internally everywhere but it doesn't. | ||||||||||||||||||||||||||||
| 125 | 144 | ▶ | my $path | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 126 | = $^O eq 'MSWin32' | ||||||||||||||||||||||||||||
| 127 | ? File::Spec->canonpath($File::Find::name) | ||||||||||||||||||||||||||||
| 128 | : $File::Find::name; | ||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 144 | ▶ | if ( $self->_path_is_excluded($path) ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | 4 | $File::Find::prune = 1; | |||||||||||||||||||||||||||
| 132 | 4 | return; | |||||||||||||||||||||||||||
| 133 | } | ||||||||||||||||||||||||||||
| 134 | |||||||||||||||||||||||||||||
| 135 | 140 | ▶ | my $entry = $self->_entry_for_map($path) or return; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | 138 | $map{$path} = $entry; | |||||||||||||||||||||||||||
| 137 | }, | ||||||||||||||||||||||||||||
| 138 | follow_fast => ( $self->follow_symlinks ? 1 : 0 ), | ||||||||||||||||||||||||||||
| 139 | no_chdir => 1, | ||||||||||||||||||||||||||||
| 140 | follow_skip => 2, | ||||||||||||||||||||||||||||
| 141 | }, | ||||||||||||||||||||||||||||
| 142 | 54 | ▶ | @{ $self->directories }, | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 143 | ); | ||||||||||||||||||||||||||||
| 144 | |||||||||||||||||||||||||||||
| 145 | 54 | return \%map; | |||||||||||||||||||||||||||
| 146 | } | ||||||||||||||||||||||||||||
| 147 | ## use critic | ||||||||||||||||||||||||||||
| 148 | |||||||||||||||||||||||||||||
| 149 | 150 | ▶ | sub _path_is_excluded { | ||||||||||||||||||||||||||
|
Subroutine
_path_is_excluded: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 150 | 150 | my $self = shift; | |||||||||||||||||||||||||||
| 151 | 150 | my $path = shift; | |||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 150 | return $self->_path_matches( $self->exclude, $path ); | |||||||||||||||||||||||||||
| 154 | } | ||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||
| 156 | 140 | ▶ | sub _entry_for_map { | ||||||||||||||||||||||||||
|
Subroutine
_entry_for_map: called CC=8 SCAR=20.8
| |||||||||||||||||||||||||||||
| 157 | 140 | my $self = shift; | |||||||||||||||||||||||||||
| 158 | 140 | my $path = shift; | |||||||||||||||||||||||||||
| 159 | |||||||||||||||||||||||||||||
| 160 | 140 | ▶ | my $is_dir = -d $path ? 1 : 0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 161 | |||||||||||||||||||||||||||||
| 162 | # This should be free since the stat call was already done when checking | ||||||||||||||||||||||||||||
| 163 | # -d. | ||||||||||||||||||||||||||||
| 164 | 140 | my @stat = stat; | |||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 140 | ▶ | return if -l $path && !$is_dir; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
-l $path and not $is_dir
MC/DC100%2/2
-l $path and not $is_dir
-l $path
not $is_dir
Truth table100%3/3
A and not(B)
A= -l $pathB= not $is_dir
| |||||||||||||||||||||||||||||
| 167 | |||||||||||||||||||||||||||||
| 168 | 138 | ▶ | unless ($is_dir) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 169 | 56 | my $filter = $self->filter; | |||||||||||||||||||||||||||
| 170 | 56 | ▶ | return unless ( File::Spec->splitpath($path) )[2] =~ /$filter/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 171 | } | ||||||||||||||||||||||||||||
| 172 | |||||||||||||||||||||||||||||
| 173 | return { | ||||||||||||||||||||||||||||
| 174 | 138 | ▶ | is_dir => $is_dir, | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 175 | size => ( $is_dir ? 0 : $stat[7] ), | ||||||||||||||||||||||||||||
| 176 | $self->_maybe_file_attributes( $path, \@stat ), | ||||||||||||||||||||||||||||
| 177 | ( $is_dir ? () : $self->_maybe_content($path) ), | ||||||||||||||||||||||||||||
| 178 | }; | ||||||||||||||||||||||||||||
| 179 | } | ||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||
| 181 | 138 | ▶ | sub _maybe_file_attributes { | ||||||||||||||||||||||||||
|
Subroutine
_maybe_file_attributes: called CC=3 SCAR=12.7
| |||||||||||||||||||||||||||||
| 182 | 138 | my $self = shift; | |||||||||||||||||||||||||||
| 183 | 138 | my $path = shift; | |||||||||||||||||||||||||||
| 184 | 138 | my $stat = shift; | |||||||||||||||||||||||||||
| 185 | |||||||||||||||||||||||||||||
| 186 | # The Default watcher always requires the mtime, regardless of whether or | ||||||||||||||||||||||||||||
| 187 | # not we're including stat info in the modify events. | ||||||||||||||||||||||||||||
| 188 | 138 | ▶ | unless ( $self->_always_requires_mtime ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 189 | return | ||||||||||||||||||||||||||||
| 190 | 0 | ▶ | unless $self->_path_matches( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 191 | $self->modify_includes_file_attributes, | ||||||||||||||||||||||||||||
| 192 | $path, | ||||||||||||||||||||||||||||
| 193 | ); | ||||||||||||||||||||||||||||
| 194 | } | ||||||||||||||||||||||||||||
| 195 | |||||||||||||||||||||||||||||
| 196 | 138 | return ( stat => $self->_stat( $path, $stat ) ); | |||||||||||||||||||||||||||
| 197 | } | ||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||
| 199 | 138 | ▶ | sub _stat { | ||||||||||||||||||||||||||
|
Subroutine
_stat: called CC=2 SCAR=7.0
| |||||||||||||||||||||||||||||
| 200 | 138 | my $self = shift; | |||||||||||||||||||||||||||
| 201 | 138 | my $path = shift; | |||||||||||||||||||||||||||
| 202 | 138 | my $stat = shift; | |||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||
| 204 | 138 | ▶ | my @stat = $stat ? @{$stat} : stat $path; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 205 | return { | ||||||||||||||||||||||||||||
| 206 | 138 | attributes => { | |||||||||||||||||||||||||||
| 207 | permissions => S_IMODE( $stat[2] ), | ||||||||||||||||||||||||||||
| 208 | uid => $stat[4], | ||||||||||||||||||||||||||||
| 209 | gid => $stat[5], | ||||||||||||||||||||||||||||
| 210 | }, | ||||||||||||||||||||||||||||
| 211 | mtime => $stat[9], | ||||||||||||||||||||||||||||
| 212 | }; | ||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||
| 214 | |||||||||||||||||||||||||||||
| 215 | 0 | ▶ | sub _always_requires_mtime {0} | ||||||||||||||||||||||||||
|
Subroutine
_always_requires_mtime: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 216 | |||||||||||||||||||||||||||||
| 217 | 56 | ▶ | sub _maybe_content { | ||||||||||||||||||||||||||
|
Subroutine
_maybe_content: called CC=5 SCAR=16.3
| |||||||||||||||||||||||||||||
| 218 | 56 | my $self = shift; | |||||||||||||||||||||||||||
| 219 | 56 | my $path = shift; | |||||||||||||||||||||||||||
| 220 | |||||||||||||||||||||||||||||
| 221 | return | ||||||||||||||||||||||||||||
| 222 | 56 | ▶ | unless $self->_path_matches( $self->modify_includes_content, $path ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 223 | |||||||||||||||||||||||||||||
| 224 | 8 | ▶ | open my $fh, '<', $path or die "Cannot open $path for reading: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 225 | 8 | ▶ | binmode $fh, ':bytes' or die qq{Cannot binmode $path as ':bytes': $!}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 226 | 8 | my $content = do { | |||||||||||||||||||||||||||
| 227 | 8 | local $/ = undef; | |||||||||||||||||||||||||||
| 228 | 8 | <$fh>; | |||||||||||||||||||||||||||
| 229 | }; | ||||||||||||||||||||||||||||
| 230 | 8 | ▶ | close $fh or die "Cannot close $path: $!"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 231 | |||||||||||||||||||||||||||||
| 232 | 8 | return ( content => $content ); | |||||||||||||||||||||||||||
| 233 | } | ||||||||||||||||||||||||||||
| 234 | |||||||||||||||||||||||||||||
| 235 | 17 | ▶ | sub new_events { | ||||||||||||||||||||||||||
|
Subroutine
new_events: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 236 | 17 | my $self = shift; | |||||||||||||||||||||||||||
| 237 | |||||||||||||||||||||||||||||
| 238 | 17 | return $self->_interesting_events; | |||||||||||||||||||||||||||
| 239 | } | ||||||||||||||||||||||||||||
| 240 | |||||||||||||||||||||||||||||
| 241 | ## no critic ( Subroutines::ProhibitUnusedPrivateSubroutines) | ||||||||||||||||||||||||||||
| 242 | 47 | ▶ | sub _modify_event_maybe_file_attribute_changes { | ||||||||||||||||||||||||||
|
Subroutine
_modify_event_maybe_file_attribute_changes: called CC=4 SCAR=13.9
| |||||||||||||||||||||||||||||
| 243 | 47 | my $self = shift; | |||||||||||||||||||||||||||
| 244 | 47 | my $path = shift; | |||||||||||||||||||||||||||
| 245 | 47 | my $old_map = shift; | |||||||||||||||||||||||||||
| 246 | 47 | my $new_map = shift; | |||||||||||||||||||||||||||
| 247 | |||||||||||||||||||||||||||||
| 248 | return | ||||||||||||||||||||||||||||
| 249 | 47 | ▶ | unless $self->_path_matches( | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 250 | $self->modify_includes_file_attributes, | ||||||||||||||||||||||||||||
| 251 | $path, | ||||||||||||||||||||||||||||
| 252 | ); | ||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||
| 254 | 8 | my $old_attr = $old_map->{$path}{stat}{attributes}; | |||||||||||||||||||||||||||
| 255 | 8 | my $new_attr = $new_map->{$path}{stat}{attributes}; | |||||||||||||||||||||||||||
| 256 | |||||||||||||||||||||||||||||
| 257 | 8 | for my $k ( keys %{$new_attr} ) { | |||||||||||||||||||||||||||
| 258 | |||||||||||||||||||||||||||||
| 259 | # Any possible info retrieved from stat will be numeric, so we can | ||||||||||||||||||||||||||||
| 260 | # always use numeric comparison safely. | ||||||||||||||||||||||||||||
| 261 | return ( attributes => [ $old_attr, $new_attr ] ) | ||||||||||||||||||||||||||||
| 262 | 20 | ▶ | if $old_attr->{$k} != $new_attr->{$k}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 263 | } | ||||||||||||||||||||||||||||
| 264 | |||||||||||||||||||||||||||||
| 265 | 4 | return; | |||||||||||||||||||||||||||
| 266 | } | ||||||||||||||||||||||||||||
| 267 | |||||||||||||||||||||||||||||
| 268 | 14 | ▶ | sub _modify_event_maybe_content_changes { | ||||||||||||||||||||||||||
|
Subroutine
_modify_event_maybe_content_changes: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||
| 269 | 14 | my $self = shift; | |||||||||||||||||||||||||||
| 270 | 14 | my $path = shift; | |||||||||||||||||||||||||||
| 271 | 14 | my $old_map = shift; | |||||||||||||||||||||||||||
| 272 | 14 | my $new_map = shift; | |||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||
| 274 | return | ||||||||||||||||||||||||||||
| 275 | 14 | ▶ | unless $self->_path_matches( $self->modify_includes_content, $path ); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 276 | return ( | ||||||||||||||||||||||||||||
| 277 | 4 | content => [ $old_map->{$path}{content}, $new_map->{$path}{content} ] | |||||||||||||||||||||||||||
| 278 | ); | ||||||||||||||||||||||||||||
| 279 | } | ||||||||||||||||||||||||||||
| 280 | |||||||||||||||||||||||||||||
| 281 | 267 | ▶ | sub _path_matches { | ||||||||||||||||||||||||||
|
Subroutine
_path_matches: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||
| 282 | 267 | my $self = shift; | |||||||||||||||||||||||||||
| 283 | 267 | my $matches = shift; | |||||||||||||||||||||||||||
| 284 | 267 | my $path = shift; | |||||||||||||||||||||||||||
| 285 | |||||||||||||||||||||||||||||
| 286 | 267 | ▶ | return $matches if !ref $matches; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||
| 288 | 172 | foreach my $matcher ( @{$matches} ) { | |||||||||||||||||||||||||||
| 289 | 73 | ▶ | if ( my $ref = ref $matcher ) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 290 | 54 | ▶ | if ( $ref eq 'Regexp' ) { | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 291 | 51 | ▶ | return 1 if $path =~ /$matcher/; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||
| 293 | elsif ( $ref eq 'CODE' ) { | ||||||||||||||||||||||||||||
| 294 | 3 | local $_ = $path; | |||||||||||||||||||||||||||
| 295 | 3 | ▶ | return 1 if $matcher->($path); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 296 | } | ||||||||||||||||||||||||||||
| 297 | } | ||||||||||||||||||||||||||||
| 298 | else { | ||||||||||||||||||||||||||||
| 299 | 19 | ▶ | return 1 if $path eq $matcher; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||
| 301 | } | ||||||||||||||||||||||||||||
| 302 | |||||||||||||||||||||||||||||
| 303 | 155 | return; | |||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||
| 305 | |||||||||||||||||||||||||||||
| 306 | 2 | ▶ | sub _remove_directory { | ||||||||||||||||||||||||||
|
Subroutine
_remove_directory: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 307 | 2 | my $self = shift; | |||||||||||||||||||||||||||
| 308 | 2 | my $dir = shift; | |||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||
| 310 | $self->_set_directories( | ||||||||||||||||||||||||||||
| 311 | 2 | [ grep { $_ ne $dir } @{ $self->directories } ] ); | |||||||||||||||||||||||||||
| 312 | } | ||||||||||||||||||||||||||||
| 313 | ## use critic | ||||||||||||||||||||||||||||
| 314 | |||||||||||||||||||||||||||||
| 315 | 3 | 1; | |||||||||||||||||||||||||||
| 316 | |||||||||||||||||||||||||||||
| 317 | # ABSTRACT: Role consumed by all watchers | ||||||||||||||||||||||||||||
| 318 | |||||||||||||||||||||||||||||
| 319 | __END__ | ||||||||||||||||||||||||||||