Update README and fix script path in Makefile.PL
[catagits/CatalystX-HelpText.git] / lib / CatalystX / HelpText / Model.pm
CommitLineData
f22d4e6f 1package CatalystX::HelpText::Model;
2use Moose;
3use MooseX::Types::Moose qw/Str Undef/;
4use MooseX::Types::Path::Class qw/ Dir /;
5use Moose::Autobox;
6use Carp qw/ croak confess/;
7use namespace::autoclean;
8
9extends 'Catalyst::Model';
10
11has help_files_path => (
12 is => 'ro',
13 isa => Dir,
14 coerce => 1,
15 required => 1,
16 handles => {
17 _get_file => 'file',
18 }
19);
20
21has help_files_ext => (
22 is => 'ro',
23 isa => Str|Undef,
24 default => 'html',
25);
26
69ca94ae 27has wrapper_css_class => (
28 is => 'ro',
29 isa => Str,
30 default => 'help_text',
31);
32
33has wrapper_tag => (
34 is => 'ro',
35 isa => Str,
36 default => 'span',
37);
38
39
f22d4e6f 40sub get_help_text_for {
41 my ($self, $help_key) = @_;
42 confess('No $help_key provided') unless $help_key;
43
44 my $fn = $help_key;
45 $fn .= "." . $self->help_files_ext if defined($self->help_files_ext);
46
47 my $file = $self->_get_file($fn);
48
69ca94ae 49 if ( -e $file ) {
50 return sprintf('<%s class="%s">%s</%s>',
51 $self->wrapper_tag,
52 $self->wrapper_css_class,
53 $file->slurp,
54 $self->wrapper_tag
55 );
56 }
f22d4e6f 57
58 croak "Cannot find help text '$help_key' in $file";
59}
60
be01cec8 61__PACKAGE__->meta->make_immutable;
f22d4e6f 621;
63
be01cec8 64=head1 NAME
65
66CatalystX::HelpText::Model - Model to provide snippets of help text
67
68=head1 SYNOPSIS
69
70 package MyApp::Model::Help;
71 use Moose;
72 use namespace::autoclean;
73
74 extends 'CatalystX::HelpText::Model';
75
76 1;
77
78=head1 DESCRIPTION
79
80A very simple file system based help text finder.
81
82Expects each piece of help text to be in an individual file, and provides a
83C<get_help_text_for> method as used by L<CatalaystX::HelpText::ViewRole> which
84just slurps in this file verbatim.
85
86Users are expected (and encouraged) to replace the simple logic in this
87model with a more complicated method of help text resolution if needed.
88
89=head1 METHODS
90
91=head1 get_help_text_for ($help_key)
92
93Returns a snippet of help text.
94
95Will throw an exception if the requested help key is not found.
96
97=head1 CONFIGURATION ATTRIBUTES
98
99XXX - FIXME - document these
100
101=head2 help_files_path
102
103=head2 help_files_ext
104
105=head2 wrapper_css_class
106
107=head2 wrapper_tag
108
109=head1 BUGS
110
111=head2 File system only.
112
113Currently we only support getting help texts from the file system (as individual files).
114
115A model to get help from a database table, or YAML file or similar could (and should)
116be provided as part of this distribution. Patches are welcome!
117
118=head1 SEE ALSO
119
120=over
121
122=item L<CatalystX::HelpText>
123
124=back
125
126=head1 AUTHOR
127
128Toomas Doran, C<< t0m at state51.co.uk >>
129
130Cinxgler Mariaca Minda, C<< cinxgler at ci-info.com >>
131
132=head1 COPYRIGHT
133
134Copyright Oscar Music and Media 2011.
135
136=head1 LICENSE
137
138This sofware is free software, and is licensed under the same terms as perl itself.
139
140=cut
141