Make an instance of the finder
Tomas Doran [Mon, 10 Oct 2011 14:24:29 +0000 (15:24 +0100)]
lib/CatalystX/HelpText/Finder/TemplateToolkit.pm
lib/CatalystX/HelpText/Script/SearchUndocumentedHelpText.pm

index 9c06656..077d470 100644 (file)
@@ -4,11 +4,17 @@ use List::MoreUtils qw/ uniq /;
 use Template;
 use namespace::autoclean;
 
+has template_search_dir => (
+    isa => Str,
+    is => 'ro',
+    required => 1,
+);
+
 sub find_helptext_keys_in_fn {
-    my ($self, $fn, $script) = @_;
+    my ($self, $fn) = @_;
     my @keys = ();
     my $t = Template->new({
-        INCLUDE_PATH => [ $script->template_search_dir ],
+        INCLUDE_PATH => [ $self->template_search_dir ],
         ABSOLUTE => 1,
     });
     my $out;
index 2eb149c..01ba939 100644 (file)
@@ -15,8 +15,19 @@ has finder_class => (
     isa => LoadableClass,
     coerce => 1,
     default => 'CatalystX::HelpText::Finder::TemplateToolkit',
+    handles => "_construct_finder",
+);
+
+has finder => (
+    isa => duck_type([qw/ find_helptext_keys_in_fn /]),
+    default => sub {
+        my $self = shift;
+        $self->_construct_finder( # Args here
+        );
+    },
+    lazy => 1,
     handles => {
-        find_helptext_keys_in_fn => 'find_helptext_keys_in_fn',
+        _find_helptext_keys_in_fn => 'find_helptext_keys_in_fn',
     }
 );
 
@@ -136,11 +147,6 @@ sub _build_all_files {
     return [ @files ];
 }
 
-sub _find_helptext_keys_in_fn {
-    my ($self, $fn) = @_;
-    return $self->find_helptext_keys_in_fn($fn, $self);
-}
-
 sub _helptext_file_for_key_exists {
     my ($self, $key) = @_;
     my $file = $self->_get_file($key);