Many bugfixes,better docs
Sebastian Riedel [Wed, 2 Mar 2005 18:21:17 +0000 (18:21 +0000)]
Changes
Makefile.PL
README
lib/Catalyst.pm
lib/Catalyst/Engine.pm
lib/Catalyst/Engine/Apache.pm
lib/Catalyst/Engine/CGI.pm
lib/Catalyst/Helper.pm
lib/Catalyst/Request.pm
lib/Catalyst/Test.pm

diff --git a/Changes b/Changes
index 7695a0b..0db02ef 100644 (file)
--- a/Changes
+++ b/Changes
@@ -1,5 +1,15 @@
 This file documents the revision history for Perl extension Catalyst.
 
+4.11  Wed Mar 02 11:00:00 2005
+        - removed some warnings
+        - improved docs
+
+4.10  Wed Mar 02 10:00:00 2005
+        - improved documentation
+        - fixed upload bug
+        - fixed prefixed private actions bug
+        - fixed more little bugs
+
 4.01  Tue Mar 01 10:00:00 2005
         - improved documentation
         - documentation fixes (Johan Lindstrom)
index 4ff5625..2dda1b6 100644 (file)
@@ -15,8 +15,7 @@ WriteMakefile(
     }
 );
 
-my $gabb =
-  int( rand(2) ) == 1
-  ? "Gabbana is the greatest!"
-  : "Gabbana is drunk again!";
-print "$gabb\n";
+print(
+    (qw/draven naughton sri the_jester/)[ int( rand(4) ) ],
+    " is the greatest and gabb is drunk again!\n"
+);
diff --git a/README b/README
index 3ff93e9..a9e783d 100644 (file)
--- a/README
+++ b/README
@@ -3,19 +3,19 @@ NAME
 
 SYNOPSIS
         # use the helper to start a new application
-        catalyst MyApp
+        perl /path/to/catalyst MyApp
         cd MyApp
 
         # add models, views, controllers
-        bin/create model Something
-        bin/create view Stuff
-        bin/create controller Yada
+        perl bin/create model Something
+        perl bin/create view Stuff
+        perl bin/create controller Yada
 
         # built in testserver
-        bin/server
+        perl bin/server
 
         # command line interface
-        bin/test /yada
+        perl bin/test /yada
 
         See also L<Catalyst::Manual::Intro>
 
@@ -94,8 +94,8 @@ AUTHOR
     Sebastian Riedel, "sri@oook.de"
 
 THANK YOU
-    David Naughton, Gary Ashton Jones, Marcus Ramberg and all the others
-    who've helped.
+    Danijel Milicevic, David Naughton, Gary Ashton Jones, Jesse Sheidlower,
+    Johan Lindstrom, Marcus Ramberg and all the others who've helped.
 
 LICENSE
     This library is free software . You can redistribute it and/or modify it
index e49736f..d547702 100644 (file)
@@ -7,7 +7,7 @@ use Catalyst::Log;
 
 __PACKAGE__->mk_classdata($_) for qw/_config log/;
 
-our $VERSION = '4.01';
+our $VERSION = '4.11';
 our @ISA;
 
 =head1 NAME
@@ -17,19 +17,19 @@ Catalyst - The Elegant MVC Web Application Framework
 =head1 SYNOPSIS
 
     # use the helper to start a new application
-    catalyst MyApp
+    perl /path/to/catalyst MyApp
     cd MyApp
 
     # add models, views, controllers
-    bin/create model Something
-    bin/create view Stuff
-    bin/create controller Yada
+    perl bin/create model Something
+    perl bin/create view Stuff
+    perl bin/create controller Yada
 
     # built in testserver
-    bin/server
+    perl bin/server
 
     # command line interface
-    bin/test /yada
+    perl bin/test /yada
 
 
     See also L<Catalyst::Manual::Intro>
index a1ec313..5ef4639 100644 (file)
@@ -3,7 +3,6 @@ package Catalyst::Engine;
 use strict;
 use base qw/Class::Data::Inheritable Class::Accessor::Fast/;
 use UNIVERSAL::require;
-use B;
 use Data::Dumper;
 use HTML::Entities;
 use HTTP::Headers;
