| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Dancer2::Core::Request::Upload; |
|
2
|
|
|
|
|
|
|
# ABSTRACT: Class representing file upload requests |
|
3
|
|
|
|
|
|
|
$Dancer2::Core::Request::Upload::VERSION = '2.0.1'; |
|
4
|
161
|
|
|
161
|
|
355531
|
use Moo; |
|
|
161
|
|
|
|
|
42803
|
|
|
|
161
|
|
|
|
|
1643
|
|
|
5
|
|
|
|
|
|
|
|
|
6
|
161
|
|
|
161
|
|
80816
|
use Carp; |
|
|
161
|
|
|
|
|
449
|
|
|
|
161
|
|
|
|
|
14854
|
|
|
7
|
161
|
|
|
161
|
|
1152
|
use File::Spec; |
|
|
161
|
|
|
|
|
385
|
|
|
|
161
|
|
|
|
|
9024
|
|
|
8
|
161
|
|
|
161
|
|
5715
|
use Module::Runtime 'require_module'; |
|
|
161
|
|
|
|
|
18522
|
|
|
|
161
|
|
|
|
|
1717
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
161
|
|
|
161
|
|
12227
|
use Dancer2::Core::Types; |
|
|
161
|
|
|
|
|
605
|
|
|
|
161
|
|
|
|
|
1545
|
|
|
11
|
161
|
|
|
161
|
|
2403506
|
use Dancer2::FileUtils qw(open_file); |
|
|
161
|
|
|
|
|
527
|
|
|
|
161
|
|
|
|
|
96624
|
|
|
12
|
|
|
|
|
|
|
|
|
13
|
|
|
|
|
|
|
has filename => ( |
|
14
|
|
|
|
|
|
|
is => 'ro', |
|
15
|
|
|
|
|
|
|
isa => Str, |
|
16
|
|
|
|
|
|
|
); |
|
17
|
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
has tempname => ( |
|
19
|
|
|
|
|
|
|
is => 'ro', |
|
20
|
|
|
|
|
|
|
isa => Str, |
|
21
|
|
|
|
|
|
|
); |
|
22
|
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
has headers => ( |
|
24
|
|
|
|
|
|
|
is => 'ro', |
|
25
|
|
|
|
|
|
|
isa => HashRef, |
|
26
|
|
|
|
|
|
|
); |
|
27
|
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
has size => ( |
|
29
|
|
|
|
|
|
|
is => 'ro', |
|
30
|
|
|
|
|
|
|
isa => Num, |
|
31
|
|
|
|
|
|
|
); |
|
32
|
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
sub file_handle { |
|
34
|
23
|
|
|
23
|
1
|
18408
|
my ($self) = @_; |
|
35
|
23
|
100
|
|
|
|
139
|
return $self->{_fh} if defined $self->{_fh}; |
|
36
|
20
|
|
|
|
|
124
|
my $fh = open_file( '<', $self->tempname ); |
|
37
|
17
|
|
|
|
|
59
|
$self->{_fh} = $fh; |
|
38
|
|
|
|
|
|
|
} |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub copy_to { |
|
41
|
3
|
|
|
3
|
1
|
36
|
my ( $self, $target ) = @_; |
|
42
|
3
|
|
|
|
|
12
|
require_module('File::Copy'); |
|
43
|
3
|
|
|
|
|
5200
|
File::Copy::copy( $self->tempname, $target ); |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub link_to { |
|
47
|
3
|
|
|
3
|
1
|
3824
|
my ( $self, $target ) = @_; |
|
48
|
3
|
|
|
|
|
304
|
CORE::link( $self->tempname, $target ); |
|
49
|
|
|
|
|
|
|
} |
|
50
|
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
sub content { |
|
52
|
20
|
|
|
20
|
1
|
135
|
my ( $self, $layer ) = @_; |
|
53
|
|
|
|
|
|
|
return $self->{_content} |
|
54
|
20
|
100
|
|
|
|
87
|
if defined $self->{_content}; |
|
55
|
|
|
|
|
|
|
|
|
56
|
17
|
50
|
|
|
|
51
|
$layer = ':raw' unless $layer; |
|
57
|
|
|
|
|
|
|
|
|
58
|
17
|
|
|
|
|
37
|
my $content = undef; |
|
59
|
17
|
|
|
|
|
60
|
my $handle = $self->file_handle; |
|
60
|
|
|
|
|
|
|
|
|
61
|
17
|
|
|
|
|
118
|
binmode( $handle, $layer ); |
|
62
|
|
|
|
|
|
|
|
|
63
|
17
|
|
|
|
|
107
|
while ( $handle->read( my $buffer, 8192 ) ) { |
|
64
|
17
|
|
|
|
|
851
|
$content .= $buffer; |
|
65
|
|
|
|
|
|
|
} |
|
66
|
|
|
|
|
|
|
|
|
67
|
17
|
|
|
|
|
302
|
$self->{_content} = $content; |
|
68
|
|
|
|
|
|
|
} |
|
69
|
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
sub basename { |
|
71
|
3
|
|
|
3
|
1
|
2070
|
my ($self) = @_; |
|
72
|
3
|
|
|
|
|
20
|
require_module('File::Basename'); |
|
73
|
3
|
|
|
|
|
1376
|
File::Basename::basename( $self->filename ); |
|
74
|
|
|
|
|
|
|
} |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
sub type { |
|
77
|
3
|
|
|
3
|
1
|
11
|
my $self = shift; |
|
78
|
3
|
|
|
|
|
23
|
return $self->headers->{'Content-Type'}; |
|
79
|
|
|
|
|
|
|
} |
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
1; |
|
82
|
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
__END__ |