cvsuser     04/02/02 13:23:16

  Modified:    App-Context/lib/App Context.pm
  Log:
  cleaned up some debug and option naming in code
  
  Revision  Changes    Path
  1.13      +61 -52    p5ee/App-Context/lib/App/Context.pm
  
  Index: Context.pm
  ===================================================================
  RCS file: /cvs/public/p5ee/App-Context/lib/App/Context.pm,v
  retrieving revision 1.12
  retrieving revision 1.13
  diff -u -w -r1.12 -r1.13
  --- Context.pm        3 Dec 2003 16:16:03 -0000       1.12
  +++ Context.pm        2 Feb 2004 21:23:16 -0000       1.13
  @@ -1,6 +1,6 @@
   
   #############################################################################
  -## $Id: Context.pm,v 1.12 2003/12/03 16:16:03 spadkins Exp $
  +## $Id: Context.pm,v 1.13 2004/02/02 21:23:16 spadkins Exp $
   #############################################################################
   
   package App::Context;
  @@ -118,8 +118,8 @@
   =head2 Master Data Structure Map
   
    $context
  - $context->{dbgscope}{$class}          Debugging all methods in class
  - $context->{dbgscope}{$class.$method}  Debugging a single method
  + $context->{debug_scope}{$class}          Debugging all methods in class
  + $context->{debug_scope}{$class.$method}  Debugging a single method
    $context->{options}    Args that Context was created with
    $context->{used}{$class}  Similar to %INC, keeps track of what classes used
    $context->{Conf}{$user} Info from conf file
  @@ -215,7 +215,7 @@
           }
           if ($debug) {
               foreach $pkg (split(/,/,$debug)) {
  -                $self->{dbgscope}{$pkg} = 1;
  +                $self->{debug_scope}{$pkg} = 1;
               }
           }
       }
  @@ -241,7 +241,7 @@
       };
       $self->add_message($@) if ($@);
   
  -    if ($options{debugconf} >= 2) {
  +    if ($options{debug_conf} >= 2) {
           $self->dbgprint($self->{conf}->dump());
       }
   
  @@ -753,11 +753,11 @@
   
       $script_url_dir = $context->iget("scriptUrlDir", "/cgi-bin");
   
  -The iget() returns the value of an Initialization Conf variable
  +The iget() returns the value of an Option variable
   (or the "default" value if not set).
   
   This is an alternative to 
  -getting the reference of the entire hash of Initialization Conf
  +getting the reference of the entire hash of Option
   variables with $self->options().
   
   =cut
  @@ -1297,10 +1297,9 @@
   
   =head2 session()
   
  -The session() method returns the session
  -
       * Signature: $session = $context->session();
  -    * Param:  void
  +    * Signature: $session = $context->session($session_id);
  +    * Param:  $session_id   string
       * Return: $session    App::Session
       * Throws: <none>
       * Since:  0.01
  @@ -1310,33 +1309,42 @@
       $session = $context->session();
       $session = $context->session("some_session_id");
   
  +The session() method returns the current session (if no session_id is
  +supplied).  If a session_id is supplied, the requested session is
  +instantiated if necessary and is returned.
  +
   =cut
   
   sub session {
       &App::sub_entry if ($App::trace_subs);
  -    my ($self, $session_id) = @_;
  +    my ($self, $session_id, $args) = @_;
       my ($session_class, $session, $options);
       if ($session_id) {
           $session = $self->{sessions}{$session_id};
  -        if (! defined $session) {
  -            $session_id = $self->new_session_id();
  +    }
  +    else {
  +        $session_id = "default";
  +        $session = $self->{session};
  +    }
  +    if (!$session) {
               $options = $self->{options};
               $session_class = $options->{session_class} || 
$self->_default_session_class();
   
               eval {
                   $self->dbgprint("Context->new(): session_class=$session_class (", 
join(",",%$options), ")")
                       if ($App::DEBUG && $self->dbg(1));
  -        
  -                $self->{sessions}{$session_id} = App->new($session_class, "new", { 
context => $self, name => $session_id });
  -            };
  -            $self->add_message($@) if ($@);
  +            if (defined $args) {
  +                $args = { %$args };
           }
           else {
  -            $session = $self->{sessions}{$session_id};
  -        }
  +                $args = {};
       }
  -    else {
  -        $session = $self->{session};
  +            $args->{context} = $self;
  +            $args->{name} = $session_id;
  +            $session = App->new($session_class, "new", $args);
  +            $self->{sessions}{$session_id} = $session;
  +        };
  +        $self->add_message($@) if ($@);
       }
       &App::sub_exit($session) if ($App::trace_subs);
       return($session);
  @@ -1345,8 +1353,9 @@
   sub new_session_id {
       &App::sub_entry if ($App::trace_subs);
       my ($self) = @_;
  -    &App::sub_exit($self->{session}) if ($App::trace_subs);
  -    $self->{session};
  +    my $session_id = "user";
  +    &App::sub_exit($session_id) if ($App::trace_subs);
  +    return($session_id);
   }
   
   sub set_current_session {
  @@ -1356,7 +1365,7 @@
       &App::sub_exit() if ($App::trace_subs);
   }
   
  -sub set_default_session {
  +sub restore_default_session {
       &App::sub_entry if ($App::trace_subs);
       my ($self) = @_;
       $self->{session} = $self->{sessions}{default};
  @@ -1408,26 +1417,26 @@
   
   =cut
   
  -my %dbgscope;
  +my %debug_scope;
   
   sub dbg {
       my ($self, $level) = @_;
       return 0 if (! $App::DEBUG);
       $level = 1 if (!defined $level);
       return 0 if (defined $level && $App::DEBUG < $level);
  -    my ($dbgscope, $stacklevel);
  +    my ($debug_scope, $stacklevel);
       my ($package, $file, $line, $subroutine, $hasargs, $wantarray);
  -    $dbgscope = (ref($self) eq "") ? \%dbgscope : $self->{dbgscope};
  +    $debug_scope = (ref($self) eq "") ? \%debug_scope : $self->{debug_scope};
       $stacklevel = 1;
       ($package, $file, $line, $subroutine, $hasargs, $wantarray) = 
caller($stacklevel);
       while (defined $subroutine && $subroutine eq "(eval)") {
           $stacklevel++;
           ($package, $file, $line, $subroutine, $hasargs, $wantarray) = 
caller($stacklevel);
       }
  -    return 1 if (! defined $dbgscope);
  -    return 1 if (! %$dbgscope);
  -    return 1 if (defined $dbgscope->{$package});
  -    return 1 if (defined $dbgscope->{$subroutine});
  +    return 1 if (! defined $debug_scope);
  +    return 1 if (! %$debug_scope);
  +    return 1 if (defined $debug_scope->{$package});
  +    return 1 if (defined $debug_scope->{$subroutine});
       return 0;
   }
   
  @@ -1497,39 +1506,39 @@
   }
   
   #############################################################################
  -# dbgscope()
  +# debug_scope()
   #############################################################################
   
  -=head2 dbgscope()
  +=head2 debug_scope()
   
  -The dbgscope() method is used to get the hash which determines which
  +The debug_scope() method is used to get the hash which determines which
   debug statements are to be printed out when the debug level is set to a
   positive number.  It returns a hash reference.  If class names or
   "class.method" names are defined in the hash, it will cause the
   debug statements from those classes or methods to be printed.
   
  -    * Signature: $dbgscope = $context->dbgscope();
  +    * Signature: $debug_scope = $context->debug_scope();
       * Param:     void
  -    * Return:    $dbgscope   {}
  +    * Return:    $debug_scope   {}
       * Throws:    App::Exception::Context
       * Since:     0.01
   
       Sample Usage: 
   
  -    $dbgscope = $context->dbgscope();
  -    $dbgscope->{"App::Context::CGI"} = 1;
  -    $dbgscope->{"App::Context::CGI.process_request"} = 1;
  +    $debug_scope = $context->debug_scope();
  +    $debug_scope->{"App::Context::CGI"} = 1;
  +    $debug_scope->{"App::Context::CGI.process_request"} = 1;
   
   =cut
   
  -sub dbgscope {
  +sub debug_scope {
       my $self = shift;
  -    my $dbgscope = $self->{dbgscope};
  -    if (!defined $dbgscope) {
  -        $dbgscope = {};
  -        $self->{dbgscope} = $dbgscope;
  +    my $debug_scope = $self->{debug_scope};
  +    if (!defined $debug_scope) {
  +        $debug_scope = {};
  +        $self->{debug_scope} = $debug_scope;
       }
  -    $dbgscope;
  +    $debug_scope;
   }
   
   #############################################################################
  
  
  

Reply via email to