Skip to content

Commit

Permalink
Bug 17600: Standardize our EXPORT_OK
Browse files Browse the repository at this point in the history
On bug 17591 we discovered that there was something weird going on with
the way we export and use subroutines/modules.
This patch tries to standardize our EXPORT to use EXPORT_OK only.

That way we will need to explicitely define the subroutine we want to
use from a module.

This patch is a squashed version of:
Bug 17600: After export.pl
Bug 17600: After perlimport
Bug 17600: Manual changes
Bug 17600: Other manual changes after second perlimports run
Bug 17600: Fix tests

And a lot of other manual changes.

export.pl is a dirty script that can be found on bug 17600.

"perlimport" is:
git clone https://github.com/oalders/App-perlimports.git
cd App-perlimports/
cpanm --installdeps .
export PERL5LIB="$PERL5LIB:/kohadevbox/koha/App-perlimports/lib"
find . \( -name "*.pl" -o -name "*.pm" \) -exec perl App-perlimports/script/perlimports --inplace-edit --no-preserve-unused --filename {} \;

The ideas of this patch are to:
* use EXPORT_OK instead of EXPORT
* perltidy the EXPORT_OK list
* remove '&' before the subroutine names
* remove some uneeded use statements
* explicitely import the subroutines we need within the controllers or
modules

Note that the private subroutines (starting with _) should not be
exported (and not used from outside of the module except from tests).

