Hi Jesse,

The below is a much cleaned up version of the global accessor method that I
believe is a Good Thing for each of the reasons that I mentioned in my prior
posts (and some that I didn't mention).  If you drop the init_globals() method
into the CGI::Application class, it should work.  However, it may be a better
idea to put into a CGI::Application::Config class, for future expansion.

Summary: From within the WidgetApp:

  $self->init_gloabals( "package", "conf_mode", "Config_class" )

'package' in which to put globals from the ::Config object; default or undef
indicates current (caller) package

'conf_mode' is set of globals to get from the; default or undef uses
'std_conf_mode' which must exist in the ::Config object;

'Config_class' is the class holding the conf_mode methods and globals; default
or undef uses ${caller_pkg}::Config

Bill

----
William Catlan, J.D.
Programmer Analyst - Internet Strategist
"Early Insights That Make A Difference"
v: 631.956.0780
f: 631.956.0026
e: [EMAIL PROTECTED]
----

This sub goes into CGI::Application:

sub init_globals
{
  my $self = shift;
  my $caller_pkg = ( defined $_[0] ) ? $_[0] : caller; # caller package
  my $conf_mode  = ( defined $_[1] ) ? $_[1] : "std_conf_mode"; # standard conf
mode
  my $conf_pkg   = ( defined $_[2] ) ? $_[2] : "${caller_pkg}::Config"; #
standard ::Config class - must be placed in directory $caller_pkg in a path
listed in @INC

  eval "require $conf_pkg";
  $conf_pkg->$conf_mode;

  foreach $symname (keys %{"${conf_pkg}::"})
  {
    my $sym = (${"${conf_pkg}::$symname"});
    if ( defined $sym )
    {
      # print "$symname = $sym\n";
      (${"${caller_pkg}::$symname"}) = (${"${conf_pkg}::$symname"});
    }

  }

}


package WidgetApp::Config;

use CGI::Application;

sub new
{
  my $pkg = shift;
  my $r_config = {};

  bless $r_config, $pkg;

  return $r_config;
}

sub std_conf_mode {}


package WidgetApp;

use base 'CGI::Application';
.
.
.
$self->init_globals( undef, undef, undef );
.
.
.







---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to