lib/HTML/FormFu/UploadParam.pm

filter: Statementstmt 55.3% 31 / 56 Branchbran 7.1% 1 / 14 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 80.0% 8 / 10 Podpod 0.0% 0 / 3 totaltotal 48.1% 40 / 83 CC 8 SCAR 23.1
CC
8
Cov
46%
STORABLE_freeze
20.0
STORABLE_thaw
20.0
form
2.0
CRAP 10.1
« lib/HTML/FormFu/Constraint.pm ↑ Summary lib/HTML/FormFu/Constraint/Equal.pm »
1 13 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2  
3 package HTML::FormFu::UploadParam;
4 13 $HTML::FormFu::UploadParam::VERSION = '2.09';
5 # ABSTRACT: accessor class
6  
7 13 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 13 ▶use MooseX::Attribute::Chained;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 13 ▶use Carp qw( croak );
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 13 ▶use File::Temp qw( tempfile );
Subroutine BEGIN: called CC=1 SCAR=0.0
13 13 ▶use Scalar::Util qw( weaken );
Subroutine BEGIN: called CC=1 SCAR=0.0
14 13 ▶use Storable qw( nfreeze thaw );
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 13 has param => ( is => 'rw', traits => ['Chained'], required => 1 );
17 13 has filename => ( is => 'rw', traits => ['Chained'] );
18  
19 18 ▶sub form {
Subroutine form: called CC=2 SCAR=7.0
Pod undocumented
20 18 my $self = shift;
21  
22 18 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 18 0 18
23 18 $self->{form} = shift;
24  
25 18 weaken( $self->{form} );
26 }
27  
28 18 return $self->{form};
29 }
30  
31 0 ▶sub STORABLE_freeze {
Subroutine STORABLE_freeze: not called CC=4 SCAR=30.0
Pod undocumented
32 0 my ( $self, $cloning ) = @_;
33  
34 0 ▶ return if $cloning;
Branch: 1 branch
BranchTrueFalseTotal
if $cloning 0 0 0
35  
36 my $fh
37 = $self->{param}->can('fh')
38 ? $self->{param}->fh
39 0 ▶ : $self->{param};
Branch: 1 branch
BranchTrueFalseTotal
$self->{'param'}->can('fh') ? : 0 0 0
40  
41 0 seek $fh, 0, 0;
42  
43 0 local $/ = undef;
44 0 my $data = <$fh>;
45  
46 0 ▶ if ( defined( my $dir = $self->form->tmp_upload_dir ) ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined(my $dir = $self->form->tmp_upload_dir)) { } 0 0 0
47 0 my ( $fh, $filename ) = tempfile( DIR => $dir, UNLINK => 0 );
48  
49 0 print $fh $data;
50  
51 0 close $fh;
52  
53 0 return nfreeze( { filename => $filename } );
54 }
55 else {
56 0 return nfreeze( { param => $data } );
57 }
58 }
59  
60 0 ▶sub STORABLE_thaw {
Subroutine STORABLE_thaw: not called CC=4 SCAR=30.0
Pod undocumented
61 0 my ( $self, $cloning, $serialized ) = @_;
62  
63 0 ▶ return if $cloning;
Branch: 1 branch
BranchTrueFalseTotal
if $cloning 0 0 0
64  
65 0 my $data = thaw($serialized);
66  
67 0 my $filename = $data->{filename};
68  
69 0 ▶ if ($filename) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filename) { } 0 0 0
70 0 ▶ open my $fh, '<', $filename
Branch: 1 branch
BranchTrueFalseTotal
open my $fh, "<", $filename or croak("could not open file in tmp dir: '${filename}'") 0 0 0
71 or croak "could not open file in tmp dir: '$filename'";
72  
73 0 $self->{param} = $fh;
74 0 $self->{filename} = $filename;
75 }
76 else {
77 0 my ($fh) = tempfile();
78  
79 0 print $fh $data->{param};
80  
81 0 seek $fh, 0, 0;
82  
83 0 $self->{param} = $fh;
84 }
85  
86 0 return;
87 }
88  
89 13 __PACKAGE__->meta->make_immutable;
90  
91 13 1;
92  
93 __END__
« lib/HTML/FormFu/Constraint.pm ↑ Summary lib/HTML/FormFu/Constraint/Equal.pm »