Filename | /var/www/foswiki11/lib/Foswiki/Request/Upload.pm |
Statements | Executed 9 statements in 393µs |
Calls | P | F | Exclusive Time |
Inclusive Time |
Subroutine |
---|---|---|---|---|---|
1 | 1 | 1 | 16µs | 32µs | BEGIN@13 | Foswiki::Request::Upload::
1 | 1 | 1 | 11µs | 18µs | BEGIN@14 | Foswiki::Request::Upload::
1 | 1 | 1 | 10µs | 26µs | BEGIN@15 | Foswiki::Request::Upload::
1 | 1 | 1 | 4µs | 4µs | BEGIN@17 | Foswiki::Request::Upload::
0 | 0 | 0 | 0s | 0s | finish | Foswiki::Request::Upload::
0 | 0 | 0 | 0s | 0s | handle | Foswiki::Request::Upload::
0 | 0 | 0 | 0s | 0s | new | Foswiki::Request::Upload::
0 | 0 | 0 | 0s | 0s | tmpFileName | Foswiki::Request::Upload::
0 | 0 | 0 | 0s | 0s | uploadInfo | Foswiki::Request::Upload::
Line | State ments |
Time on line |
Calls | Time in subs |
Code |
---|---|---|---|---|---|
1 | # See bottom of file for license and copyright information | ||||
2 | |||||
3 | =begin TML | ||||
4 | |||||
5 | ---+!! package Foswiki::Request::Upload | ||||
6 | |||||
7 | Class to encapsulate uploaded file info. | ||||
8 | |||||
9 | =cut | ||||
10 | |||||
11 | package Foswiki::Request::Upload; | ||||
12 | |||||
13 | 2 | 34µs | 2 | 49µs | # spent 32µs (16+16) within Foswiki::Request::Upload::BEGIN@13 which was called:
# once (16µs+16µs) by Foswiki::Engine::CLI::BEGIN@24 at line 13 # spent 32µs making 1 call to Foswiki::Request::Upload::BEGIN@13
# spent 16µs making 1 call to strict::import |
14 | 2 | 34µs | 2 | 25µs | # spent 18µs (11+7) within Foswiki::Request::Upload::BEGIN@14 which was called:
# once (11µs+7µs) by Foswiki::Engine::CLI::BEGIN@24 at line 14 # spent 18µs making 1 call to Foswiki::Request::Upload::BEGIN@14
# spent 7µs making 1 call to warnings::import |
15 | 2 | 27µs | 2 | 43µs | # spent 26µs (10+16) within Foswiki::Request::Upload::BEGIN@15 which was called:
# once (10µs+16µs) by Foswiki::Engine::CLI::BEGIN@24 at line 15 # spent 26µs making 1 call to Foswiki::Request::Upload::BEGIN@15
# spent 16µs making 1 call to Assert::import |
16 | |||||
17 | 2 | 296µs | 1 | 4µs | # spent 4µs within Foswiki::Request::Upload::BEGIN@17 which was called:
# once (4µs+0s) by Foswiki::Engine::CLI::BEGIN@24 at line 17 # spent 4µs making 1 call to Foswiki::Request::Upload::BEGIN@17 |
18 | |||||
19 | =begin TML | ||||
20 | |||||
21 | ---++ ClassMethod new() | ||||
22 | |||||
23 | Constructs a Foswiki::Request::Upload object | ||||
24 | |||||
25 | =cut | ||||
26 | |||||
27 | sub new { | ||||
28 | my ( $proto, %args ) = @_; | ||||
29 | my $class = ref($proto) || $proto; | ||||
30 | my $this = { | ||||
31 | headers => $args{headers}, | ||||
32 | tmpname => $args{tmpname}, | ||||
33 | }; | ||||
34 | return bless $this, $class; | ||||
35 | } | ||||
36 | |||||
37 | =begin TML | ||||
38 | |||||
39 | ---++ ObjectMethod finish() | ||||
40 | |||||
41 | Deletes temp file associated. | ||||
42 | |||||
43 | =cut | ||||
44 | |||||
45 | # Note to developers; please undef *all* fields in the object explicitly, | ||||
46 | # whether they are references or not. That way this method is "golden | ||||
47 | # documentation" of the live fields in the object. | ||||
48 | sub finish { | ||||
49 | my $this = shift; | ||||
50 | undef $this->{headers}; | ||||
51 | |||||
52 | #SMELL: Note: untaint filename. Taken from CGI.pm | ||||
53 | # (had to be updated for OSX in Dec2008) | ||||
54 | $this->tmpFileName =~ m{^([a-zA-Z0-9_\+ \'\":/.\$\\~-]+)$}; | ||||
55 | my $file = $1; | ||||
56 | if ( scalar( unlink($file) ) != 1 ) { | ||||
57 | ASSERT( 0, "unable to unlink $file : $!" ) if DEBUG; | ||||
58 | throw Error::Simple("unable to unlink $file : $!"); | ||||
59 | } | ||||
60 | undef $this->{tmpname}; | ||||
61 | } | ||||
62 | |||||
63 | =begin TML | ||||
64 | |||||
65 | ---++ ObjectMethod uploadInfo() -> $headers | ||||
66 | |||||
67 | Returns a hashref to information about uploaded | ||||
68 | file as sent by browser. | ||||
69 | |||||
70 | =cut | ||||
71 | |||||
72 | sub uploadInfo { | ||||
73 | return $_[0]->{headers}; | ||||
74 | } | ||||
75 | |||||
76 | =begin TML | ||||
77 | |||||
78 | ---++ ObjectMethod handle() -> ( $fh ) | ||||
79 | |||||
80 | Returns an open filehandle to uploaded file. | ||||
81 | |||||
82 | =cut | ||||
83 | |||||
84 | sub handle { | ||||
85 | my $fh = new IO::File( $_[0]->{tmpname}, '<' ); | ||||
86 | binmode $fh; | ||||
87 | return $fh; | ||||
88 | } | ||||
89 | |||||
90 | =begin TML | ||||
91 | |||||
92 | ---++ ObjectMethod tmpFileName() -> ( $tmpName ) | ||||
93 | |||||
94 | Returns the names of temporarly created file. | ||||
95 | |||||
96 | =cut | ||||
97 | |||||
98 | sub tmpFileName { | ||||
99 | return $_[0]->{tmpname}; | ||||
100 | } | ||||
101 | |||||
102 | 1 | 3µs | 1; | ||
103 | __END__ |