lib/Dancer2/Core/Request/Upload.pm

filter: Statementstmt 100% 41 / 41 Branchbran 87.5% 7 / 8 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 11 / 11 Podpod 100% 6 / 6 totaltotal 98.4% 65 / 66 CC 5 SCAR 6.6
CC
5
Cov
98%
content
4.0
file_handle
2.0
BEGIN
1.0
CRAP 1.9
« blib/lib/auto/share/dist/Dancer2/skel/tutorial/lib/AppFile/Schema/Result/User.pm ↑ Summary lib/Dancer2/Core/Factory.pm »
1 package Dancer2::Core::Request::Upload;
2 # ABSTRACT: Class representing file upload requests
3 192 $Dancer2::Core::Request::Upload::VERSION = '2.3.0';
4 192 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 192 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 192 ▶use Path::Tiny ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 192 ▶use File::Copy ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 192 ▶use Dancer2::Core::Types;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 192 has filename => (
13 is => 'ro',
14 isa => Str,
15 );
16  
17 192 has tempname => (
18 is => 'ro',
19 isa => Str,
20 );
21  
22 192 has headers => (
23 is => 'ro',
24 isa => HashRef,
25 );
26  
27 192 has size => (
28 is => 'ro',
29 isa => Num,
30 );
31  
32 20 ▶sub file_handle {
Subroutine file_handle: called CC=2 SCAR=6.9
Pod documented
33 20 my ($self) = @_;
34 20 ▶ return $self->{_fh} if defined $self->{_fh};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_fh"} 3 17 20
35 17 $self->{_fh} = Path::Tiny::path( $self->tempname )->openr_raw;
36 }
37  
38 3 ▶sub copy_to {
Subroutine copy_to: called CC=1 SCAR=0.0
Pod documented
39 3 my ( $self, $target ) = @_;
40 3 File::Copy::copy( $self->tempname, $target );
41 }
42  
43 3 ▶sub link_to {
Subroutine link_to: called CC=1 SCAR=0.0
Pod documented
44 3 my ( $self, $target ) = @_;
45 3 CORE::link( $self->tempname, $target );
46 }
47  
48 20 ▶sub content {
Subroutine content: called CC=4 SCAR=13.9
Pod documented
49 20 my ( $self, $layer ) = @_;
50 return $self->{_content}
51 20 ▶ if defined $self->{_content};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"_content"} 3 17 20
52  
53 17 ▶ $layer = ':raw' unless $layer;
Branch: 1 branch
BranchTrueFalseTotal
unless $layer 17 0 17
54  
55 17 my $content = undef;
56 17 my $handle = $self->file_handle;
57  
58 17 binmode( $handle, $layer );
59  
60 17 ▶ while ( $handle->read( my $buffer, 8192 ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($handle->read(my $buffer, 8192)) 17 17 34
61 17 $content .= $buffer;
62 }
63  
64 17 $self->{_content} = $content;
65 }
66  
67 3 ▶sub basename {
Subroutine basename: called CC=1 SCAR=0.0
Pod documented
68 3 my ($self) = @_;
69 3 return Path::Tiny::path( $self->filename )->basename;
70 }
71  
72 3 ▶sub type {
Subroutine type: called CC=1 SCAR=0.0
Pod documented
73 3 my $self = shift;
74 3 return $self->headers->{'Content-Type'};
75 }
76  
77 192 1;
78  
79 __END__
« blib/lib/auto/share/dist/Dancer2/skel/tutorial/lib/AppFile/Schema/Result/User.pm ↑ Summary lib/Dancer2/Core/Factory.pm »