[Koha-devel] The order of "use"

David Cook dcook at prosentient.com.au
Thu Oct 25 01:24:26 CEST 2018


Whether or not to prefix the function with "C4::Accounts::" is something we should probably talk about at some point. 

Historically, a lot of Koha modules use the "Exporter" module to export their functions into the main namespace of the caller. When "use C4::Accounts" runs, it automatically calls the "import" function in C4::Accounts, which in most/all cases is provided by the Exporter module. Blah blah blah. You can use the syntax "use C4::Accounts qw()" to prevent the importing of any functions or you can selectively import functions with "use C4::Accounts qw(function1 function2)". Fun times...

If you don't automatically import functions into the main namespace of the caller, then you'd want to definitely prefix the function with C4::Accounts::, otherwise you'll get an error since that function would be declared in the main namespace (or worse it's the same function name and you wind up with more errors/unexpected behaviour). 

Personally, I rather use object oriented programming like we're trying in the Koha:: modules and/or have function libraries that don't use Exporter and instead require use of full namespace (e.g. C4::Accounts::function1). I think that's just a lot more transparent. More verbose but more explicit and easier to understand. Also fewer changes of function name collisions and less messy main namespace in the caller. 

That's my 2 cents. 

David Cook
Systems Librarian
Prosentient Systems
72/330 Wattle St
Ultimo, NSW 2007
Australia

Office: 02 9212 0899
Direct: 02 8005 0595

-----Original Message-----
From: koha-devel-bounces at lists.koha-community.org [mailto:koha-devel-bounces at lists.koha-community.org] On Behalf Of Mark Tompsett
Sent: Thursday, 25 October 2018 3:43 AM
To: Koha-devel <koha-devel at lists.koha-community.org>
Subject: [Koha-devel] The order of "use"

Greetings,

I was looking at bug 21641, and noticed the patch was explicitly stating
C4::Accounts:: on the function in question. I vaguely recalled this sort of symptom shows itself in a knotted “use” mess.

C4::Circulation –> C4::Members –> C4::Accounts C4::Circulation –> C4::Accounts C4::Circulation –> C4::Overdues –> C4::Accounts

What is the best order to list these? C4::Accounts last?
Is putting the C4::Accounts:: on the function in question still something we should do anyways?

Feedback appreciated,
Mark Tompsett 

_______________________________________________
Koha-devel mailing list
Koha-devel at lists.koha-community.org
http://lists.koha-community.org/cgi-bin/mailman/listinfo/koha-devel
website : http://www.koha-community.org/ git : http://git.koha-community.org/ bugs : http://bugs.koha-community.org/




More information about the Koha-devel mailing list