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)
}
);
-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"
+);
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>
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
__PACKAGE__->mk_classdata($_) for qw/_config log/;
-our $VERSION = '4.01';
+our $VERSION = '4.11';
our @ISA;
=head1 NAME
=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>
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;
$_[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;
}
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;
}
}
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";
}
}
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;
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);
}
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
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
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
};
}
}
require CGI::Simple;
require CGI::Cookie;
+$CGI::Simple::POST_MAX = 1048576;
+$CGI::Simple::DISABLE_UPLOADS = 0;
+
__PACKAGE__->mk_accessors('cgi');
=head1 NAME
$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 );
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' )
};
}
}
}
}
+=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>,
__PACKAGE__->mk_accessors(
qw/action arguments base cookies headers match method parameters path
- snippets uploads user/
+ snippets uploads/
);
*args = \&arguments;
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
$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;
}