@@ -, +, @@ context --- C4/Reserves.pm | 2 +- C4/SIP/ILS/Transaction/Hold.pm | 2 +- Koha/Club.pm | 4 ++-- Koha/Club/Enrollment.pm | 4 ++-- Koha/Club/Field.pm | 2 +- Koha/Objects.pm | 18 +++++++++--------- Koha/Patron.pm | 7 +++++-- Koha/Subscription.pm | 4 ++-- acqui/booksellers.pl | 2 +- acqui/uncertainprice.pl | 2 +- cataloguing/moveitem.pl | 2 +- circ/overdue.pl | 2 +- members/memberentry.pl | 2 +- members/pay.pl | 4 ++-- opac/opac-memberentry.pl | 2 +- t/db_dependent/Koha/Objects.t | 13 ++++++++++--- 16 files changed, 41 insertions(+), 31 deletions(-) --- a/C4/Reserves.pm +++ a/C4/Reserves.pm @@ -800,7 +800,7 @@ sub CheckReserves { next if (($branchitemrule->{'holdallowed'} == 1) && ($branch ne $patron->branchcode)); my $hold_fulfillment_policy = $branchitemrule->{hold_fulfillment_policy}; next if ( ($branchitemrule->{hold_fulfillment_policy} ne 'any') && ($res->{branchcode} ne $item->$hold_fulfillment_policy) ); - next unless $item->can_be_transferred( { to => scalar Koha::Libraries->find( $res->{branchcode} ) } ); + next unless $item->can_be_transferred( { to => Koha::Libraries->find( $res->{branchcode} ) } ); $priority = $res->{'priority'}; $highest = $res; last if $local_hold_match; --- a/C4/SIP/ILS/Transaction/Hold.pm +++ a/C4/SIP/ILS/Transaction/Hold.pm @@ -60,7 +60,7 @@ sub do_hold { $self->ok(0); return $self; } - unless ( $item->can_be_transferred( { to => scalar Koha::Libraries->find( $branch ) } ) ) { + unless ( $item->can_be_transferred( { to => Koha::Libraries->find( $branch ) } ) ) { $self->screen_msg('Item cannot be transferred.'); $self->ok(0); return $self; --- a/Koha/Club.pm +++ a/Koha/Club.pm @@ -48,7 +48,7 @@ sub club_template { return unless $self->club_template_id(); - return scalar Koha::Club::Templates->find( $self->club_template_id() ); + return Koha::Club::Templates->find( $self->club_template_id() ); } =head3 club_fields @@ -84,7 +84,7 @@ sub branch { return unless $self->branchcode(); - return scalar Koha::Libraries->find( $self->branchcode() ); + return Koha::Libraries->find( $self->branchcode() ); } =head3 type --- a/Koha/Club/Enrollment.pm +++ a/Koha/Club/Enrollment.pm @@ -59,7 +59,7 @@ sub cancel { sub club { my ( $self ) = @_; - return scalar Koha::Clubs->find( $self->club_id() ); + return Koha::Clubs->find( $self->club_id() ); } =head3 patron @@ -68,7 +68,7 @@ sub club { sub patron { my ( $self ) = @_; - return scalar Koha::Patrons->find( $self->borrowernumber() ); + return Koha::Patrons->find( $self->borrowernumber() ); } =head3 type --- a/Koha/Club/Field.pm +++ a/Koha/Club/Field.pm @@ -46,7 +46,7 @@ Represents the value set at creation time for a Koha::Club::Template::Field sub club_template_field { my ( $self ) = @_; - return scalar Koha::Club::Template::Fields->find( $self->club_template_field_id ); + return Koha::Club::Template::Fields->find( $self->club_template_field_id ); } =head3 type --- a/Koha/Objects.pm +++ a/Koha/Objects.pm @@ -85,15 +85,15 @@ my $object = Koha::Objects->find( $idpart1, $idpart2, $attrs ); # composite PK sub find { my ( $self, @pars ) = @_; - croak 'Cannot use "->find" in list context' if wantarray; - - return if !@pars || none { defined($_) } @pars; - - my $result = $self->_resultset()->find( @pars ); - - return unless $result; - - my $object = $self->object_class()->_new_from_dbic( $result ); + my $object; + + @pars = grep { defined } @pars; + if (@pars) { + my $result = $self->_resultset()->find(@pars); + if ($result) { + $object = $self->object_class()->_new_from_dbic($result); + } + } return $object; } --- a/Koha/Patron.pm +++ a/Koha/Patron.pm @@ -374,9 +374,12 @@ Returns a Koha::Patron object for this patron's guarantor sub guarantor { my ( $self ) = @_; - return unless $self->guarantorid(); + my $guarantor; + if ($self->guarantorid()) { + $guarantor = Koha::Patrons->find( $self->guarantorid() ); + } - return Koha::Patrons->find( $self->guarantorid() ); + return $guarantor; } sub image { --- a/Koha/Subscription.pm +++ a/Koha/Subscription.pm @@ -51,7 +51,7 @@ Returns the biblio linked to this subscription as a Koha::Biblio object sub biblio { my ($self) = @_; - return scalar Koha::Biblios->find($self->biblionumber); + return Koha::Biblios->find($self->biblionumber); } =head3 vendor @@ -62,7 +62,7 @@ Returns the vendor/supplier linked to this subscription as a Koha::Acquisition:: sub vendor { my ($self) = @_; - return scalar Koha::Acquisition::Booksellers->find($self->aqbooksellerid); + return Koha::Acquisition::Booksellers->find($self->aqbooksellerid); } =head3 subscribers --- a/acqui/booksellers.pl +++ a/acqui/booksellers.pl @@ -82,7 +82,7 @@ my $allbaskets= $query->param('allbaskets')||0; my @suppliers; if ($booksellerid) { - push @suppliers, scalar Koha::Acquisition::Booksellers->find( $booksellerid ); + push @suppliers, Koha::Acquisition::Booksellers->find( $booksellerid ); } else { @suppliers = Koha::Acquisition::Booksellers->search( { name => { -like => "%$supplier%" } }, --- a/acqui/uncertainprice.pl +++ a/acqui/uncertainprice.pl @@ -72,7 +72,7 @@ my $op = $input->param('op'); my $owner = $input->param('owner') || 0 ; # flag to see only "my" orders, or everyone orders my $bookseller = Koha::Acquisition::Booksellers->find( $booksellerid ); -$template->param( basket => scalar Koha::Acquisition::Baskets->find($basketno) ); +$template->param( basket => Koha::Acquisition::Baskets->find($basketno) ); #show all orders that have uncertain price for the bookseller my $pendingorders = SearchOrders({ --- a/cataloguing/moveitem.pl +++ a/cataloguing/moveitem.pl @@ -79,7 +79,7 @@ if ( $barcode && $biblionumber ) { if ($moveresult) { $template->param( success => 1, - from_biblio => scalar Koha::Biblios->find($frombiblionumber), + from_biblio => Koha::Biblios->find($frombiblionumber), ); } else { --- a/circ/overdue.pl +++ a/circ/overdue.pl @@ -299,7 +299,7 @@ if ($noreport) { } push @overduedata, { - patron => scalar Koha::Patrons->find( $data->{borrowernumber} ), + patron => Koha::Patrons->find( $data->{borrowernumber} ), duedate => $data->{date_due}, borrowernumber => $data->{borrowernumber}, cardnumber => $data->{cardnumber}, --- a/members/memberentry.pl +++ a/members/memberentry.pl @@ -800,7 +800,7 @@ $template->param( csrf_token => # HouseboundModule data $template->param( - housebound_role => scalar Koha::Patron::HouseboundRoles->find($borrowernumber), + housebound_role => Koha::Patron::HouseboundRoles->find($borrowernumber), ); if(defined($data{'flags'})){ --- a/members/pay.pl +++ a/members/pay.pl @@ -110,7 +110,7 @@ elsif ( $input->param('confirm_writeoff') ) { Koha::Account->new( { patron_id => $borrowernumber } )->pay( { amount => $amount, - lines => [ scalar Koha::Account::Lines->find($accountlines_id) ], + lines => [ Koha::Account::Lines->find($accountlines_id) ], type => 'writeoff', note => $payment_note, interface => C4::Context->interface, @@ -214,7 +214,7 @@ sub writeoff_all { Koha::Account->new( { patron_id => $borrowernumber } )->pay( { amount => $amount, - lines => [ scalar Koha::Account::Lines->find($accountlines_id) ], + lines => [ Koha::Account::Lines->find($accountlines_id) ], type => 'writeoff', note => $payment_note, interface => C4::Context->interface, --- a/opac/opac-memberentry.pl +++ a/opac/opac-memberentry.pl @@ -312,7 +312,7 @@ elsif ( $action eq 'edit' ) { #Display logged in borrower's data $template->param( borrower => $borrower, - guarantor => scalar Koha::Patrons->find($borrowernumber)->guarantor(), + guarantor => Koha::Patrons->find($borrowernumber)->guarantor(), hidden => GetHiddenFields( $mandatory, 'edit' ), csrf_token => Koha::Token->new->generate_csrf({ session_id => scalar $cgi->cookie('CGISESSID'), --- a/t/db_dependent/Koha/Objects.t +++ a/t/db_dependent/Koha/Objects.t @@ -46,13 +46,20 @@ my $borrowernumber_exists = grep { /^borrowernumber$/ } @columns; is( $borrowernumber_exists, 1, 'Koha::Objects->columns should return the table columns' ); subtest 'find' => sub { - plan tests => 4; + plan tests => 6; my $patron = $builder->build({source => 'Borrower'}); my $patron_object = Koha::Patrons->find( $patron->{borrowernumber} ); is( $patron_object->borrowernumber, $patron->{borrowernumber}, '->find should return the correct object' ); - eval { my @patrons = Koha::Patrons->find( $patron->{borrowernumber} ); }; - like( $@, qr|^Cannot use "->find" in list context|, "->find should not be called in list context to avoid side-effects" ); + my @patrons = Koha::Patrons->find( $patron->{borrowernumber} ); + is(scalar @patrons, 1, '->find in list context returns a value'); + is($patrons[0]->borrowernumber, $patron->{borrowernumber}, '->find in list context returns the same value as in scalar context'); + + my $patrons = { + foo => Koha::Patrons->find('foo'), + bar => 'baz', + }; + is ($patrons->{foo}, undef, '->find in list context returns undef when no record is found'); # Test sending undef to find; should not generate a warning warning_is { $patron = Koha::Patrons->find( undef ); } --