Missed some changes, merged again from r1019
Andy Grundman [Mon, 10 Oct 2005 19:19:04 +0000 (19:19 +0000)]
lib/Catalyst/Log.pm
lib/Catalyst/Request/Upload.pm
lib/Catalyst/Setup.pm [deleted file]
lib/Catalyst/Utils.pm
script/catalyst.pl

index d9d03b8..deae3ca 100644 (file)
@@ -7,6 +7,8 @@ use Data::Dumper;
 our %LEVELS = ();
 
 __PACKAGE__->mk_accessors('level');
+__PACKAGE__->mk_accessors('body');
+__PACKAGE__->mk_accessors('abort');
 
 {
     my @levels = qw[ debug info warn error fatal ];
@@ -69,7 +71,18 @@ sub _log {
     my $level   = shift;
     my $time    = localtime(time);
     my $message = join( "\n", @_ );
-    printf( STDERR "[%s] [catalyst] [%s] %s\n", $time, $level, $message );
+    $self->{body} .= sprintf( "[%s] [catalyst] [%s] %s\n", 
+                    $time, $level, $message ) ;
+}
+
+sub _flush {
+    my $self    = shift;
+    if ( $self->abort || ! $self->body ) {
+       $self->abort(undef);
+    } else {
+       print( STDERR $self->body);
+    }
+    $self->body(undef);
 }
 
 1;
@@ -180,8 +193,20 @@ Disable log levels
 
 Is the log level active?
 
+=item abort
+
+Should Catalyst emit logs for this request? Will be reset at the end of 
+each request. 
+
+*NOTE* This method is not compatible with other log apis, so if you plan
+to use Log4Perl or another logger, you should call it like this:
+
+    $c->log->abort(1) if $c->log->can('abort');
+
 =back
 
+
+
 =head1 SEE ALSO
 
 L<Catalyst>.
index ff0b5de..25e6d89 100644 (file)
@@ -7,7 +7,7 @@ use Catalyst::Exception;
 use File::Copy ();
 use IO::File   ();
 
-__PACKAGE__->mk_accessors(qw/filename size tempname type/);
+__PACKAGE__->mk_accessors(qw/filename headers size tempname type/);
 
 sub new { shift->SUPER::new( ref( $_[0] ) ? $_[0] : {@_} ) }
 
@@ -20,6 +20,7 @@ Catalyst::Request::Upload - Catalyst Request Upload Class
     $upload->copy_to
     $upload->fh
     $upload->filename;
+    $upload->headers;
     $upload->link_to;
     $upload->size;
     $upload->slurp;
@@ -64,14 +65,13 @@ sub fh {
     my $self = shift;
 
     my $fh = IO::File->new( $self->tempname, IO::File::O_RDONLY );
-    
+
     unless ( defined $fh ) {
-        
+
         my $filename = $self->tempname;
-        
+
         Catalyst::Exception->throw(
-            message => qq/Can't open '$filename': '$!'/
-        );
+            message => qq/Can't open '$filename': '$!'/ );
     }
 
     return $fh;
@@ -81,6 +81,10 @@ sub fh {
 
 Contains client supplied filename.
 
+=item $upload->headers
+
+Returns a C<HTTP::Headers> object.
+
 =item $upload->link_to
 
 Creates a hard link to the tempname.  Returns true for success, 
@@ -108,7 +112,7 @@ Returns a scalar containing contents of tempname.
 sub slurp {
     my ( $self, $layer ) = @_;
 
-    unless ( $layer ) {
+    unless ($layer) {
         $layer = ':raw';
     }
 
diff --git a/lib/Catalyst/Setup.pm b/lib/Catalyst/Setup.pm
deleted file mode 100644 (file)
index be83e17..0000000
+++ /dev/null
@@ -1,426 +0,0 @@
-package Catalyst::Setup;
-
-use strict;
-use Catalyst::Exception;
-use Catalyst::Log;
-use Catalyst::Utils;
-use Path::Class;
-use Text::ASCIITable;
-
-require Module::Pluggable::Fast;
-
-=head1 NAME
-
-Catalyst::Setup - The Catalyst Setup class
-
-=head1 SYNOPSIS
-
-See L<Catalyst>.
-
-=head1 DESCRIPTION
-
-=head1 METHODS
-
-=over 4
-
-=item $c->setup
-
-Setup.
-
-    $c->setup;
-
-=cut
-
-sub setup {
-    my ( $class, @arguments ) = @_;
-
-    unless ( $class->isa('Catalyst') ) {
-
-        Catalyst::Exception->throw(
-            message => qq/'$class' does not inherit from Catalyst/
-        );
-    }
-    
-    if ( $class->arguments ) {
-        @arguments = ( @arguments, @{ $class->arguments } );
-    }
-
-    # Process options
-    my $flags = { };
-
-    foreach (@arguments) {
-
-        if ( /^-Debug$/ ) {
-            $flags->{log} = ( $flags->{log} ) ? 'debug,' . $flags->{log} : 'debug';
-        }
-        elsif (/^-(\w+)=?(.*)$/) {
-            $flags->{ lc $1 } = $2;
-        }
-        else {
-            push @{ $flags->{plugins} }, $_;
-        }
-    }
-
-    $class->setup_log        ( delete $flags->{log}        );
-    $class->setup_plugins    ( delete $flags->{plugins}    );
-    $class->setup_dispatcher ( delete $flags->{dispatcher} );
-    $class->setup_engine     ( delete $flags->{engine}     );
-    $class->setup_home       ( delete $flags->{home}       );
-
-    for my $flag ( sort keys %{ $flags } ) {
-
-        if ( my $code = $class->can( 'setup_' . $flag ) ) {
-            &$code( $class, delete $flags->{$flag} );
-        }
-        else {
-            $class->log->warn(qq/Unknown flag "$flag"/);
-        }
-    }
-
-    $class->log->warn( "You are running an old helper script! "
-          . "Please update your scripts by regenerating the "
-          . "application and copying over the new scripts." )
-      if ( $ENV{CATALYST_SCRIPT_GEN}
-        && ( $ENV{CATALYST_SCRIPT_GEN} < $Catalyst::CATALYST_SCRIPT_GEN ) );
-
-
-    if ( $class->debug ) {
-
-        my @plugins = ();
-
-        {
-            no strict 'refs';
-            @plugins = grep { /^Catalyst::Plugin/ } @{"$class\::ISA"};
-        }
-
-        if ( @plugins ) {
-            my $t = Text::ASCIITable->new;
-            $t->setOptions( 'hide_HeadRow',  1 );
-            $t->setOptions( 'hide_HeadLine', 1 );
-            $t->setCols('Class');
-            $t->setColWidth( 'Class', 75, 1 );
-            $t->addRow($_) for @plugins;
-            $class->log->debug( "Loaded plugins:\n" . $t->draw );
-        }
-
-        my $dispatcher = $class->dispatcher;
-        my $engine     = $class->engine;
-        my $home       = $class->config->{home};
-
-        $class->log->debug(qq/Loaded dispatcher "$dispatcher"/);
-        $class->log->debug(qq/Loaded engine "$engine"/);
-
-        $home
-          ? ( -d $home )
-          ? $class->log->debug(qq/Found home "$home"/)
-          : $class->log->debug(qq/Home "$home" doesn't exist/)
-          : $class->log->debug(q/Couldn't find home/);
-    }
-
-    # Call plugins setup
-    $class->NEXT::setup;
-
-    # Initialize our data structure
-    $class->components( {} );
-
-    $class->setup_components;
-
-    if ( $class->debug ) {
-        my $t = Text::ASCIITable->new;
-        $t->setOptions( 'hide_HeadRow',  1 );
-        $t->setOptions( 'hide_HeadLine', 1 );
-        $t->setCols('Class');
-        $t->setColWidth( 'Class', 75, 1 );
-        $t->addRow($_) for sort keys %{ $class->components };
-        $class->log->debug( "Loaded components:\n" . $t->draw )
-          if ( @{ $t->{tbl_rows} } );
-    }
-
-    # Add our self to components, since we are also a component
-    $class->components->{$class} = $class;
-
-    $class->setup_actions;
-
-    if ( $class->debug ) {
-        my $name = $class->config->{name} || 'Application';
-        $class->log->info("$name powered by Catalyst $Catalyst::VERSION");
-    }
-}
-
-=item $c->setup_components
-
-Setup components.
-
-=cut
-
-sub setup_components {
-    my $class = shift;
-
-    my $callback = sub {
-        my ( $component, $context ) = @_;
-
-        unless ( $component->isa('Catalyst::Base') ) {
-            return $component;
-        }
-
-        my $suffix = Catalyst::Utils::class2classsuffix($component);
-        my $config = $class->config->{$suffix} || {};
-
-        my $instance;
-
-        eval { $instance = $component->new( $context, $config ); };
-
-        if ( my $error = $@ ) {
-
-            chomp $error;
-
-            Catalyst::Exception->throw( 
-                message => qq/Couldn't instantiate component "$component", "$error"/
-            );
-        }
-
-        return $instance;
-    };
-
-    eval {
-        Module::Pluggable::Fast->import(
-            name   => '_components',
-            search => [
-                "$class\::Controller", "$class\::C",
-                "$class\::Model",      "$class\::M",
-                "$class\::View",       "$class\::V"
-            ],
-            callback => $callback
-        );
-    };
-
-    if ( my $error = $@ ) {
-
-        chomp $error;
-
-        Catalyst::Exception->throw( 
-            message => qq/Couldn't load components "$error"/ 
-        );
-    }
-
-    for my $component ( $class->_components($class) ) {
-        $class->components->{ ref $component || $component } = $component;
-    }
-}
-
-=item $c->setup_dispatcher
-
-=cut
-
-sub setup_dispatcher {
-    my ( $class, $dispatcher ) = @_;
-
-    if ( $dispatcher ) {
-        $dispatcher = 'Catalyst::Dispatcher::' . $dispatcher;
-    }
-
-    if ( $ENV{CATALYST_DISPATCHER} ) {
-        $dispatcher = 'Catalyst::Dispatcher::' . $ENV{CATALYST_DISPATCHER};
-    }
-
-    if ( $ENV{ uc($class) . '_DISPATCHER' } ) {
-        $dispatcher = 'Catalyst::Dispatcher::' . $ENV{ uc($class) . '_DISPATCHER' };
-    }
-
-    unless ( $dispatcher ) {
-        $dispatcher = 'Catalyst::Dispatcher';
-    }
-
-    $dispatcher->require;
-
-    if ( $@ ) {
-        Catalyst::Exception->throw(
-            message => qq/Couldn't load dispatcher "$dispatcher", "$@"/
-        );
-    }
-
-    {
-        no strict 'refs';
-        push @{"$class\::ISA"}, $dispatcher;
-    }
-
-    $class->dispatcher($dispatcher);
-}
-
-=item $c->setup_engine
-
-=cut
-
-sub setup_engine {
-    my ( $class, $engine ) = @_;
-
-    if ( $engine ) {
-        $engine = 'Catalyst::Engine::' . $engine;
-    }
-
-    if ( $ENV{CATALYST_ENGINE} ) {
-        $engine = 'Catalyst::Engine::' . $ENV{CATALYST_ENGINE};
-    }
-
-    if ( $ENV{ uc($class) . '_ENGINE' } ) {
-        $engine = 'Catalyst::Engine::' . $ENV{ uc($class) . '_ENGINE' };
-    }
-
-    if ( ! $engine && $ENV{MOD_PERL} ) {
-
-        my ( $software, $version ) = $ENV{MOD_PERL} =~ /^(\S+)\/(\d+(?:[\.\_]\d+)+)/;
-
-        $version =~ s/_//g;
-        $version =~ s/(\.[^.]+)\./$1/g;
-
-        if ( $software eq 'mod_perl') {
-
-            if ( $version >= 1.99922 ) {
-
-                $engine = 'Catalyst::Engine::Apache::MP20';
-
-                if ( Apache2::Request->require ) {
-                    $engine = 'Catalyst::Engine::Apache::MP20::Apreq';
-                }
-            }
-
-            elsif ( $version >= 1.9901 ) {
-
-                $engine = 'Catalyst::Engine::Apache::MP19';
-
-                if ( Apache::Request->require ) {
-                    $engine = 'Catalyst::Engine::Apache::MP19::Apreq';
-                }
-            }
-
-            elsif ( $version >= 1.24 ) {
-
-                $engine = 'Catalyst::Engine::Apache::MP13';
-
-                if ( Apache::Request->require ) {
-                    $engine = 'Catalyst::Engine::Apache::MP13::Apreq';
-                }
-            }
-
-            else {
-                Catalyst::Exception->throw(
-                    message => qq/Unsupported mod_perl version: $ENV{MOD_PERL}/
-                );
-            }
-        }
-
-        elsif ( $software eq 'Zeus-Perl' ) {
-            $engine = 'Catalyst::Engine::Zeus';
-        }
-
-        else {
-            Catalyst::Exception->throw(
-                message => qq/Unsupported mod_perl: $ENV{MOD_PERL}/
-            );
-        }
-    }
-
-    unless ( $engine ) {
-        $engine = 'Catalyst::Engine::CGI';
-    }
-
-    $engine->require;
-
-    if ( $@ ) {
-        Catalyst::Exception->throw(
-            message => qq/Couldn't load engine "$engine", "$@"/
-        );
-    }
-
-    {
-        no strict 'refs';
-        push @{"$class\::ISA"}, $engine;
-    }
-
-    $class->engine($engine);
-}
-
-=item $c->setup_home
-
-=cut
-
-sub setup_home {
-    my ( $class, $home ) = @_;
-
-    if ( $ENV{CATALYST_HOME} ) {
-        $home = $ENV{CATALYST_HOME};
-    }
-
-    if ( $ENV{ uc($class) . '_HOME' } ) {
-        $home = $ENV{ uc($class) . '_HOME' };
-    }
-
-    unless ( $home ) {
-        $home = Catalyst::Utils::home($class);
-    }
-
-    if ( $home ) {
-        $class->config->{home} ||= $home;
-        $class->config->{root} ||= dir($home)->subdir('root');
-    }
-}
-
-=item $c->setup_log
-
-=cut
-
-sub setup_log {
-    my ( $class, $debug ) = @_;
-
-    unless ( $class->log ) {
-        $class->log( Catalyst::Log->new );
-    }
-
-    if ( $ENV{CATALYST_DEBUG} || $ENV{ uc($class) . '_DEBUG' } || $debug ) {
-        no strict 'refs';
-        *{"$class\::debug"} = sub { 1 };
-        $class->log->debug('Debug messages enabled');
-    }
-}
-
-=item $c->setup_plugins
-
-=cut
-
-sub setup_plugins {
-    my ( $class, $plugins ) = @_;
-
-    for my $plugin ( @$plugins ) {
-
-        $plugin = "Catalyst::Plugin::$plugin";
-
-        $plugin->require;
-
-        if ( $@ ) {
-            Catalyst::Exception->throw(
-                message => qq/Couldn't load plugin "$plugin", "$@"/
-            );
-        }
-
-        {
-            no strict 'refs';
-            push @{"$class\::ISA"}, $plugin;
-        }
-    }
-}
-
-=back
-
-=head1 AUTHOR
-
-Sebastian Riedel, C<sri@cpan.org>
-Christian Hansen, C<ch@ngmedia.com>
-
-=head1 COPYRIGHT
-
-This program is free software, you can redistribute it and/or modify 
-it under the same terms as Perl itself.
-
-=cut
-
-1;
index 15e4a68..8a2a27b 100644 (file)
@@ -127,18 +127,17 @@ Returns a tempdir for class. If create is true it will try to create the path.
 sub class2tempdir {
     my $class  = shift || '';
     my $create = shift || 0;
-    my @parts  = split '::', lc $class;
+    my @parts = split '::', lc $class;
 
     my $tmpdir = dir( File::Spec->tmpdir, @parts )->cleanup;
 
-    if ( $create && ! -e $tmpdir ) {
+    if ( $create && !-e $tmpdir ) {
 
         eval { $tmpdir->mkpath };
 
-        if ( $@ ) {
+        if ($@) {
             Catalyst::Exception->throw(
-                message => qq/Couldn't create tmpdir '$tmpdir', "$@"/
-            );
+                message => qq/Couldn't create tmpdir '$tmpdir', "$@"/ );
         }
     }
 
@@ -167,6 +166,7 @@ sub home {
         {
             $home = $subdir;
         }
+
         # clean up relative path:
         # MyApp/script/.. -> MyApp
         my ($lastdir) = $home->dir_list( -1, 1 );
@@ -202,13 +202,12 @@ sub reflect_actions {
     my $class   = shift;
     my $actions = [];
     eval '$actions = $class->_action_cache';
-    
-    if ( $@ ) {
-        Catalyst::Exception->throw(
-            message => qq/Couldn't reflect actions of component "$class", "$@"/
-        );
+
+    if ($@) {
+        Catalyst::Exception->throw( message =>
+              qq/Couldn't reflect actions of component "$class", "$@"/ );
     }
-    
+
     return $actions;
 }
 
index 7514e11..14ae648 100755 (executable)
@@ -31,33 +31,125 @@ catalyst.pl [options] application-name
    -help        display this help and exits
    -nonew       don't create a .new file where a file to be created exists
 
- application-name has to be a valid Perl module name and can include ::
+ application-name must be a valid Perl module name and can include "::"
 
  Examples:
     catalyst.pl My::App
     catalyst.pl MyApp
 
- See also:
-    perldoc Catalyst::Manual
-    perldoc Catalyst::Manual::Intro
 
 =head1 DESCRIPTION
 
-Bootstrap a Catalyst application.
+The C<catalyst.pl> script bootstraps a Catalyst application, creating a
+directory structure populated with skeleton files.  
+
+The application name must be a valid Perl module name.  The name of the
+directory created is formed from the application name supplied, with double
+colons replaced with hyphens (so, for example, the directory for C<My::App> is
+C<My-App>).
+
+Using the example application name C<My::App>, the application directory will
+contain the following items:
+
+=over 4
+
+=item README
+
+a skeleton README file, which you are encouraged to expand on
+
+=item Build.PL
+
+a C<Module::Build> build script
+
+=item Changes
+
+a changes file with an initial entry for the creation of the application
+
+=item Makefile.PL
+
+an old-style MakeMaker script.  Catalyst uses the C<Module::Build> system so
+this script actually generates a Makeifle that invokes the Build script.
+
+=item lib
+
+contains the application module (C<My/App.pm>) and
+subdirectories for model, view, and controller components (C<My/App/M>,
+C<My/App/V>, and C<My/App/C>).  
+
+=item root
+
+root directory for your web document content.  This is left empty.
+
+=item script
+
+a directory containing helper scripts:
+
+=over 4
+
+=item C<my_app_create.pl>
+
+helper script to generate new component modules
+
+=item C<my_app_server.pl>
+
+runs the generated application within a Catalyst test server, which can be
+used for testing without resorting to a full-blown web server configuration.
+
+=item C<my_app_cgi.pl>
+
+runs the generated application as a CGI script
+
+=item C<my_app_fastcgi.pl>
+
+runs the generated application as a FastCGI script
+
+
+=item C<my_app_test.pl>
+
+runs an action of the generated application from the comand line.
+
+=back
+
+=item t
+
+test directory
+
+=back
+
+
+The application module generated by the C<catalyst.pl> script is functional,
+although it reacts to all requests by outputting the message:
+
+    Congratulations, My::App is on Catalyst!
+
+
+=head1 NOTE
+
+Neither C<catalyst.pl> nor the generated helper script will overwrite existing
+files.  In fact the scripts will generate new versions of any existing files,
+adding the extension C<.new> to the filename.  The C<.new> file is not created
+if would be identical to the existing file.  
+
+This means you can re-run the scripts for example to see if newer versions of
+Catalyst or its plugins generate different code, or to see how you may have
+changed the generated code (although you do of course have all your code in a
+version control system anyway, don't you ...).
+
+
 
 =head1 SEE ALSO
 
-L<Catalyst>, L<Catalyst::Manual>, L<Catalyst::Manual::Intro>,
-L<Catalyst::Test>, L<Catalyst::Request>, L<Catalyst::Response>,
-L<Catalyst::Engine>
+L<Catalyst::Manual>, L<Catalyst::Manual::Intro>
 
 =head1 AUTHOR
 
-Sebastian Riedel, C<sri@oook.de>
+Sebastian Riedel <sri@oook.de>,
+Andrew Ford <A.Ford@ford-mason.co.uk>
+
 
 =head1 COPYRIGHT
 
-Copyright 2004 Sebastian Riedel. All rights reserved.
+Copyright 2004-2005 Sebastian Riedel. All rights reserved.
 
 This library is free software. You can redistribute it and/or modify it under
 the same terms as perl itself.