Better error handling
[catagits/CatalystX-HelpText.git] / lib / CatalystX / HelpText / File.pm
CommitLineData
3259663d 1package CatalystX::HelpText::File;
fceef83f 2use Moose;
3259663d 3use MooseX::Types::Moose qw/Str/;
4use Moose::Autobox;
5use Carp qw/confess/;
6use namespace::autoclean;
7
8has help_files_path => (
de884840 9 is => 'ro',
10 isa => Str,
11 default => '/support/help/',
3259663d 12);
13
14has help_files_ext => (
15 is => 'ro',
16 isa => Str,
17 default => '.html',
18);
19
20sub get_help_text_for {
21 my ($self, $c, $help_key) = @_;
de884840 22 confess('No $c provided') unless $c;
23 confess('No $help_key provided') unless $help_key;
3259663d 24
25 my $file_path = $c->path_to('root', $self->help_files_path.$help_key.$self->help_files_ext);
26 my $string = '';
3259663d 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
371;
de884840 38