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

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