line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Dancer::Request::Upload; |
2
|
|
|
|
|
|
|
our $AUTHORITY = 'cpan:SUKRIA'; |
3
|
|
|
|
|
|
|
#ABSTRACT: class representing file uploads requests |
4
|
|
|
|
|
|
|
$Dancer::Request::Upload::VERSION = '1.3520'; |
5
|
182
|
|
|
182
|
|
1306
|
use File::Spec; |
|
182
|
|
|
|
|
405
|
|
|
182
|
|
|
|
|
6280
|
|
6
|
182
|
|
|
182
|
|
941
|
use Carp; |
|
182
|
|
|
|
|
383
|
|
|
182
|
|
|
|
|
8950
|
|
7
|
|
|
|
|
|
|
|
8
|
182
|
|
|
182
|
|
1079
|
use strict; |
|
182
|
|
|
|
|
506
|
|
|
182
|
|
|
|
|
4134
|
|
9
|
182
|
|
|
182
|
|
1052
|
use warnings; |
|
182
|
|
|
|
|
1792
|
|
|
182
|
|
|
|
|
6102
|
|
10
|
182
|
|
|
182
|
|
1085
|
use base 'Dancer::Object'; |
|
182
|
|
|
|
|
418
|
|
|
182
|
|
|
|
|
20865
|
|
11
|
182
|
|
|
182
|
|
1314
|
use Dancer::FileUtils qw(open_file); |
|
182
|
|
|
|
|
466
|
|
|
182
|
|
|
|
|
9668
|
|
12
|
182
|
|
|
182
|
|
1185
|
use Dancer::Exception qw(:all); |
|
182
|
|
|
|
|
589
|
|
|
182
|
|
|
|
|
101057
|
|
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Dancer::Request::Upload->attributes( |
15
|
|
|
|
|
|
|
qw( |
16
|
|
|
|
|
|
|
filename tempname headers size |
17
|
|
|
|
|
|
|
) |
18
|
|
|
|
|
|
|
); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
sub file_handle { |
21
|
11
|
|
|
11
|
1
|
21
|
my ($self) = @_; |
22
|
11
|
100
|
|
|
|
33
|
return $self->{_fh} if defined $self->{_fh}; |
23
|
10
|
50
|
|
|
|
34
|
my $fh = open_file('<', $self->tempname) |
24
|
|
|
|
|
|
|
or raise core_request => "Can't open `" . $self->tempname . "' for reading: $!"; |
25
|
10
|
|
|
|
|
32
|
$self->{_fh} = $fh; |
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
|
28
|
|
|
|
|
|
|
sub copy_to { |
29
|
1
|
|
|
1
|
1
|
18
|
my ($self, $target) = @_; |
30
|
1
|
|
|
|
|
599
|
require File::Copy; |
31
|
1
|
|
|
|
|
2614
|
File::Copy::copy($self->{tempname}, $target); |
32
|
|
|
|
|
|
|
} |
33
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
sub link_to { |
35
|
1
|
|
|
1
|
1
|
862
|
my ($self, $target) = @_; |
36
|
1
|
|
|
|
|
54
|
CORE::link($self->{tempname}, $target); |
37
|
|
|
|
|
|
|
} |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
sub content { |
40
|
10
|
|
|
10
|
1
|
935
|
my ($self, $layer) = @_; |
41
|
|
|
|
|
|
|
return $self->{_content} |
42
|
10
|
50
|
|
|
|
29
|
if defined $self->{_content}; |
43
|
|
|
|
|
|
|
|
44
|
10
|
50
|
|
|
|
27
|
$layer = ':raw' unless $layer; |
45
|
|
|
|
|
|
|
|
46
|
10
|
|
|
|
|
17
|
my $content = undef; |
47
|
10
|
|
|
|
|
24
|
my $handle = $self->file_handle; |
48
|
|
|
|
|
|
|
|
49
|
10
|
|
|
|
|
56
|
binmode($handle, $layer); |
50
|
|
|
|
|
|
|
|
51
|
10
|
|
|
|
|
38
|
while ($handle->read(my $buffer, 8192)) { |
52
|
10
|
|
|
|
|
383
|
$content .= $buffer; |
53
|
|
|
|
|
|
|
} |
54
|
|
|
|
|
|
|
|
55
|
10
|
|
|
|
|
163
|
$self->{_content} = $content; |
56
|
|
|
|
|
|
|
} |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
sub basename { |
59
|
1
|
|
|
1
|
1
|
463
|
my ($self) = @_; |
60
|
1
|
|
|
|
|
10
|
require File::Basename; |
61
|
1
|
|
|
|
|
4
|
File::Basename::basename($self->filename); |
62
|
|
|
|
|
|
|
} |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
sub type { |
65
|
1
|
|
|
1
|
1
|
4
|
my $self = shift; |
66
|
|
|
|
|
|
|
|
67
|
1
|
|
|
|
|
5
|
return $self->headers->{'Content-Type'}; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
|
72
|
|
|
|
|
|
|
# private |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
1; |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
__END__ |