AutoCRUD/View/Download.pm untested

filter: Statementstmt 0.0% 0 / 35 Branchbran n/a Conditioncond 0.0% 0 / 4 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 0.0% 0 / 9 Podpod 0.0% 0 / 1 totaltotal 0.0% 0 / 51 CC 1 SCAR 6.9
CC
1
Cov
0%
render
2.0
BEGIN
2.0
BEGIN
2.0
CRAP 2.0
1 package App::AutoCRUD::View::Download;
2
3 use 5.010;
4 use strict;
5 use warnings;
6
7 use Moose;
8 extends 'App::AutoCRUD::View';
9
10 use Cwd;
11 use HTTP::Date;
12 use Plack::MIME;
13
14 use namespace::clean -except => 'meta';
15
16
17 sub render {
18 my ($self, $file, $context) = @_;
19
20 open my $fh, "<:raw", $file or die $!;
21 my ($size, $mtime) = (stat $fh)[7, 9];
22
23 # code mostly borrowed from App::File
24 my $content_type = Plack::MIME->mime_type($file) || 'text/plain';
25 Plack::Util::set_io_path($fh, Cwd::realpath($file));
26
27 # TODO : SUPPORT CONDITIONAL GET
28
29 return [
30 200,
31 [
32 'Content-Type' => $content_type,
33 'Content-Length' => $size,
34 'Last-Modified' => HTTP::Date::time2str($mtime),
35 ],
36 $fh,
37 ];
38
39 }
40
41 1;
42
43
44 __END__