<!DOCTYPE html
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
<!--
This file was generated by Devel::Cover Version 1.26
Devel::Cover is copyright 2001-2012, Paul Johnson (paul@pjcj.net)
Devel::Cover is free. It is licensed under the same terms as Perl itself.
The latest version of Devel::Cover should be available from my homepage:
-->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"></meta>
<meta http-equiv="Content-Language" content="en-us"></meta>
<link rel="stylesheet" type="text/css" href="cover.css"></link>
<link rel="stylesheet" type="text/css" href="cover.css"></link>
<title>File Coverage: lib/Yukki/Web/Controller/Attachment.pm</title>
</head>
<body>
<h1>File Coverage</h1>
<table>
<tr><td class="h" align="right">File:</td><td align="left">lib/Yukki/Web/Controller/Attachment.pm</td></tr>
<tr><td class="h" align="right">Coverage:</td><td align="left" class="c0">42.8%</td></tr>
</table>
<div><br/></div>
<table>
<tr><th>line</th><th>stmt</th><th>bran</th><th>cond</th><th>sub</th><th>pod</th><th>time</th><th>code</th></tr>
<tr><td class="h">1</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s">package Yukki::Web::Controller::Attachment;</td></tr>
<tr><td class="h">2</td><td colspan="7"></td></tr><tr><td class="h">3</td><td><div class="c3">2</div><div class="c3">2</div></td><td></td><td></td><td><div class="c3"><a href="lib-Yukki-Web-Controller-Attachment-pm--subroutine.html#L3">2</a></div></td><td></td><td><div>616</div><div>7</div></td><td class="s">use v5.24;</td></tr>
<tr><td class="h">4</td><td><div class="c3">2</div><div class="c3">2</div><div class="c3">2</div></td><td></td><td></td><td><div class="c3"><a href="lib-Yukki-Web-Controller-Attachment-pm--subroutine.html#L4">2</a></div></td><td></td><td><div>7</div><div>14</div><div>21</div></td><td class="s">use utf8;</td></tr>
<tr><td class="h">5</td><td><div class="c3">2</div><div class="c3">2</div><div class="c3">2</div></td><td></td><td></td><td><div class="c3"><a href="lib-Yukki-Web-Controller-Attachment-pm--subroutine.html#L5">2</a></div></td><td></td><td><div>30</div><div>2</div><div>17</div></td><td class="s">use Moo;</td></tr>
<tr><td class="h">6</td><td colspan="7"></td></tr><tr><td class="h">7</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s">with 'Yukki::Web::Controller';</td></tr>
<tr><td class="h">8</td><td colspan="7"></td></tr><tr><td class="h">9</td><td><div class="c3">2</div><div class="c3">2</div><div class="c3">2</div></td><td></td><td></td><td><div class="c3"><a href="lib-Yukki-Web-Controller-Attachment-pm--subroutine.html#L9">2</a></div></td><td></td><td><div>2238</div><div>11824</div><div>9</div></td><td class="s">use JSON;</td></tr>
<tr><td class="h">10</td><td><div class="c3">2</div><div class="c3">2</div><div class="c3">2</div></td><td></td><td></td><td><div class="c3"><a href="lib-Yukki-Web-Controller-Attachment-pm--subroutine.html#L10">2</a></div></td><td></td><td><div>360</div><div>4</div><div>7</div></td><td class="s">use Yukki::Error qw( http_throw );</td></tr>
<tr><td class="h">11</td><td colspan="7"></td></tr><tr><td class="h">12</td><td><div class="c3">2</div><div class="c3">2</div><div class="c3">2</div></td><td></td><td></td><td><div class="c3"><a href="lib-Yukki-Web-Controller-Attachment-pm--subroutine.html#L12">2</a></div></td><td></td><td><div>308</div><div>3</div><div>7</div></td><td class="s">use namespace::clean;</td></tr>
<tr><td class="h">13</td><td colspan="7"></td></tr><tr><td class="h">14</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s"># ABSTRACT: Controller for uploading, downloading, and viewing attachments</td></tr>
<tr><td class="h">15</td><td colspan="7"></td></tr><tr><td class="h">16 - 26</td><td colspan="6"></td><td class="s"><pre>=head1 DESCRIPTION
Handles uploading, downloading, and viewing attachments.
=head1 METHODS
=head2 fire
Maps download requests to L</download_file>, upload requests to L</upload_file>, and view requestst to L</view_file>.
=cut</pre></td></tr>
<tr><td class="h">27</td><td colspan="7"></td></tr><tr><td class="h">28</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s">sub fire {</td></tr>
<tr><td class="h">29</td><td><div class="c3">2</div></td><td></td><td></td><td><div class="c3"><a href="lib-Yukki-Web-Controller-Attachment-pm--subroutine.html#L29">2</a></div></td><td><div class="c3">1</div></td><td><div>5</div></td><td class="s"> my ($self, $ctx) = @_;</td></tr>
<tr><td class="h">30</td><td colspan="7"></td></tr><tr><td class="h">31</td><td><div class="c3">2</div></td><td></td><td></td><td></td><td></td><td><div>26</div></td><td class="s"> my $action = $ctx->request->path_parameters->{action};</td></tr>
<tr><td class="h">32</td><td><div class="c3">2</div><div class="c3">1</div></td><td><div class="c3" title="T/F"><a href="lib-Yukki-Web-Controller-Attachment-pm--branch.html#L32">100</a></div><div class="c0" title="-/F"><a href="lib-Yukki-Web-Controller-Attachment-pm--branch.html#L32">50</a></div><div class="c0" title="-/F"><a href="lib-Yukki-Web-Controller-Attachment-pm--branch.html#L32">50</a></div><div class="c0" title="-/F"><a href="lib-Yukki-Web-Controller-Attachment-pm--branch.html#L32">50</a></div><div class="c0" title="-/F"><a href="lib-Yukki-Web-Controller-Attachment-pm--branch.html#L32">50</a></div></td><td></td><td></td><td></td><td><div>42</div><div>3</div></td><td class="s"> if ($action eq 'download') { $self->download_file($ctx) }</td></tr>
<tr><td class="h">33</td><td><div class="c0">0</div></td><td></td><td></td><td></td><td></td><td><div>0</div></td><td class="s"> elsif ($action eq 'upload') { $self->upload_file($ctx) }</td></tr>
<tr><td class="h">34</td><td><div class="c0">0</div></td><td></td><td></td><td></td><td></td><td><div>0</div></td><td class="s"> elsif ($action eq 'view') { $self->view_file($ctx) }</td></tr>
<tr><td class="h">35</td><td><div class="c0">0</div></td><td></td><td></td><td></td><td></td><td><div>0</div></td><td class="s"> elsif ($action eq 'rename') { $self->rename_file($ctx) }</td></tr>
<tr><td class="h">36</td><td><div class="c0">0</div></td><td></td><td></td><td></td><td></td><td><div>0</div></td><td class="s"> elsif ($action eq 'remove') { $self->remove_file($ctx) }</td></tr>
<tr><td class="h">37</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s"> else {</td></tr>
<tr><td class="h">38</td><td><div class="c3">1</div></td><td></td><td></td><td></td><td></td><td><div>5</div></td><td class="s"> http_throw('That attachment action does not exist.', {</td></tr>
<tr><td class="h">39</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s"> status => 'NotFound',</td></tr>
<tr><td class="h">40</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s"> });</td></tr>
<tr><td class="h">41</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s"> }</td></tr>
<tr><td class="h">42</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s">}</td></tr>
<tr><td class="h">43</td><td colspan="7"></td></tr><tr><td class="h">44 - 51</td><td colspan="6"></td><td class="s"><pre>=head2 lookup_file
my $file = $self->lookup_file($repository, $path);
This is a helper for locating and returning a L<Yukki::Model::File> for the
requested repository and path.
=cut</pre></td></tr>
<tr><td class="h">52</td><td colspan="7"></td></tr><tr><td class="h">53</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s">sub lookup_file {</td></tr>
<tr><td class="h">54</td><td><div class="c3">1</div></td><td></td><td></td><td><div class="c3"><a href="lib-Yukki-Web-Controller-Attachment-pm--subroutine.html#L54">1</a></div></td><td><div class="c3">1</div></td><td><div>2</div></td><td class="s"> my ($self, $repo_name, $file) = @_;</td></tr>
<tr><td class="h">55</td><td colspan="7"></td></tr><tr><td class="h">56</td><td><div class="c3">1</div></td><td></td><td></td><td></td><td></td><td><div>20</div></td><td class="s"> my $repository = $self->model('Repository', { name => $repo_name });</td></tr>
<tr><td class="h">57</td><td colspan="7"></td></tr><tr><td class="h">58</td><td><div class="c3">1</div></td><td></td><td></td><td></td><td></td><td><div>6</div></td><td class="s"> my $final_part = pop @$file;</td></tr>
<tr><td class="h">59</td><td><div class="c3">1</div></td><td></td><td></td><td></td><td></td><td><div>2</div></td><td class="s"> my $filetype;</td></tr>
<tr><td class="h">60</td><td><div class="c3">1</div></td><td><div class="c0" title="-/F"><a href="lib-Yukki-Web-Controller-Attachment-pm--branch.html#L60">50</a></div></td><td></td><td></td><td></td><td><div>3</div></td><td class="s"> if ($final_part =~ s/\.(?<filetype>[a-z0-9]+)$//) {</td></tr>
<tr><td class="h">61</td><td><div class="c3">1</div><div class="c3">1</div><div class="c3">1</div><div class="c0">0</div></td><td></td><td></td><td><div class="c3"><a href="lib-Yukki-Web-Controller-Attachment-pm--subroutine.html#L61">1</a></div></td><td></td><td><div>461</div><div>278</div><div>468</div><div>0</div></td><td class="s"> $filetype = $+{filetype};</td></tr>
<tr><td class="h">62</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s"> }</td></tr>
<tr><td class="h">63</td><td colspan="7"></td></tr><tr><td class="h">64</td><td><div class="c3">1</div></td><td></td><td></td><td></td><td></td><td><div>3</div></td><td class="s"> my $path = join '/', @$file, $final_part;</td></tr>
<tr><td class="h">65</td><td><div class="c3">1</div></td><td></td><td></td><td></td><td></td><td><div>5</div></td><td class="s"> return $repository->file({ path => $path, filetype => $filetype });</td></tr>
<tr><td class="h">66</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s">}</td></tr>
<tr><td class="h">67</td><td colspan="7"></td></tr><tr><td class="h">68 - 73</td><td colspan="6"></td><td class="s"><pre>=head2 download_file
Returns the file in the response with a MIME type of "application/octet". This
should force the browser to treat it like a download.
=cut</pre></td></tr>
<tr><td class="h">74</td><td colspan="7"></td></tr><tr><td class="h">75</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s">sub download_file {</td></tr>
<tr><td class="h">76</td><td><div class="c3">1</div></td><td></td><td></td><td><div class="c3"><a href="lib-Yukki-Web-Controller-Attachment-pm--subroutine.html#L76">1</a></div></td><td><div class="c3">1</div></td><td><div>2</div></td><td class="s"> my ($self, $ctx) = @_;</td></tr>
<tr><td class="h">77</td><td colspan="7"></td></tr><tr><td class="h">78</td><td><div class="c3">1</div></td><td></td><td></td><td></td><td></td><td><div>13</div></td><td class="s"> my $repo_name = $ctx->request->path_parameters->{repository};</td></tr>
<tr><td class="h">79</td><td><div class="c3">1</div></td><td></td><td></td><td></td><td></td><td><div>64</div></td><td class="s"> my $path = $ctx->request->path_parameters->{file};</td></tr>
<tr><td class="h">80</td><td colspan="7"></td></tr><tr><td class="h">81</td><td><div class="c3">1</div></td><td></td><td></td><td></td><td></td><td><div>27</div></td><td class="s"> my $file = $self->lookup_file($repo_name, $path);</td></tr>
<tr><td class="h">82</td><td colspan="7"></td></tr><tr><td class="h">83</td><td><div class="c3">1</div></td><td></td><td></td><td></td><td></td><td><div>22</div></td><td class="s"> $ctx->response->content_type('application/octet');</td></tr>
<tr><td class="h">84</td><td><div class="c3">1</div></td><td></td><td></td><td></td><td></td><td><div>179</div></td><td class="s"> $ctx->response->body([ scalar $file->fetch ]);</td></tr>
<tr><td class="h">85</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s">}</td></tr>
<tr><td class="h">86</td><td colspan="7"></td></tr><tr><td class="h">87 - 92</td><td colspan="6"></td><td class="s"><pre>=head2 view_file
Returns the file in the response with a MIME type reported by
L<Yukki::Model::File/media_type>.
=cut</pre></td></tr>
<tr><td class="h">93</td><td colspan="7"></td></tr><tr><td class="h">94</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s">sub view_file {</td></tr>
<tr><td class="h">95</td><td><div class="c0">0</div></td><td></td><td></td><td><div class="c0"><a href="lib-Yukki-Web-Controller-Attachment-pm--subroutine.html#L95">0</a></div></td><td><div class="c3">1</div></td><td></td><td class="s"> my ($self, $ctx) = @_;</td></tr>
<tr><td class="h">96</td><td colspan="7"></td></tr><tr><td class="h">97</td><td><div class="c0">0</div></td><td></td><td></td><td></td><td></td><td></td><td class="s"> my $repo_name = $ctx->request->path_parameters->{repository};</td></tr>
<tr><td class="h">98</td><td><div class="c0">0</div></td><td></td><td></td><td></td><td></td><td></td><td class="s"> my $path = $ctx->request->path_parameters->{file};</td></tr>
<tr><td class="h">99</td><td colspan="7"></td></tr><tr><td class="h">100</td><td><div class="c0">0</div></td><td></td><td></td><td></td><td></td><td></td><td class="s"> my $file = $self->lookup_file($repo_name, $path);</td></tr>
<tr><td class="h">101</td><td colspan="7"></td></tr><tr><td class="h">102</td><td><div class="c0">0</div></td><td></td><td></td><td></td><td></td><td></td><td class="s"> $ctx->response->content_type($file->media_type);</td></tr>
<tr><td class="h">103</td><td><div class="c0">0</div></td><td></td><td></td><td></td><td></td><td></td><td class="s"> $ctx->response->body([ scalar $file->fetch ]);</td></tr>
<tr><td class="h">104</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s">}</td></tr>
<tr><td class="h">105</td><td colspan="7"></td></tr><tr><td class="h">106 - 110</td><td colspan="6"></td><td class="s"><pre>=head2 rename_file
Handles attachment renaming via the page rename controller.
=cut</pre></td></tr>
<tr><td class="h">111</td><td colspan="7"></td></tr><tr><td class="h">112</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s">sub rename_file {</td></tr>
<tr><td class="h">113</td><td><div class="c0">0</div></td><td></td><td></td><td><div class="c0"><a href="lib-Yukki-Web-Controller-Attachment-pm--subroutine.html#L113">0</a></div></td><td><div class="c3">1</div></td><td></td><td class="s"> my ($self, $ctx) = @_;</td></tr>
<tr><td class="h">114</td><td colspan="7"></td></tr><tr><td class="h">115</td><td><div class="c0">0</div></td><td></td><td></td><td></td><td></td><td></td><td class="s"> my $repo_name = $ctx->request->path_parameters->{repository};</td></tr>
<tr><td class="h">116</td><td><div class="c0">0</div></td><td></td><td></td><td></td><td></td><td></td><td class="s"> my $path = $ctx->request->path_parameters->{file};</td></tr>
<tr><td class="h">117</td><td colspan="7"></td></tr><tr><td class="h">118</td><td><div class="c0">0</div></td><td></td><td></td><td></td><td></td><td></td><td class="s"> my $file = $self->lookup_file($repo_name, $path);</td></tr>
<tr><td class="h">119</td><td colspan="7"></td></tr><tr><td class="h">120</td><td><div class="c0">0</div></td><td><div class="c0" title="-/-"><a href="lib-Yukki-Web-Controller-Attachment-pm--branch.html#L120">0</a></div></td><td></td><td></td><td></td><td></td><td class="s"> if ($ctx->request->method eq 'POST') {</td></tr>
<tr><td class="h">121</td><td><div class="c0">0</div></td><td></td><td></td><td></td><td></td><td></td><td class="s"> my $new_name = $ctx->request->parameters->{yukkiname_new};</td></tr>
<tr><td class="h">122</td><td colspan="7"></td></tr><tr><td class="h">123</td><td><div class="c0">0</div></td><td></td><td></td><td></td><td></td><td></td><td class="s"> my $part = qr{[_a-z0-9-.]+(?:\.[_a-z0-9-]+)*}i;</td></tr>
<tr><td class="h">124</td><td><div class="c0">0</div></td><td><div class="c0" title="-/-"><a href="lib-Yukki-Web-Controller-Attachment-pm--branch.html#L124">0</a></div></td><td></td><td></td><td></td><td></td><td class="s"> if ($new_name =~ m{^$part(?:/$part)*$}) {</td></tr>
<tr><td class="h">125</td><td><div class="c0">0</div></td><td><div class="c0" title="-/-"><a href="lib-Yukki-Web-Controller-Attachment-pm--branch.html#L125">0</a></div></td><td></td><td></td><td></td><td></td><td class="s"> if (my $user = $ctx->session->{user}) {</td></tr>
<tr><td class="h">126</td><td><div class="c0">0</div></td><td></td><td></td><td></td><td></td><td></td><td class="s"> $file->author_name($user->{name});</td></tr>
<tr><td class="h">127</td><td><div class="c0">0</div></td><td></td><td></td><td></td><td></td><td></td><td class="s"> $file->author_email($user->{email});</td></tr>
<tr><td class="h">128</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s"> }</td></tr>
<tr><td class="h">129</td><td colspan="7"></td></tr><tr><td class="h">130</td><td><div class="c0">0</div></td><td></td><td></td><td></td><td></td><td></td><td class="s"> my $new_file = $file->rename({</td></tr>
<tr><td class="h">131</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s"> full_path => $new_name,</td></tr>
<tr><td class="h">132</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s"> comment => 'Renamed ' . $file->full_path . ' to ' . $new_name,</td></tr>
<tr><td class="h">133</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s"> });</td></tr>
<tr><td class="h">134</td><td colspan="7"></td></tr><tr><td class="h">135</td><td><div class="c0">0</div></td><td></td><td><div class="c0"><a href="lib-Yukki-Web-Controller-Attachment-pm--condition.html#L135">0</a></div></td><td></td><td></td><td></td><td class="s"> my $parent = $new_file->parent // $file->repository->default_file;</td></tr>
<tr><td class="h">136</td><td colspan="7"></td></tr><tr><td class="h">137</td><td><div class="c0">0</div></td><td></td><td></td><td></td><td></td><td></td><td class="s"> $ctx->response->redirect(join '/',</td></tr>
<tr><td class="h">138</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s"> '/page/edit', $repo_name, $parent->full_path);</td></tr>
<tr><td class="h">139</td><td><div class="c0">0</div></td><td></td><td></td><td></td><td></td><td></td><td class="s"> return;</td></tr>
<tr><td class="h">140</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s"> }</td></tr>
<tr><td class="h">141</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s"> else {</td></tr>
<tr><td class="h">142</td><td><div class="c0">0</div></td><td></td><td></td><td></td><td></td><td></td><td class="s"> $ctx->add_errors('the new name must contain only letters, numbers, underscores, dashes, periods, and slashes');</td></tr>
<tr><td class="h">143</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s"> }</td></tr>
<tr><td class="h">144</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s"> }</td></tr>
<tr><td class="h">145</td><td colspan="7"></td></tr><tr><td class="h">146</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s"> $ctx->response->body(</td></tr>
<tr><td class="h">147</td><td><div class="c0">0</div></td><td></td><td></td><td></td><td></td><td></td><td class="s"> $self->view('Attachment')->rename($ctx, {</td></tr>
<tr><td class="h">148</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s"> title => $file->title,</td></tr>
<tr><td class="h">149</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s"> repository => $repo_name,</td></tr>
<tr><td class="h">150</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s"> page => $file->full_path,</td></tr>
<tr><td class="h">151</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s"> file => $file,</td></tr>
<tr><td class="h">152</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s"> })</td></tr>
<tr><td class="h">153</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s"> );</td></tr>
<tr><td class="h">154</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s">}</td></tr>
<tr><td class="h">155</td><td colspan="7"></td></tr><tr><td class="h">156 - 160</td><td colspan="6"></td><td class="s"><pre>=head2 remove_file
Displays the remove confirmation.
=cut</pre></td></tr>
<tr><td class="h">161</td><td colspan="7"></td></tr><tr><td class="h">162</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s">sub remove_file {</td></tr>
<tr><td class="h">163</td><td><div class="c0">0</div></td><td></td><td></td><td><div class="c0"><a href="lib-Yukki-Web-Controller-Attachment-pm--subroutine.html#L163">0</a></div></td><td><div class="c3">1</div></td><td></td><td class="s"> my ($self, $ctx) = @_;</td></tr>
<tr><td class="h">164</td><td colspan="7"></td></tr><tr><td class="h">165</td><td><div class="c0">0</div></td><td></td><td></td><td></td><td></td><td></td><td class="s"> my $repo_name = $ctx->request->path_parameters->{repository};</td></tr>
<tr><td class="h">166</td><td><div class="c0">0</div></td><td></td><td></td><td></td><td></td><td></td><td class="s"> my $path = $ctx->request->path_parameters->{file};</td></tr>
<tr><td class="h">167</td><td colspan="7"></td></tr><tr><td class="h">168</td><td><div class="c0">0</div></td><td></td><td></td><td></td><td></td><td></td><td class="s"> my $file = $self->lookup_file($repo_name, $path);</td></tr>
<tr><td class="h">169</td><td colspan="7"></td></tr><tr><td class="h">170</td><td><div class="c0">0</div></td><td></td><td><div class="c0"><a href="lib-Yukki-Web-Controller-Attachment-pm--condition.html#L170">0</a></div></td><td></td><td></td><td></td><td class="s"> my $return_to = $file->parent // $file->repository->default_file;</td></tr>
<tr><td class="h">171</td><td colspan="7"></td></tr><tr><td class="h">172</td><td><div class="c0">0</div></td><td></td><td></td><td></td><td></td><td></td><td class="s"> my $confirmed = $ctx->request->body_parameters->{confirmed};</td></tr>
<tr><td class="h">173</td><td><div class="c0">0</div></td><td><div class="c0" title="-/-"><a href="lib-Yukki-Web-Controller-Attachment-pm--branch.html#L173">0</a></div></td><td><div class="c0"><a href="lib-Yukki-Web-Controller-Attachment-pm--condition.html#L173">0</a></div></td><td></td><td></td><td></td><td class="s"> if ($ctx->request->method eq 'POST' and $confirmed) {</td></tr>
<tr><td class="h">174</td><td colspan="7"></td></tr><tr><td class="h">175</td><td><div class="c0">0</div></td><td><div class="c0" title="-/-"><a href="lib-Yukki-Web-Controller-Attachment-pm--branch.html#L175">0</a></div></td><td></td><td></td><td></td><td></td><td class="s"> if (my $user = $ctx->session->{user}) {</td></tr>
<tr><td class="h">176</td><td><div class="c0">0</div></td><td></td><td></td><td></td><td></td><td></td><td class="s"> $file->author_name($user->{name});</td></tr>
<tr><td class="h">177</td><td><div class="c0">0</div></td><td></td><td></td><td></td><td></td><td></td><td class="s"> $file->author_email($user->{email});</td></tr>
<tr><td class="h">178</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s"> }</td></tr>
<tr><td class="h">179</td><td colspan="7"></td></tr><tr><td class="h">180</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s"> $file->remove({</td></tr>
<tr><td class="h">181</td><td><div class="c0">0</div></td><td></td><td></td><td></td><td></td><td></td><td class="s"> comment => 'Removing ' . $file->full_path . ' from repository.',</td></tr>
<tr><td class="h">182</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s"> });</td></tr>
<tr><td class="h">183</td><td colspan="7"></td></tr><tr><td class="h">184</td><td><div class="c0">0</div></td><td></td><td></td><td></td><td></td><td></td><td class="s"> $ctx->response->redirect(join '/', '/page/view', $repo_name, $return_to->full_path);</td></tr>
<tr><td class="h">185</td><td><div class="c0">0</div></td><td></td><td></td><td></td><td></td><td></td><td class="s"> return;</td></tr>
<tr><td class="h">186</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s"> }</td></tr>
<tr><td class="h">187</td><td colspan="7"></td></tr><tr><td class="h">188</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s"> $ctx->response->body(</td></tr>
<tr><td class="h">189</td><td><div class="c0">0</div></td><td></td><td></td><td></td><td></td><td></td><td class="s"> $self->view('Attachment')->remove($ctx, {</td></tr>
<tr><td class="h">190</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s"> title => $file->title,</td></tr>
<tr><td class="h">191</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s"> repository => $repo_name,</td></tr>
<tr><td class="h">192</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s"> page => $file->full_path,</td></tr>
<tr><td class="h">193</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s"> file => $file,</td></tr>
<tr><td class="h">194</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s"> return_link => join('/', '/page/view', $repo_name, $return_to->full_path),</td></tr>
<tr><td class="h">195</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s"> })</td></tr>
<tr><td class="h">196</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s"> );</td></tr>
<tr><td class="h">197</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s">}</td></tr>
<tr><td class="h">198</td><td colspan="7"></td></tr><tr><td class="h">199 - 203</td><td colspan="6"></td><td class="s"><pre>=head2 upload_file
This uploads the file given into the wiki.
=cut</pre></td></tr>
<tr><td class="h">204</td><td colspan="7"></td></tr><tr><td class="h">205</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s">sub upload_file {</td></tr>
<tr><td class="h">206</td><td><div class="c0">0</div></td><td></td><td></td><td><div class="c0"><a href="lib-Yukki-Web-Controller-Attachment-pm--subroutine.html#L206">0</a></div></td><td><div class="c3">1</div></td><td></td><td class="s"> my ($self, $ctx) = @_;</td></tr>
<tr><td class="h">207</td><td colspan="7"></td></tr><tr><td class="h">208</td><td><div class="c0">0</div></td><td></td><td></td><td></td><td></td><td></td><td class="s"> my $repo_name = $ctx->request->path_parameters->{repository};</td></tr>
<tr><td class="h">209</td><td><div class="c0">0</div></td><td></td><td></td><td></td><td></td><td></td><td class="s"> my $path = $ctx->request->path_parameters->{file};</td></tr>
<tr><td class="h">210</td><td colspan="7"></td></tr><tr><td class="h">211</td><td><div class="c0">0</div></td><td></td><td></td><td></td><td></td><td></td><td class="s"> my $file = $self->lookup_file($repo_name, $path);</td></tr>
<tr><td class="h">212</td><td colspan="7"></td></tr><tr><td class="h">213</td><td><div class="c0">0</div></td><td><div class="c0" title="-/-"><a href="lib-Yukki-Web-Controller-Attachment-pm--branch.html#L213">0</a></div></td><td></td><td></td><td></td><td></td><td class="s"> if (my $user = $ctx->session->{user}) {</td></tr>
<tr><td class="h">214</td><td><div class="c0">0</div></td><td></td><td></td><td></td><td></td><td></td><td class="s"> $file->author_name($user->{name});</td></tr>
<tr><td class="h">215</td><td><div class="c0">0</div></td><td></td><td></td><td></td><td></td><td></td><td class="s"> $file->author_email($user->{email});</td></tr>
<tr><td class="h">216</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s"> }</td></tr>
<tr><td class="h">217</td><td colspan="7"></td></tr><tr><td class="h">218</td><td><div class="c0">0</div></td><td></td><td></td><td></td><td></td><td></td><td class="s"> my $upload = $ctx->request->uploads->{file};</td></tr>
<tr><td class="h">219</td><td><div class="c0">0</div></td><td></td><td></td><td></td><td></td><td></td><td class="s"> $file->store({</td></tr>
<tr><td class="h">220</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s"> filename => $upload->tempname,</td></tr>
<tr><td class="h">221</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s"> comment => 'Uploading file ' . $upload->filename,</td></tr>
<tr><td class="h">222</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s"> });</td></tr>
<tr><td class="h">223</td><td colspan="7"></td></tr><tr><td class="h">224</td><td><div class="c0">0</div></td><td></td><td></td><td></td><td></td><td></td><td class="s"> $ctx->response->content_type('application/json');</td></tr>
<tr><td class="h">225</td><td><div class="c0">0</div></td><td></td><td></td><td></td><td></td><td></td><td class="s"> $ctx->response->body(</td></tr>
<tr><td class="h">226</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s"> encode_json({</td></tr>
<tr><td class="h">227</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s"> viewable => 1,</td></tr>
<tr><td class="h">228</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s"> repository_path => join('/', $repo_name, $file->full_path),</td></tr>
<tr><td class="h">229</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s"> })</td></tr>
<tr><td class="h">230</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s"> );</td></tr>
<tr><td class="h">231</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s">}</td></tr>
<tr><td class="h">232</td><td colspan="7"></td></tr><tr><td class="h">233</td><td></td><td></td><td></td><td></td><td></td><td></td><td class="s">1;</td></tr>
</table>
</body>
</html>