@@ -68,8 +67,7 @@ sub action {
     $_[1] ? ( $action = {@_} ) : ( $action = shift );
     if ( ref $action eq 'HASH' ) {
         while ( my ( $name, $code ) = each %$action ) {
-            my $class  = B::svref_2object($code)->STASH->NAME;
-            my $caller = caller(0);
+            my $class = caller(0);
             if ( $name =~ /^\/(.*)\/$/ ) {
                 my $regex = $1;
                 $self->actions->{compiled}->{qr/$regex/} = $name;
@@ -77,19 +75,18 @@ sub action {
             }
             elsif ( $name =~ /^\?(.*)$/ ) {
                 $name = $1;
-                $name = _prefix( $caller, $name );
+                $name = _prefix( $class, $name );
                 $self->actions->{plain}->{$name} = [ $class, $code ];
             }
             elsif ( $name =~ /^\!\?(.*)$/ ) {
                 $name = $1;
-                $name = _prefix( $caller, $name );
+                $name = _prefix( $class, $name );
                 $name = "\!$name";
                 $self->actions->{plain}->{$name} = [ $class, $code ];
             }
             else { $self->actions->{plain}->{$name} = [ $class, $code ] }
             $self->actions->{reverse}->{"$code"} = $name;
-            $self->log->debug(
-                qq/"$caller" defined "$name" as "$code" from "$class"/)
+            $self->log->debug(qq/"$class" defined "$name" as "$code"/)
               if $self->debug;
         }
     }
@@ -378,9 +375,11 @@ sub handler {
     eval {
         my $handler = sub {
             my $c = $class->prepare($r);
-            if ( $c->req->action ) {
+            if ( my $action = $c->action( $c->req->action ) ) {
                 my ( $begin, $end );
-                if ( my $prefix = $c->req->args->[0] ) {
+                my $class  = ${ $action->[0] }[0];
+                my $prefix = _class2prefix($class);
+                if ($prefix) {
                     if ( $c->actions->{plain}->{"\!$prefix/begin"} ) {
                         $begin = "\!$prefix/begin";
                     }
@@ -392,6 +391,12 @@ sub handler {
                     }
                     elsif ( $c->actions->{plain}->{'!end'} ) { $end = '!end' }
                 }
+                else {
+                    if ( $c->actions->{plain}->{'!begin'} ) {
+                        $begin = '!begin';
+                    }
+                    if ( $c->actions->{plain}->{'!end'} ) { $end = '!end' }
+                }
                 $c->forward($begin)            if $begin;
                 $c->forward( $c->req->action ) if $c->req->action;
                 $c->forward($end)              if $end;
@@ -400,7 +405,7 @@ sub handler {
                 my $action = $c->req->path;
                 my $error  = $action
                   ? qq/Unknown resource "$action"/
-                  : "Congratulations, you're on Catalyst!";
+                  : "No default action defined";
                 $c->log->error($error) if $c->debug;
                 $c->errors($error);
             }
@@ -479,7 +484,7 @@ sub prepare_action {
     my @path = split /\//, $c->req->path;
     $c->req->args( \my @args );
     while (@path) {
-        my $path = join '/', @path;
+        $path = join '/', @path;
         if ( my $result = $c->action($path) ) {
 
             # It's a regex
@@ -710,11 +715,17 @@ sub stash {
 
 sub _prefix {
     my ( $class, $name ) = @_;
+    my $prefix = _class2prefix($class);
+    $name = "$prefix/$name" if $prefix;
+    return $name;
+}
+
+sub _class2prefix {
+    my $class = shift;
     $class =~ /^.*::[(M)(Model)(V)(View)(C)(Controller)]+::(.*)$/;
     my $prefix = lc $1 || '';
     $prefix =~ s/\:\:/_/g;
-    $name = "$prefix/$name" if $prefix;
-    return $name;
+    return $prefix;
 }
 
 =head1 AUTHOR
index 97b3387..0bba6ad 100644 (file)
@@ -162,11 +162,10 @@ sub prepare_uploads {
     my $c = shift;
     for my $upload ( $c->apache_request->upload ) {
         $upload = $c->apache_request->upload($upload) if MP2;
-        $c->req->uploads->{ $upload->name } = {
-            fh       => $upload->fh,
-            filename => $upload->filename,
-            size     => $upload->size,
-            type     => $upload->type
+        $c->req->uploads->{ $upload->filename } = {
+            fh   => $upload->fh,
+            size => $upload->size,
+            type => $upload->type
         };
     }
 }
index c6d387a..44d1903 100644 (file)
@@ -7,6 +7,9 @@ use URI;
 require CGI::Simple;
 require CGI::Cookie;
 
+$CGI::Simple::POST_MAX        = 1048576;
+$CGI::Simple::DISABLE_UPLOADS = 0;
+
 __PACKAGE__->mk_accessors('cgi');
 
 =head1 NAME
@@ -115,6 +118,10 @@ sub prepare_path {
     $c->req->{path} =~ s/^($loc)?\///;
     $c->req->{path} .= '/' if $c->req->path eq $loc;
     my $base = $c->cgi->url;
+    if ( $ENV{CATALYST_TEST} ) {
+        my $script = $c->cgi->script_name;
+        $base =~ s/$script$//i;
+    }
     $base = URI->new($base);
     $base->path('/') if ( $ENV{CATALYST_TEST} || !$base->path );
     $c->req->base( $base->as_string );
@@ -133,12 +140,10 @@ sub prepare_request { shift->cgi( CGI::Simple->new ) }
 sub prepare_uploads {
     my $c = shift;
     for my $name ( $c->cgi->upload ) {
-        my $filename = $c->req->params->{$name};
         $c->req->uploads->{$name} = {
-            fh       => $c->cgi->upload($filename),
-            filename => $filename,
-            size     => $c->cgi->upload_info( $filename, 'size' ),
-            type     => $c->cgi->upload_info( $filename, 'mime' )
+            fh   => $c->cgi->upload($name),
+            size => $c->cgi->upload_info( $name, 'size' ),
+            type => $c->cgi->upload_info( $name, 'mime' )
         };
     }
 }
index 81258bc..d50fb16 100644 (file)
@@ -508,6 +508,26 @@ EOF
     }
 }
 
+=head1 HELPERS
+
+Helpers are classes that provide two methods.
+
+    * mk_compclass - creates the Component class
+    * mk_comptest  - creates the Component test
+
+So when you call C<bin/create view MyView TT>, create would try to execute
+Catalyst::Helper::View::TT->mk_compclass and
+Catalyst::Helper::View::TT->mk_comptest.
+
+See L<Catalyst::Helper::View::TT> and L<Catalyst::Helper::Model::CDBI> for
+examples.
+
+All helper classes should be under one of the following namespaces.
+
+    Catalyst::Helper::Model::
+    Catalyst::Helper::View::
+    Catalyst::Helper::Controller::
+
 =head1 SEE ALSO
 
 L<Catalyst::Manual>, L<Catalyst::Test>, L<Catalyst::Request>,
index 6e45e69..b63e48d 100644 (file)
@@ -5,7 +5,7 @@ use base 'Class::Accessor::Fast';
 
 __PACKAGE__->mk_accessors(
     qw/action arguments base cookies headers match method parameters path
-      snippets uploads user/
+      snippets uploads/
 );
 
 *args   = \&arguments;
@@ -87,14 +87,11 @@ Returns an arrayref containing regex snippets.
 
 Returns a hashref containing the uploads.
 
-    print $c->request->uploads->{foo}->filename;
-    print $c->request->uploads->{foo}->type;
-    print $c->request->uploads->{foo}->size;
-    my $fh = $c->request->uploads->{foo}->fh;
-
-=head3 user
-
-Returns the user.
+    my $filename = $c->req->parameters->{foo};
+    print $c->request->uploads->{$filename}->type;
+    print $c->request->uploads->{$filename}->size;
+    my $fh = $c->request->uploads->{$filename}->fh;
+    my $content = do { local $/; <$fh> };
 
 =head1 AUTHOR
 
index 58be192..926885b 100644 (file)
@@ -162,7 +162,7 @@ sub server {
         $ENV{REMOTE_ADDR}     = $peeraddr;
         $ENV{REMOTE_HOST}     = $peername;
         $ENV{QUERY_STRING}    = $query_string || '';
-        $ENV{CONTENT_TYPE}    ||= 'text/plain';
+        $ENV{CONTENT_TYPE}    ||= 'multipart/form-data';
         $ENV{SERVER_SOFTWARE} ||= "Catalyst/$Catalyst::VERSION";
         $class->run;
     }