This file documents the revision history for Perl extension Catalyst.
-5.24 2005-06-03 02:30:00
+5.24 2005-00-00 00:00:00
- Make module build cons README automatically.
- Prettify home path by resolving '..' (Andy Grundman)
- Improved helper templates a bit, new naming scheme for tests...
- Added support for case sensitivity, MyApp->config->{case_sensitive}
- Added $c->detach for non returning forwards
+ - Added unified error handling, Catalyst::Exception
5.23 2005-06-03 02:30:00
- added support for non Catalyst::Base components to live in namespace
lib/Catalyst/Engine/SpeedyCGI.pm
lib/Catalyst/Engine/SpeedyCGI/Base.pm
lib/Catalyst/Engine/Test.pm
+lib/Catalyst/Exception.pm
lib/Catalyst/Helper.pm
lib/Catalyst/Log.pm
lib/Catalyst/Manual.pod
use strict;
use base 'Catalyst::Base';
use UNIVERSAL::require;
+use Catalyst::Exception;
use Catalyst::Log;
use Catalyst::Utils;
use Text::ASCIITable;
}
else {
- die( qq/Unsupported mod_perl version: $ENV{MOD_PERL}/ );
+ Catalyst::Exception->throw(
+ message => qq/Unsupported mod_perl version: $ENV{MOD_PERL}/
+ );
}
}
}
else {
- die( qq/Unsupported mod_perl: $ENV{MOD_PERL}/ );
+ Catalyst::Exception->throw(
+ message => qq/Unsupported mod_perl: $ENV{MOD_PERL}/
+ );
}
}
$plugin->require;
- if ($@) { die qq/Couldn't load plugin "$plugin", "$@"/ }
+ if ( $@ ) {
+ Catalyst::Exception->throw(
+ message => qq/Couldn't load plugin "$plugin", "$@"/
+ );
+ }
else {
push @plugins, $plugin;
no strict 'refs';
$dispatcher = "Catalyst::Dispatcher::$appdis" if $appdis;
$dispatcher->require;
- die qq/Couldn't load dispatcher "$dispatcher", "$@"/ if $@;
+
+ if ( $@ ) {
+ Catalyst::Exception->throw(
+ message => qq/Couldn't load dispatcher "$dispatcher", "$@"/
+ );
+ }
+
{
no strict 'refs';
push @{"$caller\::ISA"}, $dispatcher;
$engine = "Catalyst::Engine::$appeng" if $appeng;
$engine->require;
- die qq/Couldn't load engine "$engine", "$@"/ if $@;
+
+ if ( $@ ) {
+ Catalyst::Exception->throw(
+ message => qq/Couldn't load engine "$engine", "$@"/
+ );
+ }
{
no strict 'refs';
sub plugin {
my ( $class, $name, $plugin, @args ) = @_;
$plugin->require;
- my $error = $UNIVERSAL::require::ERROR;
- die qq/Couldn't load instant plugin "$plugin", "$error"/ if $error;
+
+ if ( my $error = $UNIVERSAL::require::ERROR ) {
+ Catalyst::Exception->throw(
+ message => qq/Couldn't load instant plugin "$plugin", "$error"/
+ );
+ }
+
eval { $plugin->import };
$class->mk_classdata($name);
my $obj;
eval { $obj = $plugin->new(@args) };
- die qq/Couldn't instantiate instant plugin "$plugin", "$@"/ if $@;
+
+ if ( $@ ) {
+ Catalyst::Exception->throw(
+ message => qq/Couldn't instantiate instant plugin "$plugin", "$@"/
+ );
+ }
+
$class->$name($obj);
$class->log->debug(qq/Initialized instant plugin "$plugin" as "$name"/)
if $class->debug;
use strict;
use base qw/Class::Data::Inheritable Class::Accessor::Fast/;
+
+use Catalyst::Exception;
use NEXT;
__PACKAGE__->mk_classdata($_) for qw/_attr_cache _action_cache _config/;
=cut
sub process {
- die( ( ref $_[0] || $_[0] ) . " did not override Catalyst::Base::process" );
+
+ Catalyst::Exception->throw(
+ message => ( ref $_[0] || $_[0] ) . " did not override Catalyst::Base::process"
+ );
}
=item FETCH_CODE_ATTRIBUTES
use strict;
use base 'Class::Data::Inheritable';
+use Catalyst::Exception;
use Catalyst::Utils;
use Text::ASCIITable;
use Tree::Simple;
use HTTP::Headers;
use Time::HiRes qw/gettimeofday tv_interval/;
use Text::ASCIITable;
+use Catalyst::Exception;
use Catalyst::Request;
use Catalyst::Request::Upload;
use Catalyst::Response;
eval { $instance = $component->new( $context, $config ); };
if ( my $error = $@ ) {
+
chomp $error;
- die qq/Couldn't instantiate component "$component", "$error"/;
+
+ Catalyst::Exception->throw(
+ message => qq/Couldn't instantiate component "$component", "$error"/
+ );
}
return $instance;
};
if ( my $error = $@ ) {
+
chomp $error;
- die qq/Couldn't load components "$error"/;
+
+ Catalyst::Exception->throw(
+ message => qq/Couldn't load components "$error"/
+ );
}
for my $component ( $self->_components($self) ) {
use strict;
use base 'Catalyst::Engine::CGI::Base';
+use Catalyst::Exception;
use CGI;
our @compile = qw[
else {
my $class = ref($object);
- die( qq/Invalid argument $object/ );
+
+ Catalyst::Exception->throw(
+ message => qq/Unknown object '$object'/
+ );
}
}
use strict;
use base 'Catalyst::Engine';
+use Catalyst::Exception;
use Class::Struct ();
use HTTP::Headers::Util 'split_header_words';
use HTTP::Request;
if ( $parameters{filename} ) {
my $fh = File::Temp->new( UNLINK => 0 );
- $fh->write( $part->content ) or die $!;
- $fh->flush or die $!;
+
+ unless ( $fh->write( $part->content ) ) {
+ Catalyst::Exception->throw( message => $! );
+ }
+
+ unless ( $fh->flush ) {
+ Catalyst::Exception->throw( message => $! );
+ }
my $upload = Catalyst::Request::Upload->new(
filename => $parameters{filename},
type => $part->content_type
);
- $fh->close;
+ unless ( $fh->close ) {
+ Catalyst::Exception->throw( message => $! );
+ }
push( @uploads, $parameters{name}, $upload );
push( @params, $parameters{name}, $parameters{filename} );
use strict;
use base 'Catalyst::Engine::HTTP::Base';
+use Catalyst::Exception;
use IO::Select;
use IO::Socket;
);
unless ( defined $daemon ) {
- die(qq/Failed to create daemon. Reason: '$!'/);
+
+ Catalyst::Exception->throw(
+ message => qq/Failed to create daemon. Reason: '$!'/
+ );
}
my $base = URI->new( $daemon->url )->canonical;
--- /dev/null
+package Catalyst::Exception;
+
+BEGIN {
+ push( @ISA, $CATALYST_EXCEPTION_CLASS || 'Catalyst::Exception::Base' );
+}
+
+use strict;
+use vars qw[@ISA $CATALYST_EXCEPTION_CLASS];
+
+package Catalyst::Exception::Base;
+
+use strict;
+use Carp ();
+
+=head1 NAME
+
+Catalyst::Exception - Catalyst Exception Class
+
+=head1 SYNOPSIS
+
+ Catalyst::Exception->throw( qq/Fatal exception/ );
+
+See also L<Catalyst>.
+
+=head1 DESCRIPTION
+
+This is the Catalyst Exception class.
+
+=head1 METHODS
+
+=over 4
+
+=item throw($message)
+
+Throws a fatal exception.
+
+=cut
+
+sub throw {
+ my $class = shift;
+ my %params = @_ == 1 ? ( error => $_[0] ) : @_;
+
+ my $message = $params{message} || $params{error} || $! || '';
+
+ local $Carp::CarpLevel = 1;
+
+ Carp::croak($message);
+}
+
+=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;
use FindBin;
use Template;
use Catalyst;
+use Catalyst::Exception;
my %cache;
my @args = @_;
my $class = "Catalyst::Helper::$helper";
eval "require $class";
- die qq/Couldn't load helper "$class", "$@"/ if $@;
+
+ if ( $@ ) {
+ Catalyst::Exception->throw(
+ message => qq/Couldn't load helper "$class", "$@"/
+ );
+ }
+
if ( $class->can('mk_stuff') ) {
return 1 unless $class->mk_stuff( $self, @args );
}
$comp = 'Controller' if $type eq 'C';
my $class = "Catalyst::Helper::$comp\::$helper";
eval "require $class";
- die qq/Couldn't load helper "$class", "$@"/ if $@;
+
+ if ( $@ ) {
+ Catalyst::Exception->throw(
+ message => qq/Couldn't load helper "$class", "$@"/
+ );
+ }
+
if ( $class->can('mk_compclass') ) {
return 1 unless $class->mk_compclass( $self, @args );
}
print qq/created "$dir"\n/;
return 1;
}
- die qq/Couldn't create "$dir", "$!"/;
+
+ Catalyst::Exception->throw(
+ message => qq/Couldn't create "$dir", "$!"/
+ );
}
=head3 mk_file
print qq/created "$file"\n/;
return 1;
}
- die qq/Couldn't create "$file", "$!"/;
+
+ Catalyst::Exception->throw(
+ message => qq/Couldn't create "$file", "$!"/
+ );
}
=head3 next_test
$log->disable( 'warn', 'error' );
=item is_debug
+
=item is_error
+
=item is_fatal
+
=item is_info
+
=item is_warn
Is the log level active?
use strict;
use base 'Class::Accessor::Fast';
+use Catalyst::Exception;
use File::Copy ();
use IO::File ();
sub fh {
my $self = shift;
- my $fh = IO::File->new( $self->tempname, IO::File::O_RDONLY )
- or die( "Can't open ", $self->tempname, ": ", $! );
+ 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': '$!'/
+ );
+ }
return $fh;
}
use strict;
+use Catalyst::Exception;
use Catalyst::Utils;
use UNIVERSAL::require;
else {
$class->require;
- my $error = $UNIVERSAL::require::ERROR;
- die qq/Couldn't load "$class", "$error"/ if $@;
+
+ if ( $@ ) {
+
+ my $error = $UNIVERSAL::require::ERROR;
+
+ Catalyst::Exception->throw(
+ message => qq/Couldn't load "$class", "$error"/
+ );
+ }
$class->import;
use strict;
use attributes ();
+use Catalyst::Exception;
use HTTP::Request;
use Path::Class;
use URI;
my $class = shift;
my $actions = [];
eval '$actions = $class->_action_cache';
- die qq/Couldn't reflect actions of component "$class", "$@"/ if $@;
+
+ if ( $@ ) {
+ Catalyst::Exception->throw(
+ message => qq/Couldn't reflect actions of component "$class", "$@"/
+ );
+ }
+
return $actions;
}