/usr/share/perl5/Dancer/Request/Upload.pm is in libdancer-perl 1.3202+dfsg-1.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 | package Dancer::Request::Upload;
our $AUTHORITY = 'cpan:SUKRIA';
#ABSTRACT: class representing file uploads requests
$Dancer::Request::Upload::VERSION = '1.3202';
use File::Spec;
use Carp;
use strict;
use warnings;
use base 'Dancer::Object';
use Dancer::FileUtils qw(open_file);
use Dancer::Exception qw(:all);
Dancer::Request::Upload->attributes(
qw(
filename tempname headers size
)
);
sub file_handle {
my ($self) = @_;
return $self->{_fh} if defined $self->{_fh};
my $fh = open_file('<', $self->tempname)
or raise core_request => "Can't open `" . $self->tempname . "' for reading: $!";
$self->{_fh} = $fh;
}
sub copy_to {
my ($self, $target) = @_;
require File::Copy;
File::Copy::copy($self->{tempname}, $target);
}
sub link_to {
my ($self, $target) = @_;
CORE::link($self->{tempname}, $target);
}
sub content {
my ($self, $layer) = @_;
return $self->{_content}
if defined $self->{_content};
$layer = ':raw' unless $layer;
my $content = undef;
my $handle = $self->file_handle;
binmode($handle, $layer);
while ($handle->read(my $buffer, 8192)) {
$content .= $buffer;
}
$self->{_content} = $content;
}
sub basename {
my ($self) = @_;
require File::Basename;
File::Basename::basename($self->filename);
}
sub type {
my $self = shift;
return $self->headers->{'Content-Type'};
}
# private
1;
__END__
=pod
=encoding UTF-8
=head1 NAME
Dancer::Request::Upload - class representing file uploads requests
=head1 VERSION
version 1.3202
=head1 SYNOPSIS
# somewhere in your view:
<form action="/upload" method="POST" enctype="multipart/form-data">
<input type="file" name="filename">
<input type="submit">
</form>
# and then in your application handler:
post '/upload' => sub {
my $file = request->upload('filename');
$file->copy_to($upload_dir); # or whatever you need
};
=head1 DESCRIPTION
This class implements a representation of file uploads for Dancer.
These objects are accessible within route handlers via the request->uploads
keyword. See L<Dancer::Request> for details.
=head1 METHODS
=over 4
=item filename
Returns the filename as sent by the client.
=item basename
Returns basename for "filename".
=item tempname
Returns the name of the temporary file the data has been saved to.
This will be in e.g. /tmp, and given a random name, with no file extension.
=item link_to
Creates a hard link to the temporary file. Returns true for success,
false for failure.
$upload->link_to('/path/to/target');
=item file_handle
Returns a read-only file handle on the temporary file.
=item content
Returns a scalar containing the contents of the temporary file.
=item copy_to
Copies the temporary file using File::Copy. Returns true for success,
false for failure.
$upload->copy_to('/path/to/target')
=item size
The size of the upload, in bytes.
=item headers
Returns a hash ref of the headers associated with this upload.
=item type
The Content-Type of this upload.
=back
=head1 AUTHORS
This module as been written by Alexis Sukrieh, heavily based on
L<Plack::Request::Upload>. Kudos to Plack authors.
=head1 SEE ALSO
L<Dancer>
=head1 AUTHOR
Dancer Core Developers
=head1 COPYRIGHT AND LICENSE
This software is copyright (c) 2010 by Alexis Sukrieh.
This is free software; you can redistribute it and/or modify it under
the same terms as the Perl 5 programming language system itself.
=cut
|