blib/lib/Dancer/Request/Upload.pm

filter: Statementstmt 100% 48 / 48 Branchbran 70.0% 7 / 10 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 13 / 13 Podpod 100% 6 / 6 totaltotal 96.1% 74 / 77 SCAR 17.9
CC
6
Cov
95%
content
4.0
file_handle
3.0
BEGIN
1.0
CRAP 6.0
« blib/lib/Dancer/MIME.pm ↑ Summary blib/lib/Dancer/Hook/Properties.pm »
1 package Dancer::Request::Upload;
2 199 our $AUTHORITY = 'cpan:SUKRIA';
3 #ABSTRACT: class representing file uploads requests
4 199 $Dancer::Request::Upload::VERSION = '1.3520';
5 199 ▶use File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 199 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 199 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 199 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 199 ▶use base 'Dancer::Object';
Subroutine BEGIN: called CC=1 SCAR=0.0
11 199 ▶use Dancer::FileUtils qw(open_file);
Subroutine BEGIN: called CC=1 SCAR=0.0
12 199 ▶use Dancer::Exception qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 199 Dancer::Request::Upload->attributes(
15 qw(
16 filename tempname headers size
17 )
18 );
19  
20 sub file_handle {
21 11 ▶ my ($self) = @_;
Subroutine file_handle: called CC=3 SCAR=11.0
Pod documented
22 11 ▶ return $self->{_fh} if defined $self->{_fh};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_fh"} 1 10 11
23 10 ▶ my $fh = open_file('<', $self->tempname)
Branch: 1 branch
BranchTrueFalseTotal
my $fh = open_file("<", $self->tempname) or &raise("core_request", q[Can't open `] . $self->tempname . "' for reading: $!") 0 10 10
24 or raise core_request => "Can't open `" . $self->tempname . "' for reading: $!";
25 10 $self->{_fh} = $fh;
26 }
27  
28 sub copy_to {
29 1 ▶ my ($self, $target) = @_;
Subroutine copy_to: called CC=1 SCAR=0.0
Pod documented
30 1 require File::Copy;
31 1 File::Copy::copy($self->{tempname}, $target);
32 }
33  
34 sub link_to {
35 1 ▶ my ($self, $target) = @_;
Subroutine link_to: called CC=1 SCAR=0.0
Pod documented
36 1 CORE::link($self->{tempname}, $target);
37 }
38  
39 sub content {
40 10 ▶ my ($self, $layer) = @_;
Subroutine content: called CC=4 SCAR=14.0
Pod documented
41 return $self->{_content}
42 10 ▶ if defined $self->{_content};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_content"} 0 10 10
43  
44 10 ▶ $layer = ':raw' unless $layer;
Branch: 1 branch
BranchTrueFalseTotal
unless $layer 10 0 10
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
BranchTrueFalseTotal
if ($handle->read(my $buffer, 8192)) 10 10 20
52 10 $content .= $buffer;
53 }
54  
55 10 $self->{_content} = $content;
56 }
57  
58 sub basename {
59 1 ▶ my ($self) = @_;
Subroutine basename: called CC=1 SCAR=0.0
Pod documented
60 1 require File::Basename;
61 1 File::Basename::basename($self->filename);
62 }
63  
64 sub type {
65 1 ▶ my $self = shift;
Subroutine type: called CC=1 SCAR=0.0
Pod documented
66  
67 1 return $self->headers->{'Content-Type'};
68 }
69  
70  
71  
72 # private
73  
74  
75 199 1;
76  
77 __END__
« blib/lib/Dancer/MIME.pm ↑ Summary blib/lib/Dancer/Hook/Properties.pm »