our
$VERSION
=
'0.3.3'
;
sub
check {
my
(
$self
,
$inputs
) =
@_
;
my
$config
=
$inputs
->{config};
my
$cache
=
$inputs
->{cache};
my
$directory
=
$config
->{path};
unless
( -d
$directory
) {
my
$subject
=
"Error: directory not found: $directory"
;
$self
->logger->error(
$self
->key .
": $subject"
);
return
{
cache
=>
$cache
,
react
=> {
subject
=>
$subject
} };
}
my
@react
;
my
$dir_h
;
opendir
(
$dir_h
,
$directory
) or
die
"Can't opendir $directory: $!"
;
ENTRY:
while
(
defined
(
my
$entry
=
readdir
(
$dir_h
) ) ) {
next
unless
$entry
;
if
(
$entry
eq
"."
||
$entry
eq
".."
) {
next
}
if
(
$self
->cache_is_seen(
$cache
,
$entry
) ) {
$self
->logger->trace(
"Already seen: "
,
$entry
);
$self
->cache_mark_seen(
$cache
,
$entry
);
next
ENTRY;
}
$self
->cache_mark_seen(
$cache
,
$entry
);
push
@react
, {
file
=>
$entry
,
subject
=>
"New: $entry"
};
}
$self
->cache_expire(
$cache
);
return
{
cache
=>
$cache
,
react
=> \
@react
};
}
__PACKAGE__->meta->make_immutable;
1;