Bugzilla – Attachment 72013 Details for
Bug 19966
Add ability to pass objects directly to slips and notices
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Help
|
New Account
|
Log In
[x]
|
Forgot Password
Login:
[x]
[patch]
[FOR DISCUSSION] Bug 19966: Add Koha::Object->read_only
Bug-19966-Add-KohaObject-readonly.patch (text/plain), 2.10 KB, created by
Jonathan Druart
on 2018-02-20 20:20:12 UTC
(
hide
)
Description:
[FOR DISCUSSION] Bug 19966: Add Koha::Object->read_only
Filename:
MIME Type:
Creator:
Jonathan Druart
Created:
2018-02-20 20:20:12 UTC
Size:
2.10 KB
patch
obsolete
>From 53201e1b68e6227130ba20bc6f5ad695c95b75c7 Mon Sep 17 00:00:00 2001 >From: Jonathan Druart <jonathan.druart@bugs.koha-community.org> >Date: Tue, 20 Feb 2018 17:17:50 -0300 >Subject: [PATCH] Bug 19966: Add Koha::Object->read_only > >If ->read_only is called, only accessor methods will be allowed on this >object. > >use Koha::Patrons; >my $p = Koha::Patrons->find(1); >say $p->borrowernumber; >$p->surname('another surname')->store; >say $p->surname; >=> Will work > >$p = Koha::Patrons->find(1); >$p->read_only; >$p->surname('another surname again')->store; >=> Will explode > >Problem: >use Koha::Patrons; >my $p = Koha::Patrons->find(1); >say $p->borrowernumber; >$p->read_only; >$p->{_read_only} = 0; >$p->surname('another surname again')->store; >=> Will not explode >--- > Koha/Object.pm | 19 +++++++++++++++++++ > 1 file changed, 19 insertions(+) > >diff --git a/Koha/Object.pm b/Koha/Object.pm >index d53654b15c..226bebe277 100644 >--- a/Koha/Object.pm >+++ b/Koha/Object.pm >@@ -222,6 +222,20 @@ sub unblessed { > return { $self->_result->get_columns }; > } > >+=head3 $object->read_only(); >+ >+Set the object as read_only, only getter methods will be allowed >+ >+=cut >+ >+sub read_only { >+ my ($self) = @_; >+ >+ $self->{_read_only} = 1; >+ >+ return $self; >+} >+ > =head3 $object->TO_JSON > > Returns an unblessed representation of the object, suitable for JSON output. >@@ -344,6 +358,8 @@ sub AUTOLOAD { > # Using direct setter/getter like $item->barcode() or $item->barcode($barcode); > if ( grep {/^$method$/} @columns ) { > if ( @_ ) { >+ die "Setter method $method called on read-only object" >+ if $self->{_read_only}; > $self->_result()->set_column( $method, @_ ); > return $self; > } else { >@@ -352,6 +368,9 @@ sub AUTOLOAD { > } > } > >+ die "Cannot call method $method on a read-only object" >+ if $self->{_read_only}; >+ > my @known_methods = qw( is_changed id in_storage get_column discard_changes update ); > Koha::Exceptions::Object::MethodNotCoveredByTests->throw( "The method $method is not covered by tests!" ) unless grep {/^$method$/} @known_methods; > >-- >2.11.0
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
|
Splinter Review
Attachments on
bug 19966
:
70470
|
71998
|
72013
|
123106
|
128546