Skip to Content.
Sympa Menu

devel - Re: [sympa-developpers] ugly code 2

Subject: Developers of Sympa

List archive

Chronological Thread  
  • From: IKEDA Soji <address@concealed>
  • To: address@concealed
  • Subject: Re: [sympa-developpers] ugly code 2
  • Date: Tue, 23 Jul 2013 12:40:36 +0900

Hi,

Our s**tting router hung-up in this weekend, so I began to watch
merges yesterday.

On Mon, 22 Jul 2013 15:03:21 +0200
Guillaume Rousse <address@concealed> wrote:

> ## getter for internal config parameters.
> croak "Can't call method \"$attr\" on uninitialized $self class"
> unless $Sympa::Site::is_initialized;
>
> If you need initialisation, it means you need a state. If you need a
> state, you need a instance, not a class with global parameters.
>
> As I guess the point is to share a single instance of Sympa::Site around
> the code, you'd better create it once for all in top-level code, and
> make it accessible as a global variable:
>
> # top-level code
>
> our $site = Sympa::Site->new();
> $site->load();
>
> # another part of code
>
> package Sympa::FooBar;
>
> $main::site->get_foo();
>
> That's what I'm currently trying to do with database object, for instance.

The croak line shown is for impossible cases: If it occurred, it is a
bug.

After succeeding merges, $Sympa::Site::is_initialized will be
referred by Sympa::Log and Sympa::Language. Because those modules
must work even when site parameters had not been loaded: In such
case they use hardcoded defaults.

I feel this is ugry, too, but instantiation won't help.

--
株式会社 コンバージョン セキュリティ&OSSソリューション部 池田荘児
〒231-0004 神奈川県横浜市中区元浜町3-21-2 ヘリオス関内ビル7F
e-mail address@concealed TEL 045-640-3550
http://www.conversion.co.jp/



Archive powered by MHonArc 2.6.19+.

Top of Page