[Koha-patches] [PATCH] get_infos_of deprecated

Joe Atzberger joe.atzberger at liblime.com
Wed Jul 8 15:18:33 CEST 2009


---
 C4/Koha.pm |   26 ++++++++++++--------------
 1 files changed, 12 insertions(+), 14 deletions(-)

diff --git a/C4/Koha.pm b/C4/Koha.pm
index 05e3074..f31f583 100644
--- a/C4/Koha.pm
+++ b/C4/Koha.pm
@@ -792,7 +792,7 @@ sub getFacets {
     return $facets;
 }
 
-=head2 get_infos_of
+=head2 get_infos_of (deprecated)
 
 Return a href where a key is associated to a href. You give a query,
 the name of the key among the fields returned by the query. If you
@@ -816,27 +816,25 @@ SELECT itemnumber,
   my $barcode_of_item = get_infos_of($query, 'itemnumber', 'barcode');
   print $barcode_of_item->{$itemnumber};
 
+FIXME: This function should be replaced with more intelligent use of the built-in
+functionality of DBI.  You can already specify query, bind and slice in one line.
+The performance and featureset is better without this function.  See perldoc DBI.
+
+Is the hash value a scalar or another hashref?  Returning variably formatted data
+based on the defined status of the optional 3rd argument is not a great API.  There
+is no check to guarantee $value_name isn't "", or that it is a valid column in the
+query results.
+
 =cut
 
 sub get_infos_of {
     my ( $query, $key_name, $value_name, $bind_params ) = @_;
-
-    my $dbh = C4::Context->dbh;
-
-    my $sth = $dbh->prepare($query);
+    my $sth = C4::Context->dbh->prepare($query);
     $sth->execute( @$bind_params );
-
     my %infos_of;
     while ( my $row = $sth->fetchrow_hashref ) {
-        if ( defined $value_name ) {
-            $infos_of{ $row->{$key_name} } = $row->{$value_name};
-        }
-        else {
-            $infos_of{ $row->{$key_name} } = $row;
-        }
+        $infos_of{ $row->{$key_name} } = (defined $value_name) ? $row->{$value_name} : $row;
     }
-    $sth->finish;
-
     return \%infos_of;
 }
 
-- 
1.5.6.5




More information about the Koha-patches mailing list