Skip to Content.
Sympa Menu

devel - [sympa-developpers] ugly code 2

Subject: Developers of Sympa

List archive

Chronological Thread  
  • From: Guillaume Rousse <address@concealed>
  • To: address@concealed
  • Subject: [sympa-developpers] ugly code 2
  • Date: Mon, 22 Jul 2013 15:03:21 +0200

## 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.
--
Guillaume Rousse
INRIA, Direction des systèmes d'information
Domaine de Voluceau
Rocquencourt - BP 105
78153 Le Chesnay
Tel: 01 39 63 58 31

Attachment: smime.p7s
Description: Signature cryptographique S/MIME




Archive powered by MHonArc 2.6.19+.

Top of Page