| 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.29'; | |||||||||||||
| 8 | |||||||||||||||
| 9 | 3 | ▶ | use File::ChangeNotify::Event; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 10 | 3 | ▶ | use Module::Runtime qw( use_module ); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 11 | 3 | ▶ | use Types::Standard qw( ArrayRef Bool ClassName CodeRef Num RegexpRef Str ); | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 12 | 3 | ▶ | use Type::Utils -all; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 13 | |||||||||||||||
| 14 | 3 | ▶ | use Moo::Role; | ||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||
| 15 | |||||||||||||||
| 16 | has filter => ( | ||||||||||||||
| 17 | is => 'ro', | ||||||||||||||
| 18 | isa => RegexpRef, | ||||||||||||||
| 19 | 13 | ▶ | default => sub {qr/.*/}, | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 20 | 3 | ); | |||||||||||||
| 21 | |||||||||||||||
| 22 | #<<< | ||||||||||||||
| 23 | my $dir_t = subtype as Str, | ||||||||||||||
| 24 | 17 | ▶ | where { -d $_ }, | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 25 | 0 | ▶ | message { "$_ is not a valid directory" }; | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||
| 26 | |||||||||||||||
| 27 | my $array_of_dirs_t = subtype as ArrayRef[Str], | ||||||||||||||
| 28 | where { | ||||||||||||||
| 29 | 21 | ▶ | map {-d} @{$_}; | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 30 | }, | ||||||||||||||
| 31 | 0 | ▶ | message {"@{$_} is not a list of valid directories"}; | ||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=2.6
| |||||||||||||||
| 32 | |||||||||||||||
| 33 | coerce $array_of_dirs_t, | ||||||||||||||
| 34 | from $dir_t, | ||||||||||||||
| 35 | 17 | ▶ | via { [$_] }; | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 36 | #>>> | ||||||||||||||
| 37 | |||||||||||||||
| 38 | 3 | has directories => ( | |||||||||||||
| 39 | is => 'ro', | ||||||||||||||
| 40 | writer => '_set_directories', | ||||||||||||||
| 41 | isa => $array_of_dirs_t, | ||||||||||||||
| 42 | required => 1, | ||||||||||||||
| 43 | coerce => 1, | ||||||||||||||
| 44 | ); | ||||||||||||||
| 45 | |||||||||||||||
| 46 | 3 | has follow_symlinks => ( | |||||||||||||
| 47 | is => 'ro', | ||||||||||||||
| 48 | isa => Bool, | ||||||||||||||
| 49 | default => 0, | ||||||||||||||
| 50 | ); | ||||||||||||||
| 51 | |||||||||||||||
| 52 | 3 | has event_class => ( | |||||||||||||
| 53 | is => 'ro', | ||||||||||||||
| 54 | isa => ClassName, | ||||||||||||||
| 55 | default => 'File::ChangeNotify::Event', | ||||||||||||||
| 56 | ); | ||||||||||||||
| 57 | |||||||||||||||
| 58 | 3 | has sleep_interval => ( | |||||||||||||
| 59 | is => 'ro', | ||||||||||||||
| 60 | isa => Num, | ||||||||||||||
| 61 | default => 2, | ||||||||||||||
| 62 | ); | ||||||||||||||
| 63 | |||||||||||||||
| 64 | 3 | my $files_or_regexps_or_code_t | |||||||||||||
| 65 | = subtype as ArrayRef [ Str | RegexpRef | CodeRef ]; | ||||||||||||||
| 66 | |||||||||||||||
| 67 | has exclude => ( | ||||||||||||||
| 68 | is => 'ro', | ||||||||||||||
| 69 | isa => $files_or_regexps_or_code_t, | ||||||||||||||
| 70 | 15 | ▶ | default => sub { [] }, | ||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||
| 71 | 3 | ); | |||||||||||||
| 72 | |||||||||||||||
| 73 | sub BUILD { | ||||||||||||||
| 74 | 0 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
BUILD: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||
| 75 | |||||||||||||||
| 76 | 0 | use_module( $self->event_class() ); | |||||||||||||
| 77 | } | ||||||||||||||
| 78 | |||||||||||||||
| 79 | sub new_events { | ||||||||||||||
| 80 | 13 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
new_events: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||
| 81 | |||||||||||||||
| 82 | 13 | return $self->_interesting_events(); | |||||||||||||
| 83 | } | ||||||||||||||
| 84 | |||||||||||||||
| 85 | ## no critic (Subroutines::ProhibitUnusedPrivateSubroutines) | ||||||||||||||
| 86 | sub _path_is_excluded { | ||||||||||||||
| 87 | 93 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
_path_is_excluded: called CC=8 SCAR=20.8
| |||||||||||||||
| 88 | 93 | my $path = shift; | |||||||||||||
| 89 | |||||||||||||||
| 90 | 93 | foreach my $excluded ( @{ $self->exclude } ) { | |||||||||||||
| 91 | 51 | ▶ | if ( my $ref = ref $excluded ) { | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 92 | 32 | ▶ | if ( $ref eq 'Regexp' ) { | ||||||||||||
|
Branch: 2 branches
| |||||||||||||||
| 93 | 29 | ▶ | return 1 if $path =~ /$excluded/; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 94 | } | ||||||||||||||
| 95 | elsif ( $ref eq 'CODE' ) { | ||||||||||||||
| 96 | 3 | local $_ = $path; | |||||||||||||
| 97 | 3 | ▶ | return 1 if $excluded->($path); | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 98 | } | ||||||||||||||
| 99 | } | ||||||||||||||
| 100 | else { | ||||||||||||||
| 101 | 19 | ▶ | return 1 if $path eq $excluded; | ||||||||||||
|
Branch: 1 branch
| |||||||||||||||
| 102 | } | ||||||||||||||
| 103 | } | ||||||||||||||
| 104 | |||||||||||||||
| 105 | 86 | return; | |||||||||||||
| 106 | } | ||||||||||||||
| 107 | |||||||||||||||
| 108 | sub _remove_directory { | ||||||||||||||
| 109 | 2 | ▶ | my $self = shift; | ||||||||||||
|
Subroutine
_remove_directory: called CC=1 SCAR=0.0
| |||||||||||||||
| 110 | 2 | my $dir = shift; | |||||||||||||
| 111 | |||||||||||||||
| 112 | $self->_set_directories( | ||||||||||||||
| 113 | 2 | [ grep { $_ ne $dir } @{ $self->directories() } ] ); | |||||||||||||
| 114 | } | ||||||||||||||
| 115 | ## use critic | ||||||||||||||
| 116 | |||||||||||||||
| 117 | 3 | 1; | |||||||||||||
| 118 | |||||||||||||||
| 119 | # ABSTRACT: Role consumed by all watchers | ||||||||||||||
| 120 | |||||||||||||||
| 121 | __END__ | ||||||||||||||