Update Tax.pm for Moose.
This commit is contained in:
parent
9d4d303bc3
commit
a7cc3696c6
2 changed files with 26 additions and 32 deletions
|
|
@ -16,7 +16,7 @@ package WebGUI::Shop::Tax;
|
||||||
|
|
||||||
use strict;
|
use strict;
|
||||||
|
|
||||||
use Class::InsideOut qw{ :std };
|
use Moose;
|
||||||
use WebGUI::Exception::Shop;
|
use WebGUI::Exception::Shop;
|
||||||
use WebGUI::Shop::Admin;
|
use WebGUI::Shop::Admin;
|
||||||
use WebGUI::Pluggable;
|
use WebGUI::Pluggable;
|
||||||
|
|
@ -44,7 +44,23 @@ These subroutines are available from this package:
|
||||||
|
|
||||||
=cut
|
=cut
|
||||||
|
|
||||||
readonly session => my %session;
|
has session => (
|
||||||
|
is => 'ro',
|
||||||
|
required => 1,
|
||||||
|
);
|
||||||
|
|
||||||
|
around BUILDARGS => sub {
|
||||||
|
my $orig = shift;
|
||||||
|
my $className = shift;
|
||||||
|
|
||||||
|
##Original arguments start here.
|
||||||
|
my $protoSession = $_[0];
|
||||||
|
if (blessed $protoSession && $protoSession->isa('WebGUI::Session')) {
|
||||||
|
return $className->$orig(session => $protoSession);
|
||||||
|
}
|
||||||
|
return $className->$orig(@_);
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
##-------------------------------------------------------------------
|
##-------------------------------------------------------------------
|
||||||
#sub appendSkuForm {
|
#sub appendSkuForm {
|
||||||
|
|
@ -127,8 +143,11 @@ A WebGUI::Session object. Required in class context, optional in instance contex
|
||||||
|
|
||||||
sub getDriver {
|
sub getDriver {
|
||||||
my $self = shift;
|
my $self = shift;
|
||||||
my $session = shift || $self->session;
|
my $session = shift;
|
||||||
|
if (!$session && blessed $self) {
|
||||||
|
$session = $self->session;
|
||||||
|
}
|
||||||
|
|
||||||
WebGUI::Error::InvalidObject->throw( expected => "WebGUI::Session", got => (ref $session), error => "Need a session." )
|
WebGUI::Error::InvalidObject->throw( expected => "WebGUI::Session", got => (ref $session), error => "Need a session." )
|
||||||
unless $session && $session->isa( 'WebGUI::Session' );
|
unless $session && $session->isa( 'WebGUI::Session' );
|
||||||
|
|
||||||
|
|
@ -144,28 +163,6 @@ sub getDriver {
|
||||||
return $driver;
|
return $driver;
|
||||||
}
|
}
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
|
||||||
|
|
||||||
=head2 new ( $session )
|
|
||||||
|
|
||||||
Constructor for the WebGUI::Shop::Tax. Returns a WebGUI::Shop::Tax object.
|
|
||||||
|
|
||||||
=cut
|
|
||||||
|
|
||||||
sub new {
|
|
||||||
my $class = shift;
|
|
||||||
my $session = shift;
|
|
||||||
|
|
||||||
WebGUI::Error::InvalidObject->throw( expected => "WebGUI::Session", got => (ref $session), error => "Need a session." )
|
|
||||||
unless $session && $session->isa( 'WebGUI::Session' );
|
|
||||||
|
|
||||||
my $self = {};
|
|
||||||
bless $self, $class;
|
|
||||||
register $self;
|
|
||||||
$session{ id $self } = $session;
|
|
||||||
return $self;
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
|
|
||||||
#-------------------------------------------------------------------
|
#-------------------------------------------------------------------
|
||||||
|
|
|
||||||
|
|
@ -17,6 +17,7 @@ use FindBin;
|
||||||
use strict;
|
use strict;
|
||||||
use lib "$FindBin::Bin/../lib";
|
use lib "$FindBin::Bin/../lib";
|
||||||
use Test::More;
|
use Test::More;
|
||||||
|
use Test::Exception;
|
||||||
use WebGUI::Test; # Must use this before any other WebGUI modules
|
use WebGUI::Test; # Must use this before any other WebGUI modules
|
||||||
use WebGUI::Session;
|
use WebGUI::Session;
|
||||||
|
|
||||||
|
|
@ -28,7 +29,7 @@ my $session = WebGUI::Test->session;
|
||||||
#----------------------------------------------------------------------------
|
#----------------------------------------------------------------------------
|
||||||
# Tests
|
# Tests
|
||||||
|
|
||||||
my $tests = 10;
|
my $tests = 9;
|
||||||
plan tests => $tests + 1; # Add initial use_ok test
|
plan tests => $tests + 1; # Add initial use_ok test
|
||||||
|
|
||||||
|
|
||||||
|
|
@ -45,11 +46,7 @@ SKIP: {
|
||||||
#
|
#
|
||||||
#######################################################################
|
#######################################################################
|
||||||
|
|
||||||
eval { my $tax = WebGUI::Shop::Tax->new( ) };
|
dies_ok { my $tax = WebGUI::Shop::Tax->new( ) } 'new: throws error when no session object is passed';
|
||||||
|
|
||||||
my $e = Exception::Class->caught();
|
|
||||||
isa_ok( $e, 'WebGUI::Error::InvalidParam', 'new: throws error when no session object is passed' );
|
|
||||||
is( $e->error, 'Need a session.', 'add: correct message for ommitted session object' );
|
|
||||||
|
|
||||||
my $tax = WebGUI::Shop::Tax->new( $session );
|
my $tax = WebGUI::Shop::Tax->new( $session );
|
||||||
|
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue