[Koha-bugs] [Bug 14539] Introduction to castToObject(), aka. make a Koha:: Object from various input types

bugzilla-daemon at bugs.koha-community.org bugzilla-daemon at bugs.koha-community.org
Mon May 8 16:30:20 CEST 2017


https://bugs.koha-community.org/bugzilla3/show_bug.cgi?id=14539

Lari Taskula <lari.taskula at jns.fi> changed:

           What    |Removed                     |Added
----------------------------------------------------------------------------
  Attachment #63237|0                           |1
        is obsolete|                            |

--- Comment #13 from Lari Taskula <lari.taskula at jns.fi> ---
Created attachment 63243
  -->
https://bugs.koha-community.org/bugzilla3/attachment.cgi?id=63243&action=edit
Bug 14539 - Koha::Objects->cast(). Introduction to cast() (ToObject), aka. make
a Koha::Object from various input types and validate.

Finds a Patron-object (or any other type) from various different types of
inputs.
Also doubles as a validator function, dying if input is improper.

USAGE:
    my $member = C4::Members::GetMember(borrowernumber => $borrowernumber);
    my $borrower = Koha::Patrons->cast($member);

Currently Koha is like an archeological dig site, we have different layers of
dealing with various business objects.

We started with DBI and numerous ways of passing an HASH around. There is no
telling if it will be a List of column => values, or a reference to HASH, or a
HASH or just any of the business object's (eg. Patron's) unique identifiers
(userid, cardnumber, borrowernumber).

Then DBIx came to the rescue and now we are need to learn DBI and DBIx and SQL
to do DB operatons in Koha. Migration to DBIx is on the way.

Finally we have Koha::Object and subclasses, which include and use the DBIx,
but those are not directly compatible, since Koha::Object is not a subclass of
DBIx::Class making life occasionally miserable.
Now we need to know 3 methods of DB accession.

I am really frustrated with all of those different layers of history, and
making things work nicely across all different programming patterns, I have
had great success in using a casting system, where we take any value and try
to make a Koha::Object-subclass out of it.

So we try to cast a Scalar or a reference of Koha::Object-implementation or
DBIx::ResultSet or HASH, to the desired Koha::Object-implementation.
This is a nice validation/entry function in any subroutine dealing with
business objects, making sure that we always have the "correct" implementation
of the same business object.

Unit tests included demonstrating the feature and possible pitfalls.

-- 
You are receiving this mail because:
You are watching all bug changes.


More information about the Koha-bugs mailing list