« blib/lib/App/Netdisco/Worker/Plugin/CheckEncoding.pm
↑ Summary
blib/lib/App/Netdisco/Worker/Plugin/Contact.pm »
| 1 | package App::Netdisco::Worker::Plugin::CheckSiteLocal; | ||
| 2 | |||
| 3 | use Dancer ':syntax'; | ||
| 4 | use App::Netdisco::Worker::Plugin; | ||
| 5 | use aliased 'App::Netdisco::Worker::Status'; | ||
| 6 | |||
| 7 | use App::Netdisco::Util::SiteLocal | ||
| 8 | qw/ site_local_paths scan_site_local scan_shadowed_files /; | ||
| 9 | |||
| 10 | register_worker({ phase => 'main' }, sub { | ||
| 11 | my @paths = site_local_paths(); | ||
| 12 | |||
| 13 | if (! scalar @paths) { | ||
| 14 | return Status->done('No site-local template paths are configured.'); | ||
| 15 | } | ||
| 16 | |||
| 17 | my @findings = ( scan_shadowed_files({ paths => \@paths }), | ||
| 18 | scan_site_local({ paths => \@paths }) ); | ||
| 19 | |||
| 20 | if (! scalar @findings) { | ||
| 21 | return Status->done(sprintf 'Checked %d path%s, nothing to report.', | ||
| 22 | scalar @paths, (scalar @paths == 1 ? '' : 's')); | ||
| 23 | } | ||
| 24 | |||
| 25 | my %files = map {($_->{path} => 1)} @findings; | ||
| 26 | |||
| 27 | # print rather than log: this is a report a person asked for, and the log | ||
| 28 | # level netdisco-do runs at would suppress it. DumpConfig.pm prints for the | ||
| 29 | # same reason. | ||
| 30 | print "\n"; | ||
| 31 | foreach my $finding (@findings) { | ||
| 32 | # a file finding has no line to cite | ||
| 33 | if (($finding->{kind} || '') eq 'file') { | ||
| 34 | printf "%s\n", $finding->{path}; | ||
| 35 | } | ||
| 36 | else { | ||
| 37 | printf "%s line %d\n", $finding->{path}, $finding->{line}; | ||
| 38 | printf " %s\n", $finding->{excerpt}; | ||
| 39 | } | ||
| 40 | printf " since %s: %s\n\n", | ||
| 41 | $finding->{release}, $finding->{advice}; | ||
| 42 | } | ||
| 43 | |||
| 44 | return Status->done(sprintf '%d finding%s in %d file%s.', | ||
| 45 | scalar @findings, (scalar @findings == 1 ? '' : 's'), | ||
| 46 | scalar (keys %files), (scalar (keys %files) == 1 ? '' : 's')); | ||
| 47 | }); | ||
| 48 | |||
| 49 | true; |