OpenInteract2/Upload.pm

filter: Statementstmt 34.0% 16 / 47 Branchbran 0.0% 0 / 6 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 33.3% 4 / 12 Podpod 12.5% 1 / 8 totaltotal 26.9% 21 / 78 CC 6 SCAR 17.5
CC
6
Cov
29%
new
12.0
save_file
12.0
filename
6.0
CRAP 5.8
« OpenInteract2/Config/IniFile.pm ↑ Summary OpenInteract2/SessionManager/DBI.pm »
1 package OpenInteract2::Upload;
2  
3 # $Id: Upload.pm,v 1.6 2005/03/17 14:57:58 sjn Exp $
4  
5 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use base qw( Class::Accessor::Fast );
Subroutine BEGIN: called CC=1 SCAR=0.0
7 1 ▶use OpenInteract2::Exception qw( oi_error );
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use OpenInteract2::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
9  
10 1 $OpenInteract2::Upload::VERSION = sprintf("%d.%02d", q$Revision: 1.6 $ =~ /(\d+)\.(\d+)/);
11  
12 1 my @FIELDS = qw( name filehandle content_type size tmp_name );
13 1 OpenInteract2::Upload->mk_accessors( @FIELDS );
14  
15 0 ▶sub FUNNY_CHARACTERS { return '\\\'"!#\$\%\|&\^\*\<\>{}\[\]\(\)\?' }
Subroutine FUNNY_CHARACTERS: not called CC=1 SCAR=6.9
Pod undocumented
16  
17 ########################################
18 # CLASS METHODS
19  
20 # Constructor
21  
22 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
23 0 my ( $class, $params ) = @_;
24 0 my $self = bless( {}, $class );
25 0 foreach my $field ( ( @FIELDS, 'filename' ) ) {
26 0 ▶ next unless ( $params->{ $field } );
Branch: 1 branch
BranchTrueFalseTotal
unless $params->{$field} 0 0 0
27 0 $self->$field( $params->{ $field } );
28 }
29 0 return $self;
30 }
31  
32  
33 # Clean up the filename given by the client -- we could probably use
34 # File::Basename here, but we don't know what OS the client is running
35 # to set in fileparse_set_fstype(). This is called whenever you call
36 # the filename() set method
37  
38 0 ▶sub base_filename {
Subroutine base_filename: not called CC=1 SCAR=6.9
Pod undocumented
39 0 my ( $class, $name ) = @_;
40 0 $name =~ s|^.*/(.*)$|$1|;
41 0 $name =~ s|^.*\\(.*)$|$1|;
42 0 return $name;
43 }
44  
45  
46 0 ▶sub clean_filename {
Subroutine clean_filename: not called CC=1 SCAR=6.9
Pod undocumented
47 0 my ( $class, $name ) = @_;
48 0 $name =~ s/^\.+//;
49 0 $name =~ s/\.\./_/g;
50 0 $name =~ s/\s/_/g;
51 0 my $funny_chars = $class->FUNNY_CHARACTERS;
52 0 $name =~ s/[$funny_chars]//g;
53 0 return $name;
54 }
55  
56  
57 ########################################
58 # OBJECT METHODS
59  
60 # Not auto-generated by Class::Accessor so we can ensure the filename
61 # does not have any leading directories.
62  
63 0 ▶sub filename {
Subroutine filename: not called CC=2 SCAR=17.9
Pod undocumented
64 0 my ( $self, $filename ) = @_;
65 0 ▶ if ( $filename ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($filename) 0 0 0
66 0 $self->{filename} = $self->clean_filename( $self->base_filename( $filename ) );
67 }
68 0 return $self->{filename};
69 }
70  
71 # Common aliases
72  
73 0 ▶sub fh { my $self = shift; return $self->filehandle( @_ ); }
Subroutine fh: not called CC=1 SCAR=6.9
Pod undocumented
74 0 ▶sub type { my $self = shift; return $self->content_type( @_ ); }
Subroutine type: not called CC=1 SCAR=6.9
Pod undocumented
75  
76  
77 0 ▶sub save_file {
Subroutine save_file: not called CC=3 SCAR=24.8
Pod undocumented
78 0 my ( $self, $filename ) = @_;
79 0 ▶ unless ( $self->filehandle ) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->filehandle) 0 0 0
80 0 oi_error "Filehandle not set in upload object, cannot save";
81 }
82 0 ▶ $filename ||= $self->filename;
Condition0%0/3
$filename ||= $self->filename
l!l&&r!l&&!r
000
MC/DC0%0/2
$filename ||= $self->filename
$filename $self->filename
Truth table0%0/3
A ||= B
A= $filenameB= $self->filename
ABresult
1X1
011
000
83 0 return OpenInteract2::File->save_file( $self->filehandle, $filename );
84 }
85  
86 1 1;
87  
88 __END__
« OpenInteract2/Config/IniFile.pm ↑ Summary OpenInteract2/SessionManager/DBI.pm »