compile
[catagits/CatalystX-HelpText.git] / lib / CatalystX / HelpText / File.pm
1 package CatalystX::HelpText::File;
2 use Moose;
3 use MooseX::Types::Moose qw/Str/;
4 use Moose::Autobox;
5 use Carp qw/confess/;
6 use namespace::autoclean;
7
8 has help_files_path => (
9   is => 'ro',
10   isa => Str,
11   default => '/support/help/',
12 );
13
14 has help_files_ext => (
15   is => 'ro',
16   isa => Str,
17   default => '.html',
18 );
19
20 sub get_help_text_for {
21     my ($self, $c, $help_key) = @_;
22     confess ('No $c provided') unless $c;
23     confess ('No $help_key provided') unless $help_key;
24
25     my $file_path = $c->path_to('root', $self->help_files_path.$help_key.$self->help_files_ext);
26     my $string = '';
27     if ( -e $file_path ) {
28         local $/=undef;
29         open FILE, $file_path or confess "Couldn't open file: $!";
30         $string = <FILE>;
31         close FILE;
32     }
33
34     return $string;
35 }
36
37 1;