Commit | Line | Data |
eb8ff5ad |
1 | package CatalystX::HelpText::Script::SearchUndocumentedHelpText; |
2 | use Moose; |
3 | use Moose::Autobox; |
4 | use MooseX::Types::Path::Class qw/ Dir /; |
5 | use MooseX::Types::Moose qw/Str Undef/; |
6 | use File::Find; |
7 | use Data::Dumper; |
8 | use Getopt::Long::Descriptive; # Force GLD as we override bits.. |
9 | use namespace::autoclean; |
10 | |
11 | has help_files_path => ( |
12 | is => 'ro', |
13 | isa => Dir, |
14 | coerce => 1, |
15 | required => 1, |
16 | handles => { |
17 | _get_file => 'file', |
18 | } |
19 | ); |
20 | |
21 | has template_search_dir => ( |
22 | is => 'ro', |
23 | isa => Str, |
24 | default => './', |
25 | ); |
26 | |
27 | has filename_pattern => ( |
28 | is => 'ro', |
29 | isa => Str, |
30 | default => '\.(html|tt)$', |
31 | ); |
32 | |
33 | has help_files_ext => ( |
34 | is => 'ro', |
35 | isa => Str|Undef, |
36 | default => 'html', |
37 | ); |
38 | |
39 | sub run { |
40 | my ($self) = @_; |
41 | my $filename_pattern = $self->filename_pattern; |
42 | my %helpkeys = (); |
43 | find( |
44 | { |
45 | wanted => sub { |
46 | my $filename = $File::Find::name; |
47 | return unless -f $filename; |
48 | return unless $filename =~ /$filename_pattern/; |
49 | |
50 | #warn $filename; |
51 | open(FILE, $filename) or warn "Can't open $filename\n" && return; |
52 | while (<FILE>) { |
53 | if (my ($key) = m/help_text\('(.*)'\)/o) { |
54 | $helpkeys{$key} = 1; |
55 | } |
56 | } |
57 | close(FILE); |
58 | }, |
59 | bydepth => 1 |
60 | }, $self->template_search_dir->flatten); |
61 | |
62 | my @notfound = (); |
63 | foreach (keys %helpkeys) { |
64 | my $file = $self->_get_file($_); |
65 | $file .= "." . $self->help_files_ext if defined($self->help_files_ext); |
66 | push (@notfound, $file) unless (-e $file); |
67 | } |
68 | print "\nMissing Help Text files:\n" if (scalar @notfound); |
69 | print " - $_\n" for (@notfound); |
70 | } |
71 | |
72 | with qw/ |
73 | MooseX::Getopt |
74 | /; |
75 | |
76 | __PACKAGE__->meta->make_immutable; |
77 | __PACKAGE__->new_with_options->run unless caller; |
78 | |
79 | 1; |