Start switching code to use Exception::Class

Use Exception::CLass is as easier to get data back up the calling tree than just using die();
This commit is contained in:
Duncan Ferguson 2011-07-01 14:46:01 +01:00
parent f1e6348160
commit efe6cf2e9c
4 changed files with 20 additions and 6 deletions

View file

@ -23,6 +23,7 @@ my $build = Module::Build->new(
'Tk' => '800.022',
'X11::Protocol' => '0.56',
'Locale::Maketext' => 0,
'Exception::Class' => '1.31',
},
build_requires => {
'Test::Pod::Coverage' => 0,

View file

@ -1,3 +1,6 @@
????-??-?? Duncan Ferguson <duncan_ferguson@user.sf.net> - v4.01_00
* Start switching code to use Exception::Class
2011-06-30 Duncan Ferguson <duncan_ferguson@user.sf.net> - v4.00_09
* Cater for missing 'pod2text' command (Thanks to Sami Kerola)
* Fix 'uninitialised variable' error

View file

@ -5,6 +5,10 @@ use strict;
use Carp;
use App::ClusterSSH::L10N;
use Exception::Class (
'App::ClusterSSH::Exception',
);
# Dont use SVN revision as it can cause problems
use version;
our $VERSION = version->new('0.02');
@ -81,7 +85,7 @@ sub set_lang {
sub set_debug_level {
my ( $self, $level ) = @_;
if ( !defined $level ) {
croak( _translate('Debug level not provided') );
croak( App::ClusterSSH::Exception->throw( error => _translate('Debug level not provided') ) );
}
if ( $level > 9 ) {
$level = 9;
@ -113,7 +117,7 @@ sub config {
my ($self) = @_;
if ( !$app_configuration ) {
croak( _translate('config has not yet been set') );
croak( App::ClusterSSH::Exception->throw( _translate('config has not yet been set') ) );
}
return $app_configuration;
@ -123,11 +127,11 @@ sub set_config {
my ( $self, $config ) = @_;
if ($app_configuration) {
croak( _translate('config has already been set') );
croak( App::ClusterSSH::Exception->throw( _translate('config has already been set') ) );
}
if(!$config) {
croak( _translate('passed config is empty'));
croak( App::ClusterSSH::Exception->throw( _translate('passed config is empty')) );
}
$self->debug( 3, _translate('Setting app configuration') );

View file

@ -49,13 +49,15 @@ for my $level ( 0 .. 9 ) {
'checking for expected debug output' );
}
my $level;
trap {
$base->set_debug_level();
$level = $base->set_debug_level();
};
isa_ok($trap->die, 'App::ClusterSSH::Exception', 'Caught exception object OK');
is( $trap->leaveby, 'die', 'returned ok' );
is( $trap->stderr, '', 'Expecting no STDERR' );
is( $trap->stdout, '', 'Expecting no STDOUT' );
like( $trap->die, qr/^Debug level not provided at/,
like( $trap->die, qr/^Debug level not provided/,
'Got correct croak text' );
$base->set_debug_level(10);
@ -137,6 +139,7 @@ is( $trap->stdout, '', 'Expecting no STDOUT' );
trap {
$get_config = $base->config();
};
isa_ok($trap->die, 'App::ClusterSSH::Exception', 'Caught exception object OK');
is( $trap->leaveby, 'die', 'died ok' );
like( $trap->die, qr/^config has not yet been set/,
'Got correct croak text' );
@ -147,6 +150,7 @@ is( $get_config, undef, 'config left empty' );
trap {
$object = $base->set_config();
};
isa_ok($trap->die, 'App::ClusterSSH::Exception', 'Caught exception object OK');
is( $trap->leaveby, 'die', 'died ok' );
like( $trap->die, qr/^passed config is empty/, 'Got correct croak text' );
is( $trap->stderr, '', 'Expecting no STDERR' );
@ -178,6 +182,7 @@ trap {
$object = $base->set_config('set to another scalar');
};
is( $trap->leaveby, 'die', 'died ok' );
isa_ok($trap->die, 'App::ClusterSSH::Exception', 'Caught exception object OK');
like(
$trap->die,
qr/^config\shas\salready\sbeen\sset/,
@ -190,6 +195,7 @@ trap {
$object = $base->set_config();
};
is( $trap->leaveby, 'die', 'died ok' );
isa_ok($trap->die, 'App::ClusterSSH::Exception', 'Caught exception object OK');
like(
$trap->die,
qr/^config\shas\salready\sbeen\sset/,