I believe the problem of the XML file being read for each "use" statement is primarily attributable to the bad way Context uses an "import" function that then calls its own constructor (each time!).
This also prevents us from doing something intelligent like: use C4::Context qw(marcfromkohafield); and actually get the right result, i.e. "marcfromkohafield" in our namespace. In fact, Context's import does *nothing* in the way of actual import/export and blocks Context being an Exporter. That might be fine if Context were entirely OO, but it clearly is not. IMHO, the intended purpose is better suited to the INIT block, that should only happen once per execution at the class level. If it is going to read KOHA_CONF on import, certainly it should do so only once, but I would argue it shouldn't do it on import in ANY case. --Joe Atzberger On Wed, Jul 2, 2008 at 3:28 AM, Frederic Demians <[EMAIL PROTECTED]> wrote: > Each time a Perl script or a module has this statement: > > use C4::Context > > a default context was created and XML config file was loaded. > > A syspref hash caches syspref already read for the whole > session. A better approach would cash syspref for the > whole application: mod_perl required (or memcached) > --- > C4/Context.pm | 8 ++++++-- > 1 files changed, 6 insertions(+), 2 deletions(-) > > diff --git a/C4/Context.pm b/C4/Context.pm > index e81fd95..ac2255f 100644 > --- a/C4/Context.pm > +++ b/C4/Context.pm > @@ -248,11 +248,10 @@ sub db_scheme2dbi { > sub import { > my $package = shift; > my $conf_fname = shift; # Config file name > - my $context; > > # Create a new context from the given config file name, if > # any, then set it as the current context. > - $context = new C4::Context($conf_fname); > + $context = new C4::Context($conf_fname) unless $context; > return undef if !defined($context); > $context->set_context; > } > @@ -445,10 +444,14 @@ variable is not set, or in case of error, returns the > undefined value. > # FIXME - The preferences aren't likely to change over the lifetime of > # the script (and things might break if they did change), so perhaps > # this function should cache the results it finds. > + > +my %syspref; > + > sub preference > { > my $self = shift; > my $var = shift; # The system preference to return > + return $syspref{$var} if $syspref{$var}; > my $retval; # Return value > my $dbh = C4::Context->dbh or return 0; > # Look up systempreferences.variable==$var > @@ -458,6 +461,7 @@ sub preference > WHERE variable='$var' > LIMIT 1 > EOT > + $syspref{$var} = $retval; > return $retval; > } >
_______________________________________________ Koha-devel mailing list Koha-devel@lists.koha.org http://lists.koha.org/mailman/listinfo/koha-devel