line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Egg::Request::Upload; |
2
|
|
|
|
|
|
|
# |
3
|
|
|
|
|
|
|
# Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt> |
4
|
|
|
|
|
|
|
# |
5
|
|
|
|
|
|
|
# $Id: Upload.pm 337 2008-05-14 12:30:09Z lushe $ |
6
|
|
|
|
|
|
|
# |
7
|
1
|
|
|
1
|
|
385
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
30
|
|
8
|
1
|
|
|
1
|
|
4
|
use warnings; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
26
|
|
9
|
1
|
|
|
1
|
|
5
|
use Carp qw/croak/; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
50
|
|
10
|
1
|
|
|
1
|
|
5
|
use base qw/ Class::Accessor::Fast /; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
444
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION= '3.00'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
__PACKAGE__->mk_accessors(qw/ name handle /); |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
sub new { |
17
|
0
|
|
|
0
|
1
|
|
my($class, $req)= splice @_, 0, 2; |
18
|
0
|
|
0
|
|
|
|
my $name = shift || croak q{ I want upload param name. }; |
19
|
0
|
|
0
|
|
|
|
my $handle= $req->r->upload($name) || return (undef); |
20
|
0
|
|
|
|
|
|
bless { name=> $name, r=> $req->r, handle=> $handle }, $class; |
21
|
|
|
|
|
|
|
} |
22
|
|
|
|
|
|
|
*fh = \&handle; |
23
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
sub catfilename { |
25
|
0
|
|
|
0
|
1
|
|
my($up)= @_; |
26
|
0
|
|
0
|
|
|
|
my $filename= $up->filename || return (undef); |
27
|
0
|
0
|
|
|
|
|
$filename=~m{([^\\\/]+)$} ? $1: undef; |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
sub copy_to { |
30
|
0
|
|
|
0
|
1
|
|
my $up= shift; |
31
|
0
|
|
|
|
|
|
File::Copy->require; |
32
|
0
|
|
|
|
|
|
File::Copy::copy($up->tempname, @_); |
33
|
|
|
|
|
|
|
} |
34
|
|
|
|
|
|
|
sub link_to { |
35
|
0
|
|
|
0
|
1
|
|
my $up= shift; |
36
|
0
|
|
|
|
|
|
link($up->tempname, @_); |
37
|
|
|
|
|
|
|
} |
38
|
0
|
|
|
0
|
|
|
sub _setup { @_ } |
39
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
1; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
__END__ |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
=head1 NAME |
45
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
Egg::Request::Upload - Base class for file upload. |
47
|
|
|
|
|
|
|
|
48
|
|
|
|
|
|
|
=head1 SYNOPSIS |
49
|
|
|
|
|
|
|
|
50
|
|
|
|
|
|
|
use Egg qw/ Request::Upload /; |
51
|
|
|
|
|
|
|
|
52
|
|
|
|
|
|
|
# Acquisition of up-loading object. |
53
|
|
|
|
|
|
|
my $upload= $e->request->upload('upload_param_name'); |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
=head1 DESCRIPTION |
56
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
This is a base class for the file upload. |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
The plugin to use this module is prepared. |
60
|
|
|
|
|
|
|
|
61
|
|
|
|
|
|
|
Please load L<Egg::Plugin::Request::Upload> to use it. |
62
|
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
Whether the plugin is used in the mod_perl environment is distinguished and the |
64
|
|
|
|
|
|
|
best following subclasses are read. |
65
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
L<Egg::Request::Upload::ModPerl>, L<Egg::Request::Upload::CGI>, |
67
|
|
|
|
|
|
|
|
68
|
|
|
|
|
|
|
Please set environment variable 'POST_MAX' to the high limit setting of the size |
69
|
|
|
|
|
|
|
of the upload file. |
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
Please set environment variable 'TEMP_DIR' temporarily to set passing the work |
72
|
|
|
|
|
|
|
file. |
73
|
|
|
|
|
|
|
|
74
|
|
|
|
|
|
|
Please refer to the document of mod_perl and CGI.pm for details for the environment |
75
|
|
|
|
|
|
|
variable. |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
=head1 METHODS |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=head2 new ([REQUEST_CONTEXT], [PARAM_NAME]) |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
Constructor. |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
The L<Egg::Request> object is received with REQUEST_CONTEXT. |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
When $e-E<gt>request-E<gt>upload is called, this method is internally called. |
86
|
|
|
|
|
|
|
|
87
|
|
|
|
|
|
|
When any REQUEST_CONTEXT-E<gt>r-E<gt>upload(PARAM_NAME) doesn't return it, |
88
|
|
|
|
|
|
|
undefined is returned. |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
my $upload= $e->request->upload( ...... ) || die 'There is no upload file.'; |
91
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
=head2 handle |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
The file steering wheel to the preservation place of the up-loading file is |
95
|
|
|
|
|
|
|
temporarily returned. |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
my $value= join '', $upload->handle->getlines; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
=over 4 |
100
|
|
|
|
|
|
|
|
101
|
|
|
|
|
|
|
=item * Alias = fh |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
=back |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
=head2 catfilename |
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
Only the file name that doesn't contain the directory path of the upload file |
108
|
|
|
|
|
|
|
is returned. |
109
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
my $filename= $upload->catfilename; |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
=head2 copy_to ([COPY_PATH]) |
113
|
|
|
|
|
|
|
|
114
|
|
|
|
|
|
|
The upload file of the work place is temporarily copied to COPY_PATH. |
115
|
|
|
|
|
|
|
|
116
|
|
|
|
|
|
|
$upload->copy_to("/path/to/upload/$filename"); |
117
|
|
|
|
|
|
|
|
118
|
|
|
|
|
|
|
=head2 link_to ([LINK_PATH]) |
119
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
The hard link of the upload file of the work place is temporarily made in |
121
|
|
|
|
|
|
|
LINK_PATH. |
122
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
$upload->link_to("/path/to/upload/$filename"); |
124
|
|
|
|
|
|
|
|
125
|
|
|
|
|
|
|
=head1 SEE ALSO |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
L<Egg::Release>, |
128
|
|
|
|
|
|
|
L<Egg::Request>, |
129
|
|
|
|
|
|
|
L<Egg::Request::Upload>, |
130
|
|
|
|
|
|
|
L<Egg::Request::Upload::CGI>, |
131
|
|
|
|
|
|
|
L<Egg::Request::Upload::ModPerl>, |
132
|
|
|
|
|
|
|
L<Egg::Plugin::Request::Upload>, |
133
|
|
|
|
|
|
|
L<Class::Accessor::Fast>, |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
=head1 AUTHOR |
136
|
|
|
|
|
|
|
|
137
|
|
|
|
|
|
|
Masatoshi Mizuno E<lt>lusheE<64>cpan.orgE<gt> |
138
|
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
Copyright (C) 2008 Bee Flag, Corp. E<lt>L<http://egg.bomcity.com/>E<gt>. |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
This library is free software; you can redistribute it and/or modify |
144
|
|
|
|
|
|
|
it under the same terms as Perl itself, either Perl version 5.8.6 or, |
145
|
|
|
|
|
|
|
at your option, any later version of Perl 5 you may have available. |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
=cut |
148
|
|
|
|
|
|
|
|