From: djfiander Date: Sun, 16 Apr 2006 15:43:11 +0000 (+0000) Subject: Switch to AUTOLOAD-based field access X-Git-Url: https://old-git.evergreen-ils.org/?a=commitdiff_plain;h=2d0363a23fc0e8dd13df7260ee2505ef37845229;p=SIPServer.git Switch to AUTOLOAD-based field access --- diff --git a/ILS/Transaction.pm b/ILS/Transaction.pm index 5e0348b..b6d2ac1 100644 --- a/ILS/Transaction.pm +++ b/ILS/Transaction.pm @@ -4,97 +4,56 @@ package ILS::Transaction; -use Exporter; +use Carp; use strict; use warnings; -our @ISA = qw(Exporter); +my %fields = ( + ok => 0, + patron => undef, + item => undef, + desensitize => 0, + alert => '', + transation_id => undef, + sip_fee_type => '01', # Other/Unknown + fee_amount => undef, + sip_currency => 'CAD', + screen_msg => '', + print_line => '', + ); + +our $AUTOLOAD; sub new { - my ($class, $obj) = @_; - my $type = ref($class) || $class; + my $class = shift; + my $self = { + _permitted => \%fields, + %fields, + }; - return bless {}, $type; + return bless $self, $class; } -sub ok { - my $self = shift; - - return $self->{ok} ? 1 : 0; # normalize, just because -} - -sub alert { - my $self = shift; - - return $self->{alert} || 0; -} - -sub screen_msg { - my $self = shift; - - return ($self->{screen_msg} || ""); -} - -sub print_line { - my $self = shift; - - return ($self->{print_line} || ""); -} - -sub patron { - my $self = shift; - - return $self->{patron}; -} - -sub item { - my $self = shift; - - return $self->{item}; +sub DESTROY { + # be cool } -sub permanent_location { +sub AUTOLOAD { my $self = shift; + my $class = ref($self) or croak "$self is not an object"; + my $name = $AUTOLOAD; - return $self->item->permanent_location || ''; -} - -sub sort_bin { - my $self = shift; - - return $self->{sort_bin} || ''; -} - -sub fee_amount { - return 0; -} - -sub transaction_id { - my $self = shift; - - return $self->{transaction_id}; -} + $name =~ s/.*://; -sub sip_currency { - return 'CAD'; # ;-) -} - -sub sip_fee_type { - my $self = shift; - - return $self->{sip_fee_type} || '01'; # "Other/Unknown" -} - -sub available { - my $self = shift; - - return $self->{available} || 'N'; # Assume that it's not available -} - -sub desensitize { - my $self = shift; + unless (exists $self->{_permitted}->{$name}) { + croak "Can't access '$name' field of class '$class'"; + } - return $self->{desensitize}; + if (@_) { + return $self->{$name} = shift; + } else { + return $self->{$name}; + } } 1; diff --git a/ILS/Transaction/Checkin.pm b/ILS/Transaction/Checkin.pm index cf43a89..3f231d8 100644 --- a/ILS/Transaction/Checkin.pm +++ b/ILS/Transaction/Checkin.pm @@ -4,7 +4,6 @@ package ILS::Transaction::Checkin; -use Exporter; use warnings; use strict; @@ -13,16 +12,25 @@ use POSIX qw(strftime); use ILS; use ILS::Transaction; -our @ISA = qw(Exporter ILS::Transaction); +our @ISA = qw(ILS::Transaction); + +my %fields = ( + magnetic => 0, + sort_bin => undef, + ); sub new { - my ($class, $obj) = @_; - my $type = ref($class) || $class; - my ($item, $patron); + my $class = shift;; + my $self = $class->SUPER::new(); + my $element; + + foreach $element (keys %fields) { + $self->{_permitted}->{$element} = $fields{$element}; + } - $obj = {}; + @{$self}{keys %fields} = values %fields; - return bless $obj, $type; + return bless $self, $class; } sub resensitize { @@ -31,10 +39,4 @@ sub resensitize { return !$self->{item}->magnetic; } -sub magnetic_media { - my $self = shift; - - return $self->{item}->magnetic; -} - 1; diff --git a/ILS/Transaction/Checkout.pm b/ILS/Transaction/Checkout.pm index 58c1a74..d46aa30 100644 --- a/ILS/Transaction/Checkout.pm +++ b/ILS/Transaction/Checkout.pm @@ -4,7 +4,6 @@ package ILS::Transaction::Checkout; -use Exporter; use warnings; use strict; @@ -13,28 +12,27 @@ use POSIX qw(strftime); use ILS; use ILS::Transaction; -our @ISA = qw(Exporter ILS::Transaction); +our @ISA = qw(ILS::Transaction); # Most fields are handled by the Transaction superclass +my %fields = ( + security_inhibit => 0, + due => undef, + ); sub new { - my ($class, $obj) = @_; - my $type = ref($class) || $class; - - $obj = {}; - - $obj->{'due'} = time() + (60*60*24*14); # two weeks hence - - return bless $obj, $type; -} - -sub security_inhibit { - return 0; -} - -sub due_date { - my $self = shift; - return(strftime("%F %H:%M:%S", localtime($self->{due}))); + my $class = shift;; + my $self = $class->SUPER::new(); + my $element; + + foreach $element (keys %fields) { + $self->{_permitted}->{$element} = $fields{$element}; + } + + @{$self}{keys %fields} = values %fields; + $self->{'due'} = time() + (60*60*24*14); # two weeks hence + + return bless $self, $class; } sub renew_ok { @@ -44,4 +42,5 @@ sub renew_ok { return ($item->{patron} eq $patron->{id}); } + 1; diff --git a/ILS/Transaction/Hold.pm b/ILS/Transaction/Hold.pm index 2f8291c..14b3a9d 100644 --- a/ILS/Transaction/Hold.pm +++ b/ILS/Transaction/Hold.pm @@ -11,12 +11,23 @@ use ILS::Transaction; our @ISA = qw(ILS::Transaction); -# Most fields are handled by the Transaction superclass +my %fields = ( + expiration_date => 0, + pickup_location => undef, + ); -sub expiration_date { - my $self = shift; +sub new { + my $class = shift;; + my $self = $class->SUPER::new(); + my $element; + + foreach $element (keys %fields) { + $self->{_permitted}->{$element} = $fields{$element}; + } + + @{$self}{keys %fields} = values %fields; - return $self->{expiration_date} || 0; + return bless $self, $class; } sub queue_position { @@ -25,9 +36,4 @@ sub queue_position { return $self->item->hold_queue_position($self->patron->id); } -sub pickup_location { - my $self = shift; - - return $self->{pickup_location}; -} 1; diff --git a/ILS/Transaction/Renew.pm b/ILS/Transaction/Renew.pm index 30ff219..40c9ae4 100644 --- a/ILS/Transaction/Renew.pm +++ b/ILS/Transaction/Renew.pm @@ -12,12 +12,22 @@ use ILS::Transaction; our @ISA = qw(ILS::Transaction); -# most fields are handled by the Transaction superclass +my %fields = ( + renewal_ok => 0, + ); -sub renewal_ok { - my $self = shift; +sub new { + my $class = shift;; + my $self = $class->SUPER::new(); + my $element; - return $self->{renewal_ok} || 0; + foreach $element (keys %fields) { + $self->{_permitted}->{$element} = $fields{$element}; + } + + @{$self}{keys %fields} = values %fields; + + return bless $self, $class; } 1; diff --git a/ILS/Transaction/RenewAll.pm b/ILS/Transaction/RenewAll.pm new file mode 100644 index 0000000..6f3b90d --- /dev/null +++ b/ILS/Transaction/RenewAll.pm @@ -0,0 +1,29 @@ +# +# RenewAll: class to manage status of "Renew All" transaction + +package ILS::Transaction::RenewAll; + +use strict; +use warnings; + +our @ISA = qw(ILS::Transaction); + +my %fields = ( + renewed => [], + unrenewed => [], + ); +sub new { + my $class = shift;; + my $self = $class->SUPER::new(); + my $element; + + foreach $element (keys %fields) { + $self->{_permitted}->{$element} = $fields{$element}; + } + + @{$self}{keys %fields} = values %fields; + + return bless $self, $class; +} + +1;