Commit | Line | Data |
f22d4e6f |
1 | package CatalystX::HelpText::Model; |
2 | use Moose; |
3 | use MooseX::Types::Moose qw/Str Undef/; |
4 | use MooseX::Types::Path::Class qw/ Dir /; |
5 | use Moose::Autobox; |
6 | use Carp qw/ croak confess/; |
7 | use namespace::autoclean; |
8 | |
9 | extends 'Catalyst::Model'; |
10 | |
11 | has help_files_path => ( |
12 | is => 'ro', |
13 | isa => Dir, |
14 | coerce => 1, |
15 | required => 1, |
16 | handles => { |
17 | _get_file => 'file', |
18 | } |
19 | ); |
20 | |
21 | has help_files_ext => ( |
22 | is => 'ro', |
23 | isa => Str|Undef, |
24 | default => 'html', |
25 | ); |
26 | |
27 | sub get_help_text_for { |
28 | my ($self, $help_key) = @_; |
29 | confess('No $help_key provided') unless $help_key; |
30 | |
31 | my $fn = $help_key; |
32 | $fn .= "." . $self->help_files_ext if defined($self->help_files_ext); |
33 | |
34 | my $file = $self->_get_file($fn); |
35 | |
36 | return $file->slurp if ( -e $file ); |
37 | |
38 | croak "Cannot find help text '$help_key' in $file"; |
39 | } |
40 | |
41 | 1; |
42 | |