package CatalystX::HelpText::Finder::TemplateToolkit;
use Moose;
use List::MoreUtils qw/ uniq /;
use MooseX::Types::Moose qw/Str/;
use Template;
use namespace::autoclean;

has template_search_dir => (
    isa => Str,
    is => 'ro',
    required => 1,
);

sub find_helptext_keys_in_fn {
    my ($self, $fn) = @_;
    my @keys = ();
    my $t = Template->new({
        INCLUDE_PATH => [ $self->template_search_dir ],
        ABSOLUTE => 1,
    });
    my $out;
    $t->process($fn, { help_text => sub { push @keys, shift } }, \$out);
    return [ uniq @keys ];
}

__PACKAGE__->meta->make_immutable;
1;