EXPORT vs EXPORT_OK (from
https://www.thegeekstuff.com/2010/06/perl-exporter-examples/)
"""
Export allows to export the functions and variables of modules to user’s namespace using the standard import method. This way, we don’t need to create the objects for the modules to access it’s members.

@export and @EXPORT_OK are the two main variables used during export operation.

@export contains list of symbols (subroutines and variables) of the module to be exported into the caller namespace.

@EXPORT_OK does export of symbols on demand basis.
"""

If this patch caused a conflict with a patch you wrote prior to its
push:
* Make sure you are not reintroducing a "use" statement that has been
removed
* "$subroutine" is not exported by the C4::$MODULE module
means that you need to add the subroutine to the @EXPORT_OK list
* Bareword "$subroutine" not allowed while "strict subs"
means that you didn't imported the subroutine from the module:
  - use $MODULE qw( $subroutine list );
You can also use the fully qualified namespace: C4::$MODULE::$subroutine

Signed-off-by: Jonathan Druart <jonathan.druart@bugs.koha-community.org>
  • Loading branch information
joubu committed Jul 16, 2021
1 parent af7e41d commit 9d6d641
Show file tree
Hide file tree
Showing 1,311 changed files with 4,077 additions and 4,362 deletions.
7 changes: 2 additions & 5 deletions C4/Accounts.pm
Original file line number Diff line number Diff line change
Expand Up @@ -22,23 +22,20 @@ use Modern::Perl;
use C4::Context;
use C4::Stats;
use C4::Members;
use C4::Log qw(logaction);
use Koha::Account;
use Koha::Account::Lines;
use Koha::Account::Offsets;
use Koha::Items;

use Mojo::Util qw(deprecated);
use Data::Dumper qw(Dumper);

use vars qw(@ISA @EXPORT);

BEGIN {
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(
&chargelostitem
&purge_zero_balance_fees
chargelostitem
purge_zero_balance_fees
);
}

Expand Down
108 changes: 53 additions & 55 deletions C4/Acquisition.pm
Original file line number Diff line number Diff line change
Expand Up @@ -19,13 +19,13 @@ package C4::Acquisition;


use Modern::Perl;
use Carp;
use Carp qw( carp croak );
use Text::CSV_XS;
use C4::Context;
use C4::Suggestions;
use C4::Biblio;
use C4::Contract;
use C4::Log qw(logaction);
use C4::Suggestions qw( GetSuggestion GetSuggestionFromBiblionumber ModSuggestion );
use C4::Biblio qw( GetMarcFromKohaField GetMarcStructure IsMarcStructureInternal );
use C4::Contract qw( GetContract );
use C4::Log qw( logaction );
use C4::Templates qw(gettemplate);
use Koha::DateUtils qw( dt_from_string output_pref );
use Koha::Acquisition::Baskets;
Expand All @@ -42,60 +42,58 @@ use Koha::Patrons;
use C4::Koha;

use MARC::Field;
use MARC::Record;
use JSON qw(to_json);
use JSON qw( to_json );

use Time::localtime;

use vars qw(@ISA @EXPORT);

our (@ISA, @EXPORT_OK);
BEGIN {
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(
&GetBasket &NewBasket &ReopenBasket &ModBasket
&GetBasketAsCSV &GetBasketGroupAsCSV
&GetBasketsByBookseller &GetBasketsByBasketgroup
&GetBasketsInfosByBookseller
&GetBasketUsers &ModBasketUsers
&CanUserManageBasket
&ModBasketHeader
&ModBasketgroup &NewBasketgroup &DelBasketgroup &GetBasketgroup &CloseBasketgroup
&GetBasketgroups &ReOpenBasketgroup
&ModOrder &GetOrder &GetOrders &GetOrdersByBiblionumber
&GetOrderFromItemnumber
&SearchOrders &GetHistory &GetRecentAcqui
&ModReceiveOrder &CancelReceipt
&TransferOrder
&ModItemOrder
&GetParcels
&GetInvoices
&GetInvoice
&GetInvoiceDetails
&AddInvoice
&ModInvoice
&CloseInvoice
&ReopenInvoice
&DelInvoice
&MergeInvoices
&AddClaim
&GetBiblioCountByBasketno
&GetOrderUsers
&ModOrderUsers
&NotifyOrderUsers
&FillWithDefaultValues
&get_rounded_price
&get_rounding_sql
@ISA = qw(Exporter);
@EXPORT_OK = qw(
GetBasket NewBasket ReopenBasket ModBasket
GetBasketAsCSV GetBasketGroupAsCSV
GetBasketsByBookseller GetBasketsByBasketgroup
GetBasketsInfosByBookseller
GetBasketUsers ModBasketUsers
CanUserManageBasket
ModBasketHeader
ModBasketgroup NewBasketgroup DelBasketgroup GetBasketgroup CloseBasketgroup
GetBasketgroups ReOpenBasketgroup
ModOrder GetOrder GetOrders GetOrdersByBiblionumber
GetOrderFromItemnumber
SearchOrders GetHistory GetRecentAcqui
ModReceiveOrder CancelReceipt
populate_order_with_prices
TransferOrder
ModItemOrder
GetParcels
GetInvoices
GetInvoice
GetInvoiceDetails
AddInvoice
ModInvoice
CloseInvoice
ReopenInvoice
DelInvoice
MergeInvoices
AddClaim
GetBiblioCountByBasketno
GetOrderUsers
ModOrderUsers
NotifyOrderUsers
FillWithDefaultValues
get_rounded_price
get_rounding_sql
);
}

Expand Down
36 changes: 18 additions & 18 deletions C4/Auth.pm
Original file line number Diff line number Diff line change
Expand Up @@ -19,40 +19,37 @@ package C4::Auth;

use strict;
use warnings;
use Carp qw/croak/;
use Carp qw( croak );

use Digest::MD5 qw(md5_base64);
use JSON qw/encode_json/;
use URI::Escape;
use Digest::MD5 qw( md5_base64 );
use CGI::Session;

require Exporter;
use C4::Context;
use C4::Templates; # to get the template
use C4::Languages;
use C4::Search::History;
use Koha;
use Koha::Logger;
use Koha::Caches;
use Koha::AuthUtils qw(get_script_name hash_password);
use Koha::AuthUtils qw( get_script_name hash_password );
use Koha::Checkouts;
use Koha::DateUtils qw(dt_from_string);
use Koha::DateUtils qw( dt_from_string );
use Koha::Library::Groups;
use Koha::Libraries;
use Koha::Cash::Registers;
use Koha::Desks;
use Koha::Patrons;
use Koha::Patron::Consents;
use POSIX qw/strftime/;
use List::MoreUtils qw/ any /;
use Encode qw( encode is_utf8);
use C4::Auth_with_shibboleth;
use List::MoreUtils qw( any );
use Encode;
use C4::Auth_with_shibboleth qw( shib_ok get_login_shib login_shib_url logout_shib checkpw_shib );
use Net::CIDR;
use C4::Log qw/logaction/;
use C4::Log qw( logaction );

# use utf8;
use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS $ldap $cas $caslogout);

use vars qw($ldap $cas $caslogout);
our (@ISA, @EXPORT_OK);
BEGIN {
sub psgi_env { any { /^psgi\./ } keys %ENV }

Expand All @@ -63,12 +60,15 @@ BEGIN {

C4::Context->set_remote_address;

@ISA = qw(Exporter);
@EXPORT = qw(&checkauth &get_template_and_user &haspermission &get_user_subpermissions);
@EXPORT_OK = qw(&check_api_auth &get_session &check_cookie_auth &checkpw &checkpw_internal &checkpw_hash
&get_all_subpermissions &get_user_subpermissions track_login_daily &in_iprange
require Exporter;
@ISA = qw(Exporter);

@EXPORT_OK = qw(
checkauth check_api_auth get_session check_cookie_auth checkpw checkpw_internal checkpw_hash
get_all_subpermissions get_user_subpermissions track_login_daily in_iprange
get_template_and_user haspermission
);
%EXPORT_TAGS = ( EditPermissions => [qw(get_all_subpermissions get_user_subpermissions)] );

$ldap = C4::Context->config('useldapserver') || 0;
$cas = C4::Context->preference('casAuthentication');
$caslogout = C4::Context->preference('casLogout');
Expand Down
7 changes: 3 additions & 4 deletions C4/Auth_with_cas.pm
Original file line number Diff line number Diff line change
Expand Up @@ -21,20 +21,19 @@ use strict;
use warnings;

use C4::Context;
use Koha::AuthUtils qw(get_script_name);
use Koha::AuthUtils qw( get_script_name );
use Authen::CAS::Client;
use CGI qw ( -utf8 );
use FindBin;
use YAML::XS;

use Koha::Logger;

use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);
our (@ISA, @EXPORT_OK);

BEGIN {
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(check_api_auth_cas checkpw_cas login_cas logout_cas login_cas_url logout_if_required);
@EXPORT_OK = qw(check_api_auth_cas checkpw_cas login_cas logout_cas login_cas_url logout_if_required);
}
my $defaultcasserver;
my $casservers;
Expand Down
12 changes: 5 additions & 7 deletions C4/Auth_with_ldap.pm
Original file line number Diff line number Diff line change
Expand Up @@ -18,23 +18,21 @@ package C4::Auth_with_ldap;
# along with Koha; if not, see <http://www.gnu.org/licenses>.

use Modern::Perl;
use Carp;
use Carp qw( croak );

use C4::Context;
use C4::Members::Messaging;
use C4::Auth qw(checkpw_internal);
use C4::Auth qw( checkpw_internal );
use Koha::Patrons;
use Koha::AuthUtils qw(hash_password);
use List::MoreUtils qw( any );
use Koha::AuthUtils qw( hash_password );
use Net::LDAP;
use Net::LDAP::Filter;

use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);

our (@ISA, @EXPORT_OK);
BEGIN {
require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw( checkpw_ldap );
@EXPORT_OK = qw( checkpw_ldap );
}

# Redefine checkpw_ldap:
Expand Down
12 changes: 5 additions & 7 deletions C4/Auth_with_shibboleth.pm
Original file line number Diff line number Diff line change
Expand Up @@ -20,22 +20,20 @@ package C4::Auth_with_shibboleth;
use Modern::Perl;

use C4::Context;
use Koha::AuthUtils qw(get_script_name);
use Koha::AuthUtils qw( get_script_name );
use Koha::Database;
use Koha::Patrons;
use C4::Members::Messaging;
use Carp;
use CGI;
use List::MoreUtils qw(any);
use Carp qw( carp );
use List::MoreUtils qw( any );

use Koha::Logger;

use vars qw(@ISA @EXPORT @EXPORT_OK %EXPORT_TAGS);

our (@ISA, @EXPORT_OK);
BEGIN {
require Exporter;
@ISA = qw(Exporter);
@EXPORT =
@EXPORT_OK =
qw(shib_ok logout_shib login_shib_url checkpw_shib get_login_shib);
}

Expand Down
66 changes: 34 additions & 32 deletions C4/AuthoritiesMarc.pm
Original file line number Diff line number Diff line change
Expand Up @@ -21,13 +21,12 @@ package C4::AuthoritiesMarc;
use strict;
use warnings;
use C4::Context;
use MARC::Record;
use C4::Biblio;
use C4::Search;
use C4::Biblio qw( GetFrameworkCode GetMarcBiblio ModBiblio );
use C4::Search qw( FindDuplicate new_record_from_zebra );
use C4::AuthoritiesMarc::MARC21;
use C4::AuthoritiesMarc::UNIMARC;
use C4::Charset;
use C4::Log;
use C4::Charset qw( SetUTF8Flag );
use C4::Log qw( logaction );
use Koha::MetadataRecord::Authority;
use Koha::Authorities;
use Koha::Authority::MergeRequests;
Expand All @@ -38,35 +37,38 @@ use Koha::SearchEngine;
use Koha::SearchEngine::Indexer;
use Koha::SearchEngine::Search;

use vars qw(@ISA @EXPORT);

our (@ISA, @EXPORT_OK);
BEGIN {

require Exporter;
@ISA = qw(Exporter);
@EXPORT = qw(
&GetTagsLabels
&GetAuthMARCFromKohaField
&AddAuthority
&ModAuthority
&DelAuthority
&GetAuthority
&GetAuthorityXML
&SearchAuthorities
&BuildSummary
&BuildAuthHierarchies
&BuildAuthHierarchy
&GenerateHierarchy
&merge
&FindDuplicateAuthority
&GuessAuthTypeCode
&GuessAuthId
);
require Exporter;
@ISA = qw(Exporter);
@EXPORT_OK = qw(
GetTagsLabels
GetAuthMARCFromKohaField
AddAuthority
ModAuthority
DelAuthority
GetAuthority
GetAuthorityXML
SearchAuthorities
BuildSummary
BuildAuthHierarchies
BuildAuthHierarchy
GenerateHierarchy
GetHeaderAuthority
AddAuthorityTrees
CompareFieldWithAuthority
merge
FindDuplicateAuthority
GuessAuthTypeCode
GuessAuthId
compare_fields
);
}


Expand Down
1 change: 0 additions & 1 deletion C4/AuthoritiesMarc/MARC21.pm
Original file line number Diff line number Diff line change
Expand Up @@ -18,7 +18,6 @@ package C4::AuthoritiesMarc::MARC21;
# along with Koha; if not, see <http://www.gnu.org/licenses>.

use Modern::Perl;
use MARC::Record;

=head1 NAME
Expand Down
Loading

0 comments on commit 9d6d641

Please sign in to comment.