Skip to content
Permalink
Browse files

Convert Shop::Credit to Moose

  • Loading branch information...
perlDreamer committed Jul 9, 2010
1 parent 09767a4 commit 49182aebec1e245d384b57984dee7a345614bf42
Showing with 21 additions and 18 deletions.
  1. +21 −18 lib/WebGUI/Shop/Credit.pm
@@ -1,7 +1,15 @@
package WebGUI::Shop::Credit;

use strict;
use Class::InsideOut qw{ :std };
use Moose;
use Scalar::Util qw/blessed/;

has [ qw/session userId/ ] => (
is => 'ro',
required => 1,
);


use WebGUI::Shop::Admin;
use WebGUI::Exception::Shop;
use WebGUI::International;
@@ -28,8 +36,18 @@ These subroutines are available from this package:
=cut

readonly session => my %session;
readonly userId => my %userId;
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, userId => $_[1], );
}
return $className->$orig(@_);
};


#-------------------------------------------------------------------

@@ -137,21 +155,6 @@ A unique id for a user that you want to adjust the credit of. Defaults to the cu
=cut

sub new {
my ($class, $session, $userId) = @_;
unless (defined $session && $session->isa("WebGUI::Session")) {
WebGUI::Error::InvalidObject->throw(expected=>"WebGUI::Session", got=>(ref $session), error=>"Need a session.");
}
unless (defined $userId) {
$userId = $session->user->userId;
}
my $self = register $class;
my $id = id $self;
$session{ $id } = $session;
$userId{ $id } = $userId;
return $self;
}

#-------------------------------------------------------------------

=head2 session ()

0 comments on commit 49182ae

Please sign in to comment.
You can’t perform that action at this time.