blib/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 blib/lib/Dancer2/Core/Factory.pm »
1 package Dancer2::Core::Request::Upload;
2 # ABSTRACT: Class representing file upload requests
3 188 $Dancer2::Core::Request::Upload::VERSION = '2.2.1';
4 188 ▶use Moo;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 188 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 188 ▶use Path::Tiny ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 188 ▶use File::Copy ();
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 188 ▶use Dancer2::Core::Types;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 188 has filename => (
13 is => 'ro',
14 isa => Str,
15 );
16  
17 188 has tempname => (
18 is => 'ro',
19 isa => Str,
20 );
21  
22 188 has headers => (
23 is => 'ro',
24 isa => HashRef,
25 );
26  
27 188 has size => (
28 is => 'ro',
29 isa => Num,
30 );
31  
32 sub file_handle {
33 20 ▶ my ($self) = @_;
Subroutine file_handle: called CC=2 SCAR=6.9
Pod documented
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 sub copy_to {
39 3 ▶ my ( $self, $target ) = @_;
Subroutine copy_to: called CC=1 SCAR=0.0
Pod documented
40 3 File::Copy::copy( $self->tempname, $target );
41 }
42  
43 sub link_to {
44 3 ▶ my ( $self, $target ) = @_;
Subroutine link_to: called CC=1 SCAR=0.0
Pod documented
45 3 CORE::link( $self->tempname, $target );
46 }
47  
48 sub content {
49 20 ▶ my ( $self, $layer ) = @_;
Subroutine content: called CC=4 SCAR=13.9
Pod documented
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 sub basename {
68 3 ▶ my ($self) = @_;
Subroutine basename: called CC=1 SCAR=0.0
Pod documented
69 3 return Path::Tiny::path( $self->filename )->basename;
70 }
71  
72 sub type {
73 3 ▶ my $self = shift;
Subroutine type: called CC=1 SCAR=0.0
Pod documented
74 3 return $self->headers->{'Content-Type'};
75 }
76  
77 188 1;
78  
79 __END__
« blib/lib/auto/share/dist/Dancer2/skel/tutorial/lib/AppFile/Schema/Result/User.pm ↑ Summary blib/lib/Dancer2/Core/Factory.pm »