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

filter: Statementstmt 0.0% 0 / 44 Branchbran 0.0% 0 / 4 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 61 CC 3 SCAR 16.7
CC
3
Cov
0%
attachment_url
12.0
BEGIN
2.0
BEGIN
2.0
CRAP 5.3
1 package Yukki::Web::Plugin::Attachment;
2 $Yukki::Web::Plugin::Attachment::VERSION = '0.991_007'; # TRIAL
3 $Yukki::Web::Plugin::Attachment::VERSION = '0.991007';
4 use v5.24;
5 use utf8;
6 use Moo;
7  
8 use Types::Standard qw( HashRef Str );
9  
10 use namespace::clean;
11  
12 extends 'Yukki::Web::Plugin';
13  
14 # ABSTRACT: plugin for attachments
15  
16 use URI::Escape qw( uri_escape );
17  
18  
19 has format_helpers => (
20 is => 'ro',
21 isa => HashRef[Str],
22 required => 1,
23 default => sub { +{
24 'attachment' => 'attachment_url',
25 } },
26 );
27  
28 with 'Yukki::Web::Plugin::Role::FormatHelper';
29  
30  
31 sub attachment_url {
32 my ($self, $params) = @_;
33  
34 my $ctx = $params->{context};
35 my $file = $params->{file};
36 my $arg = $params->{arg};
37  
38 if ($arg =~ m{
39  
40 ^\s*
41  
42 (?: ([\w]+) : )? # repository: is optional
43 (.+) # link/to/page is mandatory
44  
45 \s*$
46  
47 }x) {
48  
49 my $repository = $1 // $file->repository_name;
50 my $page = $file->full_path;
51 my $link = $2;
52  
53 $link =~ s/^\s+//; $link =~ s/\s+$//;
54  
55 $page =~ s{\.yukki$}{};
56 $link = join "/", map { uri_escape($_) } split m{/}, $link;
57  
58 if ($link =~ m{^/}) {
59 return $ctx->rebae_url("attachment/view/$repository$link");
60 }
61 else {
62 return $ctx->rebase_url("attachment/view/$repository/$page/$link");
63 }
64 }
65  
66 return;
67 }
68  
69 1;
70  
71 __END__