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