Add fixmes here
[catagits/CatalystX-HelpText.git] / lib / CatalystX / HelpText / Script / SearchUndocumentedHelpText.pm
CommitLineData
eb8ff5ad 1package CatalystX::HelpText::Script::SearchUndocumentedHelpText;
2use Moose;
3use Moose::Autobox;
4use MooseX::Types::Path::Class qw/ Dir /;
5use MooseX::Types::Moose qw/Str Undef/;
6use File::Find;
7use Data::Dumper;
8use Getopt::Long::Descriptive; # Force GLD as we override bits..
9use namespace::autoclean;
10
11has help_files_path => (
12 is => 'ro',
13 isa => Dir,
14 coerce => 1,
15 required => 1,
16 handles => {
17 _get_file => 'file',
18 }
19);
20
21has template_search_dir => (
22 is => 'ro',
23 isa => Str,
24 default => './',
25);
26
27has filename_pattern => (
28 is => 'ro',
29 isa => Str,
30 default => '\.(html|tt)$',
31);
32
33has help_files_ext => (
34 is => 'ro',
35 isa => Str|Undef,
36 default => 'html',
37);
38
39sub 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
ca3ec616 50 #FIXME - Not a regex here, we should actually pass the templates through TT
51 # and pass in our own callback!
52 # I guess the 'here is a file name, hand me the list of links in it'
53 # stuff should be delegated to another class (which is settable by command line)
54 # to allow people to have alternative methods of using this
eb8ff5ad 55 open(FILE, $filename) or warn "Can't open $filename\n" && return;
56 while (<FILE>) {
57 if (my ($key) = m/help_text\('(.*)'\)/o) {
58 $helpkeys{$key} = 1;
59 }
60 }
61 close(FILE);
62 },
63 bydepth => 1
64 }, $self->template_search_dir->flatten);
65
66 my @notfound = ();
67 foreach (keys %helpkeys) {
68 my $file = $self->_get_file($_);
69 $file .= "." . $self->help_files_ext if defined($self->help_files_ext);
70 push (@notfound, $file) unless (-e $file);
71 }
ca3ec616 72 # XXX FIXME - This method is way too big!
73 # It'd be useless if you wanted to customise it by sub-classing (which we _will_)
74 # later want to do as part of our build process!
75 # We should have a method to find a list of all the potential files
76 # then a for each file method, which calls to the delegate class and
77 # then we should build a hash of all the filemame => [qw/ helptext1 helptext 2 /]
78 # and then finally we should hand that to a method for pretty printing
79 # (and that method needs to unique the finds, which we don't do at the moment)
eb8ff5ad 80 print "\nMissing Help Text files:\n" if (scalar @notfound);
81 print " - $_\n" for (@notfound);
82}
83
84with qw/
85 MooseX::Getopt
86/;
87
88__PACKAGE__->meta->make_immutable;
89__PACKAGE__->new_with_options->run unless caller;
90
911;