Added script to missing help text files
Cinxgler Mariaca Minda [Tue, 27 Sep 2011 16:46:58 +0000 (17:46 +0100)]
bin/search_undocumented_templates.pl [new file with mode: 0644]
lib/CatalystX/HelpText/Script/SearchUndocumentedHelpText.pm [new file with mode: 0644]

diff --git a/bin/search_undocumented_templates.pl b/bin/search_undocumented_templates.pl
new file mode 100644 (file)
index 0000000..97c8884
--- /dev/null
@@ -0,0 +1,7 @@
+#!/usr/bin/env perl
+use strict;
+use warnings;
+
+require CatalystX::HelpText::Script::SearchUndocumentedHelpText;
+exit (CatalystX::HelpText::Script::SearchUndocumentedHelpText->new_with_options->run || 0);
+
diff --git a/lib/CatalystX/HelpText/Script/SearchUndocumentedHelpText.pm b/lib/CatalystX/HelpText/Script/SearchUndocumentedHelpText.pm
new file mode 100644 (file)
index 0000000..4599d87
--- /dev/null
@@ -0,0 +1,79 @@
+package CatalystX::HelpText::Script::SearchUndocumentedHelpText;
+use Moose;
+use Moose::Autobox;
+use MooseX::Types::Path::Class qw/ Dir /;
+use MooseX::Types::Moose qw/Str Undef/;
+use File::Find;
+use Data::Dumper;
+use Getopt::Long::Descriptive; # Force GLD as we override bits..
+use namespace::autoclean;
+
+has help_files_path => (
+    is => 'ro',
+    isa => Dir,
+    coerce => 1,
+    required => 1,
+    handles => {
+        _get_file => 'file',
+    }
+);
+
+has template_search_dir => (
+    is => 'ro',
+    isa => Str,
+    default => './',
+);
+
+has filename_pattern => (
+    is => 'ro',
+    isa => Str,
+    default => '\.(html|tt)$',
+);
+
+has help_files_ext => (
+    is => 'ro',
+    isa => Str|Undef,
+    default => 'html',
+);
+
+sub run {
+    my ($self) = @_;
+    my $filename_pattern = $self->filename_pattern;
+    my %helpkeys = ();
+    find(
+        {
+            wanted => sub {
+                my $filename = $File::Find::name;
+                return unless -f $filename;
+                return unless $filename =~ /$filename_pattern/;
+
+                #warn $filename;
+                open(FILE, $filename) or warn "Can't open $filename\n" && return;
+                while (<FILE>) {
+                    if (my ($key) = m/help_text\('(.*)'\)/o) {
+                        $helpkeys{$key} = 1;
+                    }
+                }
+                close(FILE);
+            },
+            bydepth => 1
+        }, $self->template_search_dir->flatten);
+
+    my @notfound = ();
+    foreach (keys %helpkeys) {
+        my $file = $self->_get_file($_);
+        $file .= "." . $self->help_files_ext if defined($self->help_files_ext);
+        push (@notfound, $file) unless (-e $file);
+    }
+    print "\nMissing Help Text files:\n" if (scalar @notfound);
+    print " - $_\n" for (@notfound);
+}
+
+with qw/
+    MooseX::Getopt
+/;
+
+__PACKAGE__->meta->make_immutable;
+__PACKAGE__->new_with_options->run unless caller;
+
+1;