From 920b36d728b041491d84ba6a2670cc924fc651b9 Mon Sep 17 00:00:00 2001 From: Colin Kuskie Date: Mon, 25 Feb 2008 21:11:44 +0000 Subject: [PATCH] force the overriding of the calculate class --- lib/WebGUI/Shop/ShipDriver.pm | 13 +++++++++++++ t/Shop/ShipDriver.t | 17 ++++++++++------- 2 files changed, 23 insertions(+), 7 deletions(-) diff --git a/lib/WebGUI/Shop/ShipDriver.pm b/lib/WebGUI/Shop/ShipDriver.pm index f0fd09518..1b4cadc58 100644 --- a/lib/WebGUI/Shop/ShipDriver.pm +++ b/lib/WebGUI/Shop/ShipDriver.pm @@ -60,6 +60,19 @@ sub _buildObj { } +#------------------------------------------------------------------- + +=head2 calculate ( ) + +This method calculates how much it costs to ship the contents of a cart. This method +MUST be overridden in all child classes. + +=cut + +sub calculate { + croak "You must override the calculate method"; +} + #------------------------------------------------------------------- =head2 className ( ) diff --git a/t/Shop/ShipDriver.t b/t/Shop/ShipDriver.t index a7a0db5db..8cc66638c 100644 --- a/t/Shop/ShipDriver.t +++ b/t/Shop/ShipDriver.t @@ -31,7 +31,7 @@ my $session = WebGUI::Test->session; #---------------------------------------------------------------------------- # Tests -my $tests = 28; +my $tests = 29; plan tests => 1 + $tests; #---------------------------------------------------------------------------- @@ -238,6 +238,15 @@ is($driver->getId, $driverCopy->getId, 'same id'); is($driver->className, $driverCopy->className, 'same className'); cmp_deeply($driver->options, $driverCopy->options, 'same options'); +####################################################################### +# +# calculate +# +####################################################################### + +eval { $driver->calculate; }; +like ($@, qr/^You must override the calculate method/, 'calculate throws an exception to force overriding it in the child classes'); + ####################################################################### # # delete @@ -251,12 +260,6 @@ is($count, 0, 'delete deleted the object'); undef $driver; -####################################################################### -# -# calculate -# -####################################################################### - } #----------------------------------------------------------------------------