1 package CatalystX::HelpText::ViewRole;
5 use namespace::autoclean;
7 requires 'expose_methods';
9 around expose_methods => sub {
10 my ($orig, $self, @args) = @_;
11 my $m = $self->$orig(@args) || [];
12 [ $m->flatten, 'help_text' ];
15 has helptext_model => (
20 has comment_if_helptext_not_found => (
27 my ($self, $c, $key) = @_;
28 my $model = try { $c->model($self->helptext_model) };
30 $c->log->warn(sprintf("Cannot find the '%s' model for %s", $self->helptext_model, ref($self))) if $c->debug;
33 if (!$model->can('get_help_text_for')) {
34 $c->log->warn(sprintf("Your '%s' model used by '%s' does not have a get_help_text_for method", $self->helptext_model, ref($self))) if $c->debug;
38 $model->get_help_text_for($key);
41 $c->log->warn("Error retrieving help_text key '$key' from model: $_")
43 return '' unless $self->comment_if_helptext_not_found;
44 return '<!-- Unknown help text: ' . $key . ' -->';
52 CatalystX::HelpText::ViewRole - Role to be applied to Views
56 package MyApp::View::HTML;
59 extends 'Catalyst::View::TT';
60 with 'CatalystX::HelpText::ViewRole';
62 ... then, in your template code ...
64 [% helptext('SomeHelpTopic') %]
68 Should work with any view which implements the C<expose_methods> functionality in the same manor
69 that L<Catalyst::View::TT> does, however this has only been tried with that view.
75 =item L<CatalystX::HelpText>
77 =item L<Catalyst::View::TT/expose_methods>
83 Toomas Doran, C<< t0m at state51.co.uk >>
85 Cinxgler Mariaca Minda, C<< cinxgler at ci-info.com >>
89 Copyright Oscar Music and Media 2011.
93 This sofware is free software, and is licensed under the same terms as perl itself.