From ea500fd1b20ffc32b7a09d1d305449b31e6c30d1 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Thu, 28 Feb 2008 17:00:34 +0000 Subject: [PATCH] Conver the FlatRate shipping driver to use exceptions. --- lib/WebGUI/Shop/ShipDriver/FlatRate.pm | 4 ++-- t/Shop/ShipDriver/FlatRate.t | 14 ++++++++++++-- 2 files changed, 14 insertions(+), 4 deletions(-) diff --git a/lib/WebGUI/Shop/ShipDriver/FlatRate.pm b/lib/WebGUI/Shop/ShipDriver/FlatRate.pm index 69c915149..3d7dd0213 100644 --- a/lib/WebGUI/Shop/ShipDriver/FlatRate.pm +++ b/lib/WebGUI/Shop/ShipDriver/FlatRate.pm @@ -2,7 +2,7 @@ package WebGUI::Shop::ShipDriver::FlatRate; use strict; use base qw/WebGUI::Shop::ShipDriver/; -use Carp qw/croak/; +use WebGUI::Exception; =head1 NAME @@ -58,7 +58,7 @@ the user. sub definition { my $class = shift; my $session = shift; - croak "Definition requires a session object" + WebGUI::Error::InvalidParam->throw(error => q{Must provide a session variable}) unless ref $session eq 'WebGUI::Session'; my $definition = shift || []; my $i18n = WebGUI::International->new($session, 'ShipDriver_FlatRate'); diff --git a/t/Shop/ShipDriver/FlatRate.t b/t/Shop/ShipDriver/FlatRate.t index b9878b05b..e67a5e191 100644 --- a/t/Shop/ShipDriver/FlatRate.t +++ b/t/Shop/ShipDriver/FlatRate.t @@ -31,7 +31,7 @@ my $session = WebGUI::Test->session; #---------------------------------------------------------------------------- # Tests -my $tests = 11; +my $tests = 12; plan tests => 1 + $tests; #---------------------------------------------------------------------------- @@ -52,9 +52,19 @@ skip 'Unable to load module WebGUI::Shop::ShipDriver::FlatRate', $tests unless $ ####################################################################### my $definition; +my $e; ##Exception variable, used throughout the file eval { $definition = WebGUI::Shop::ShipDriver::FlatRate->definition(); }; -like ($@, qr/^Definition requires a session object/, 'definition croaks without a session object'); +$e = Exception::Class->caught(); +isa_ok($e, 'WebGUI::Error::InvalidParam', 'definition takes an exception to not giving it a session variable'); +cmp_deeply( + $e, + methods( + error => 'Must provide a session variable', + ), + 'definition: requires a session variable', +); + $definition = WebGUI::Shop::ShipDriver::FlatRate->definition($session);