X-Git-Url: http://git.shadowcat.co.uk/gitweb/gitweb.cgi?p=catagits%2FCatalyst-Runtime.git;a=blobdiff_plain;f=lib%2FCatalyst%2FRequest%2FUpload.pm;h=e9ba6f2b61541ee55bac329ae868fe99d023fbc2;hp=59168d05fa28ad7bdb661458797fdd9a40d31656;hb=536bee890cf24e0e4bcda7562e7b70cc03ca0620;hpb=ac5c933bdd463558e8d621507a53a7b247a9093e diff --git a/lib/Catalyst/Request/Upload.pm b/lib/Catalyst/Request/Upload.pm index 59168d0..e9ba6f2 100644 --- a/lib/Catalyst/Request/Upload.pm +++ b/lib/Catalyst/Request/Upload.pm @@ -1,18 +1,19 @@ package Catalyst::Request::Upload; use Moose; +with 'MooseX::Emulate::Class::Accessor::Fast'; use Catalyst::Exception; use File::Copy (); use IO::File (); use File::Spec::Unix; -has filename => (is => 'rw'); -has headers => (is => 'rw'); -has size => (is => 'rw'); -has tempname => (is => 'rw'); -has type => (is => 'rw'); -has basename => (is => 'rw'); +has filename => (is => 'rw'); +has headers => (is => 'rw'); +has size => (is => 'rw'); +has tempname => (is => 'rw'); +has type => (is => 'rw'); +has basename => (is => 'ro', lazy_build => 1); has fh => ( is => 'rw', @@ -32,6 +33,15 @@ has fh => ( }, ); +sub _build_basename { + my $self = shift; + my $basename = $self->filename; + $basename =~ s|\\|/|g; + $basename = ( File::Spec::Unix->splitpath($basename) )[2]; + $basename =~ s|[^\w\.-]+|_|g; + return $basename; +} + no Moose; =head1 NAME @@ -40,6 +50,8 @@ Catalyst::Request::Upload - handles file upload requests =head1 SYNOPSIS + my $upload = $c->req->upload('field'); + $upload->basename; $upload->copy_to; $upload->fh; @@ -56,11 +68,6 @@ option in the Catalyst config. If unset, Catalyst will use the system temp dir. __PACKAGE__->config( uploadtmp => '/path/to/tmpdir' ); -It is provided a way to have configurable temporary directory. -If there is no config uploadtmp, system temprary directory will used. - - __PACKAGE__->config( uploadtmp => '/path/to/tmpdir' ); - See also L. =head1 DESCRIPTION @@ -142,19 +149,6 @@ sub slurp { return $content; } -sub basename { - my $self = shift; - unless ( $self->{basename} ) { - my $basename = $self->filename; - $basename =~ s|\\|/|g; - $basename = ( File::Spec::Unix->splitpath($basename) )[2]; - $basename =~ s|[^\w\.-]+|_|g; - $self->{basename} = $basename; - } - - return $self->{basename}; -} - =head2 $upload->basename Returns basename for C. @@ -173,13 +167,11 @@ Provided by Moose =head1 AUTHORS -Sebastian Riedel, C - -Christian Hansen, C +Catalyst Contributors, see Catalyst.pm =head1 COPYRIGHT -This program is free software, you can redistribute it and/or modify +This library is free software. You can redistribute it and/or modify it under the same terms as Perl itself. =cut