From: <jgr...@us...> - 2003-03-03 15:22:23
|
Update of /cvsroot/popfile/engine/POPFile In directory sc8-pr-cvs1:/tmp/cvs-serv12042/POPFile Modified Files: Configuration.pm Logger.pm Module.pm Log Message: Partial and broken work on POPFile refactoring; READ ONLY at this point; do not bother running unless you are very brave Index: Configuration.pm =================================================================== RCS file: /cvsroot/popfile/engine/POPFile/Configuration.pm,v retrieving revision 1.7 retrieving revision 1.8 diff -C2 -d -r1.7 -r1.8 *** Configuration.pm 28 Feb 2003 01:45:20 -0000 1.7 --- Configuration.pm 3 Mar 2003 15:21:44 -0000 1.8 *************** *** 1,4 **** # POPFILE LOADABLE MODULE ! package POPFile::Configuration; #---------------------------------------------------------------------------- --- 1,7 ---- # POPFILE LOADABLE MODULE ! package POPFile::Configuration; ! ! use POPFile::Module; ! @ISA = ( "POPFile::Module" ); #---------------------------------------------------------------------------- Index: Logger.pm =================================================================== RCS file: /cvsroot/popfile/engine/POPFile/Logger.pm,v retrieving revision 1.8 retrieving revision 1.9 diff -C2 -d -r1.8 -r1.9 *** Logger.pm 13 Feb 2003 21:24:17 -0000 1.8 --- Logger.pm 3 Mar 2003 15:21:45 -0000 1.9 *************** *** 2,5 **** --- 2,8 ---- package POPFile::Logger; + use POPFile::Module; + @ISA = ("POPFile::Module"); + #---------------------------------------------------------------------------- # Index: Module.pm =================================================================== RCS file: /cvsroot/popfile/engine/POPFile/Module.pm,v retrieving revision 1.1 retrieving revision 1.2 diff -C2 -d -r1.1 -r1.2 *** Module.pm 26 Feb 2003 05:05:29 -0000 1.1 --- Module.pm 3 Mar 2003 15:21:46 -0000 1.2 *************** *** 8,12 **** # # POPFile is constructed from a collection of classes which all have special ! # interface functions: # # initialize() - called after the class is created to set default values for internal --- 8,12 ---- # # POPFile is constructed from a collection of classes which all have special ! # PUBLIC interface functions: # # initialize() - called after the class is created to set default values for internal *************** *** 31,44 **** # used as the key for this module in %components # # A note on the naming # ! # A method or variable that ends with an underscore is PRIVATE and should not be accessed ! # from outside the class (or subclass; in C++ its protected), to access a PRIVATE variable # you will find an equivalent getter/setter method with no underscore. # # For example # ! # $c->foo_() is a private method ! # $c->{foo_} is a private variable # $c->foo() is a public method that modifies $c->{foo_} it always returns the current # value of the variable it is referencing and if passed a value sets that corresponding --- 31,56 ---- # used as the key for this module in %components # + # The following methods are PROTECTED and should be accessed by sub classes: + # + # log_() - sends a string to the logger + # + # config_() - gets or sets a configuration parameter for this module + # # A note on the naming # ! # A method or variable that ends with an underscore is PROTECTED and should not be accessed ! # from outside the class (or subclass; in C++ its protected), to access a PROTECTED variable # you will find an equivalent getter/setter method with no underscore. # + # Truly PRIVATE variables are indicated by a double underscore at the end of the name and + # should not be accessed outside the class without going through a getter/setter and may + # not be directly accessed by a subclass. + # # For example # ! # $c->foo__() is a private method ! # $c->{foo__} is a private variable ! # $c->foo_() is a protected method ! # $c->{foo_} is a protected variable # $c->foo() is a public method that modifies $c->{foo_} it always returns the current # value of the variable it is referencing and if passed a value sets that corresponding *************** *** 57,78 **** # #---------------------------------------------------------------------------- ! sub new { my $type = shift; my $self; ! # A reference to the POPFile::Configuration module, every module is # able to get configuration information through this, note that it # is valid when initialize is called, however, the configuration is not # read from disk until after initialize has been called ! ! $self->{configuration_} = 0; # A reference to the POPFile::Logger module ! ! $self->{logger_} = 0; # Used to tell any loops to terminate ! $self->{alive_} = 1; --- 69,94 ---- # #---------------------------------------------------------------------------- ! sub new { my $type = shift; my $self; ! # A reference to the POPFile::Configuration module, every module is # able to get configuration information through this, note that it # is valid when initialize is called, however, the configuration is not # read from disk until after initialize has been called ! ! $self->{configuration__} = 0; # PRIVATE # A reference to the POPFile::Logger module ! ! $self->{logger__} = 0; # PRIVATE ! ! # The name of this module ! ! $self->{name__} = ''; # PRIVATE # Used to tell any loops to terminate ! $self->{alive_} = 1; *************** *** 84,90 **** # This is a reference to a function (forker) in popfile.pl that performs a fork # and informs modules that a fork has occurred ! $self->{forker_} = 0; ! return bless $self, $type; } --- 100,106 ---- # This is a reference to a function (forker) in popfile.pl that performs a fork # and informs modules that a fork has occurred ! $self->{forker_} = 0; ! return bless $self, $type; } *************** *** 126,130 **** { my ( $self ) = @_; ! return 1; } --- 142,146 ---- { my ( $self ) = @_; ! return 1; } *************** *** 145,170 **** # --------------------------------------------------------------------------------------------- # - # name - # - # Called to get the simple name for this module, this is the name use to hook various - # module's together in popfile.pl and should be a simple lower case name. This is the only - # pure abstract function in POPFile::Module and will abort POPFile immediately if ever - # called. - # - # It should return a string containing the proposed name - # - # --------------------------------------------------------------------------------------------- - sub name - { - my ( $self ) = @_; - - # Pure virtual - - print "\nPOPFile::Module::name called; this function is pure virtual"; - exit(1); - } - - # --------------------------------------------------------------------------------------------- - # # reaper # --- 161,164 ---- *************** *** 214,217 **** --- 208,274 ---- } + # --------------------------------------------------------------------------------------------- + # + # log_ + # + # Called by a subclass to send a message to the logger, the logged message will be prefixed + # by the name of the module in use + # + # $message The message to log + # + # There is no return value from this method + # + # --------------------------------------------------------------------------------------------- + sub log_ + { + my ( $self, $message ) = @_; + + $self->{logger__}->debug( $self->{name__} . ':' . $message ); + } + + # --------------------------------------------------------------------------------------------- + # + # config_ + # + # Called by a subclass to get or set a configuration parameter + # + # $name The name of the parameter (e.g. 'port') + # $value (optional) The value to set + # $short_name 1 if the $name should be registered in short form as well + # + # If called with just a $name then config_() will return the current value + # of the configuration parameter. + # + # Short vs Long Names. All configuration parameters are identified by their + # long name which consists of the individual parameter name preceded by the + # module name (underscore is used as the separator). For compatbility with + # older versions of POPFile the configuration module will also recognize some + # short names (i.e. without the preceding name and underscore) and map automaticall + # to the long name + # + # Example: POP3 registers a parameter for its listen port call port, this is stored + # in the configuration as pop3_port. POP3 also registers for the short name version + # which is simply port. When loading the configuration either will be accepted. + # + # Note NO NEW PARAMETERS should use short form + # + # --------------------------------------------------------------------------------------------- + sub config_ + { + my ( $self, $name, $value, $short_name ) = @_; + + my $long_name = $self->{name__} . '_' . $name; + + if ( defined( $value ) ) { + $self->{configuration__}->{configuration}{$long_name} = $value; + + if ( defined( $short_name ) ) { + $self->{configuration__}->{configuration}{$name} = $value; + } + } + + return $self->{configuration__}->{configuration}{$long_name}; + } + # GETTER/SETTER methods. Note that I do not expect documentation of these unless they # are non-trivial since the documentation would be a waste of space *************** *** 223,231 **** # { # my ( $self, $value ) = @_; ! # # if ( defined( $value ) ) { # $self->{foo_} = $value; # } ! # # return $self->{foo_}; # } --- 280,288 ---- # { # my ( $self, $value ) = @_; ! # # if ( defined( $value ) ) { # $self->{foo_} = $value; # } ! # # return $self->{foo_}; # } *************** *** 237,246 **** { my ( $self, $value ) = @_; ! if ( defined( $value ) ) { ! $self->{configuration_} = $value; } ! ! return $self->{configuration_}; } --- 294,303 ---- { my ( $self, $value ) = @_; ! if ( defined( $value ) ) { ! $self->{configuration__} = $value; } ! ! return $self->{configuration__}; } *************** *** 248,256 **** { my ( $self, $value ) = @_; ! if ( defined( $value ) ) { $self->{forker_} = $value; } ! return $self->{forker_}; } --- 305,313 ---- { my ( $self, $value ) = @_; ! if ( defined( $value ) ) { $self->{forker_} = $value; } ! return $self->{forker_}; } *************** *** 259,268 **** { my ( $self, $value ) = @_; ! if ( defined( $value ) ) { ! $self->{logger_} = $value; } ! ! return $self->{logger_}; } --- 316,325 ---- { my ( $self, $value ) = @_; ! if ( defined( $value ) ) { ! $self->{logger__} = $value; } ! ! return $self->{logger__}; } *************** *** 270,278 **** { my ( $self, $value ) = @_; ! if ( defined( $value ) ) { $self->{pipeready_} = $value; } ! return $self->{pipeready_}; } --- 327,335 ---- { my ( $self, $value ) = @_; ! if ( defined( $value ) ) { $self->{pipeready_} = $value; } ! return $self->{pipeready_}; } *************** *** 281,290 **** { my ( $self, $value ) = @_; ! if ( defined( $value ) ) { $self->{alive_} = $value; } ! return $self->{alive_}; } --- 338,358 ---- { my ( $self, $value ) = @_; ! if ( defined( $value ) ) { $self->{alive_} = $value; } ! return $self->{alive_}; + } + + sub name + { + my ( $self, $value ) = @_; + + if ( defined( $value ) ) { + $self->{name__} = $value; + } + + return $self->{name__}; } |