Lines 900-915
The autoload method is used only to get and set values for an objects properties
Link Here
|
900 |
=cut |
900 |
=cut |
901 |
|
901 |
|
902 |
sub AUTOLOAD { |
902 |
sub AUTOLOAD { |
903 |
my ($self) = @_; |
903 |
my $self = shift; |
904 |
|
904 |
|
905 |
my $method = our $AUTOLOAD; |
905 |
my $method = our $AUTOLOAD; |
906 |
$method =~ s/.*://; |
906 |
$method =~ s/.*://; |
907 |
|
907 |
|
908 |
my @columns = @{$self->_columns()}; |
908 |
my @columns = @{$self->_columns()}; |
909 |
# Using direct setter/getter like $item->barcode() or $item->barcode($barcode); |
|
|
910 |
if ( grep { $_ eq $method } @columns ) { |
909 |
if ( grep { $_ eq $method } @columns ) { |
911 |
no strict 'refs'; |
910 |
# Lazy definition of get/set accessors like $item->barcode; note that it contains $method |
912 |
*{$AUTOLOAD} = sub { |
911 |
my $accessor = sub { |
913 |
my $self = shift; |
912 |
my $self = shift; |
914 |
if ( @_ ) { |
913 |
if ( @_ ) { |
915 |
$self->_result()->set_column( $method, @_); |
914 |
$self->_result()->set_column( $method, @_); |
Lines 918-924
sub AUTOLOAD {
Link Here
|
918 |
return $self->_result()->get_column( $method ); |
917 |
return $self->_result()->get_column( $method ); |
919 |
} |
918 |
} |
920 |
}; |
919 |
}; |
921 |
goto &{$AUTOLOAD}; |
920 |
no strict 'refs'; |
|
|
921 |
*{$AUTOLOAD} = $accessor; |
922 |
return $accessor->($self, @_); |
922 |
} |
923 |
} |
923 |
|
924 |
|
924 |
my @known_methods = qw( is_changed id in_storage get_column discard_changes make_column_dirty ); |
925 |
my @known_methods = qw( is_changed id in_storage get_column discard_changes make_column_dirty ); |
Lines 928-935
sub AUTOLOAD {
Link Here
|
928 |
show_trace => 1 |
929 |
show_trace => 1 |
929 |
) unless grep { $_ eq $method } @known_methods; |
930 |
) unless grep { $_ eq $method } @known_methods; |
930 |
|
931 |
|
931 |
# Remove $self so that @_ now contain arguments only |
|
|
932 |
shift; |
933 |
my $r = eval { $self->_result->$method(@_) }; |
932 |
my $r = eval { $self->_result->$method(@_) }; |
934 |
if ( $@ ) { |
933 |
if ( $@ ) { |
935 |
Koha::Exceptions::Object->throw( ref($self) . "::$method generated this error: " . $@ ); |
934 |
Koha::Exceptions::Object->throw( ref($self) . "::$method generated this error: " . $@ ); |
936 |
- |
|
|