blib/lib/Yukki/Web/Plugin/Viewer.pm untested

filter: Statementstmt 0.0% 0 / 33 Branchbran 0.0% 0 / 4 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 0.0% 0 / 4 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 42 CC 3 SCAR 19.5
CC
3
Cov
0%
show_view_link
12.0
BEGIN
2.0
BEGIN
2.0
CRAP 7.0
1 package Yukki::Web::Plugin::Viewer;
2 {
3 $Yukki::Web::Plugin::Viewer::VERSION = '0.140290';
4 }
5 use 5.12.1;
6 use Moose;
7  
8 extends 'Yukki::Web::Plugin';
9  
10 use Yukki::Error qw( http_throw );
11  
12 # ABSTRACT: plugin for custom page viewers
13  
14  
15 has format_helpers => (
16 is => 'ro',
17 isa => 'HashRef[Str]',
18 required => 1,
19 default => sub { +{
20 'show view' => 'show_view_link',
21 } },
22 );
23  
24 with 'Yukki::Web::Plugin::Role::FormatHelper';
25  
26  
27 sub show_view_link {
28 my ($self, $params) = @_;
29  
30 my $ctx = $params->{context};
31 my $file = $params->{file};
32 my $view = $params->{arg};
33  
34 my $repo = $file->repository_name;
35 my $page = $file->full_path;
36  
37 my $view_info = $self->app->settings->page_views->{$view};
38  
39 unless ($view_info) {
40 warn "no such view as '$view' configured in yukki.conf";
41 return '';
42 }
43  
44 my $args = "?view=$view";
45 $args = '' if $view eq 'default';
46  
47 $ctx->response->add_navigation_item([ qw( page page_bottom ) ] => {
48 label => $view_info->{label},
49 href => join('/', 'page/view', $repo, $page)
50 . $args,
51 sort => $view_info->{sort},
52 });
53  
54 return '';
55 }
56  
57 1;
58  
59 __END__