Fixed run-on sentence in COPYRIGHT and s/program/library/
[catagits/Catalyst-Runtime.git] / lib / Catalyst / Request / Upload.pm
index d496aa1..e9ba6f2 100644 (file)
@@ -1,20 +1,19 @@
 package Catalyst::Request::Upload;
 
-use strict;
+use Moose;
+with 'MooseX::Emulate::Class::Accessor::Fast';
 
 use Catalyst::Exception;
 use File::Copy ();
 use IO::File   ();
 use File::Spec::Unix;
 
-use Moose;
-
-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',
@@ -34,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
@@ -42,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;
@@ -58,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<Catalyst>.
 
 =head1 DESCRIPTION
@@ -144,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<filename>.
@@ -175,15 +167,15 @@ Provided by Moose
 
 =head1 AUTHORS
 
-Sebastian Riedel, C<sri@cpan.org>
-
-Christian Hansen, C<ch@ngmedia.com>
+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
 
+__PACKAGE__->meta->make_immutable;
+
 1;