| 1 | package Dancer::Request::Upload; | ||||||||||
| 2 | 208 | our $AUTHORITY = 'cpan:SUKRIA'; | |||||||||
| 3 | #ABSTRACT: class representing file uploads requests | ||||||||||
| 4 | 208 | $Dancer::Request::Upload::VERSION = '1.3522'; | |||||||||
| 5 | 208 | ▶ | use File::Spec; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 6 | 208 | ▶ | use Carp; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 7 | |||||||||||
| 8 | 208 | ▶ | use strict; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 9 | 208 | ▶ | use warnings; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 10 | 208 | ▶ | use base 'Dancer::Object'; | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 11 | 208 | ▶ | use Dancer::FileUtils qw(open_file); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 12 | 208 | ▶ | use Dancer::Exception qw(:all); | ||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||
| 13 | |||||||||||
| 14 | 208 | Dancer::Request::Upload->attributes( | |||||||||
| 15 | qw( | ||||||||||
| 16 | filename tempname headers size | ||||||||||
| 17 | ) | ||||||||||
| 18 | ); | ||||||||||
| 19 | |||||||||||
| 20 | 11 | ▶ | sub file_handle { | ||||||||
|
Subroutine
file_handle: called CC=3 SCAR=11.0
Pod
documented
| |||||||||||
| 21 | 11 | my ($self) = @_; | |||||||||
| 22 | 11 | ▶ | return $self->{_fh} if defined $self->{_fh}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 23 | 10 | ▶ | my $fh = open_file('<', $self->tempname) | ||||||||
|
Branch: 1 branch
| |||||||||||
| 24 | or raise core_request => "Can't open `" . $self->tempname . "' for reading: $!"; | ||||||||||
| 25 | 10 | $self->{_fh} = $fh; | |||||||||
| 26 | } | ||||||||||
| 27 | |||||||||||
| 28 | 1 | ▶ | sub copy_to { | ||||||||
|
Subroutine
copy_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 29 | 1 | my ($self, $target) = @_; | |||||||||
| 30 | 1 | require File::Copy; | |||||||||
| 31 | 1 | File::Copy::copy($self->{tempname}, $target); | |||||||||
| 32 | } | ||||||||||
| 33 | |||||||||||
| 34 | 1 | ▶ | sub link_to { | ||||||||
|
Subroutine
link_to: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 35 | 1 | my ($self, $target) = @_; | |||||||||
| 36 | 1 | CORE::link($self->{tempname}, $target); | |||||||||
| 37 | } | ||||||||||
| 38 | |||||||||||
| 39 | 10 | ▶ | sub content { | ||||||||
|
Subroutine
content: called CC=4 SCAR=14.0
Pod
documented
| |||||||||||
| 40 | 10 | my ($self, $layer) = @_; | |||||||||
| 41 | return $self->{_content} | ||||||||||
| 42 | 10 | ▶ | if defined $self->{_content}; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 43 | |||||||||||
| 44 | 10 | ▶ | $layer = ':raw' unless $layer; | ||||||||
|
Branch: 1 branch
| |||||||||||
| 45 | |||||||||||
| 46 | 10 | my $content = undef; | |||||||||
| 47 | 10 | my $handle = $self->file_handle; | |||||||||
| 48 | |||||||||||
| 49 | 10 | binmode($handle, $layer); | |||||||||
| 50 | |||||||||||
| 51 | 10 | ▶ | while ($handle->read(my $buffer, 8192)) { | ||||||||
|
Branch: 1 branch
| |||||||||||
| 52 | 10 | $content .= $buffer; | |||||||||
| 53 | } | ||||||||||
| 54 | |||||||||||
| 55 | 10 | $self->{_content} = $content; | |||||||||
| 56 | } | ||||||||||
| 57 | |||||||||||
| 58 | 1 | ▶ | sub basename { | ||||||||
|
Subroutine
basename: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 59 | 1 | my ($self) = @_; | |||||||||
| 60 | 1 | require File::Basename; | |||||||||
| 61 | 1 | File::Basename::basename($self->filename); | |||||||||
| 62 | } | ||||||||||
| 63 | |||||||||||
| 64 | 1 | ▶ | sub type { | ||||||||
|
Subroutine
type: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||
| 65 | 1 | my $self = shift; | |||||||||
| 66 | |||||||||||
| 67 | 1 | return $self->headers->{'Content-Type'}; | |||||||||
| 68 | } | ||||||||||
| 69 | |||||||||||
| 70 | |||||||||||
| 71 | |||||||||||
| 72 | # private | ||||||||||
| 73 | |||||||||||
| 74 | |||||||||||
| 75 | 208 | 1; | |||||||||
| 76 | |||||||||||
| 77 | __END__ | ||||||||||