Add a view for testing with
[catagits/CatalystX-HelpText.git] / lib / CatalystX / HelpText / ViewRole.pm
CommitLineData
c8c4f056 1package CatalystX::HelpText::ViewRole;
2use Moose::Role;
3use Try::Tiny;
4
5requires 'expose_methods';
6
7around expose_methods => sub {
8 my ($orig, $self, @args) = @_;
9 my @m = $self->$orig(@args)->flatten;
10 [ @m, 'help_text' ];
11};
12
13sub help_text {
14 my ($self, $c, $key) = @_;
15 try {
16 return $c->model('Help')->get_help_text_for($c, $key);
17 }
18 catch {
19 $c->log->warn("Error retrieving help_text: ".$_);
20 return '';
21 };
22}
23
241;
25
26=head1 NAME
27
28CatalystX::HelpText::ViewRole - Role to be applied to Views
29
30=head1 SYNOPSIS
31
32 package MyApp::View::HTML;
33 use Moose;
34
35 extends 'Catalyst::View::TT';
36 with 'CatalystX::HelpText::ViewRole';
37
38 ... then, in your template code ...
39
40 [% helptext('SomeHelpTopic') %]
41
42=cut
43