cvsuser     05/10/20 12:40:39

  Modified:    App-Context/lib App.pm
  Log:
  added App::in_debug_scope and App::debug_indent()
  
  Revision  Changes    Path
  1.18      +84 -1     p5ee/App-Context/lib/App.pm
  
  Index: App.pm
  ===================================================================
  RCS file: /cvs/public/p5ee/App-Context/lib/App.pm,v
  retrieving revision 1.17
  retrieving revision 1.18
  diff -u -r1.17 -r1.18
  --- App.pm    12 Oct 2005 13:53:35 -0000      1.17
  +++ App.pm    20 Oct 2005 19:40:39 -0000      1.18
  @@ -899,6 +899,89 @@
       return(@_);
   }
   
  +#############################################################################
  +# in_debug_scope()
  +#############################################################################
  +
  +=head2 in_debug_scope()
  +
  +    * Signature: &App::in_debug_scope
  +    * Signature: App->in_debug_scope
  +    * Param:     <no arg list supplied>
  +    * Return:    void
  +    * Throws:    none
  +    * Since:     0.01
  +
  +This is called within a subroutine or method in order to see if debug output
  +should be produced.
  +
  +  if ($App::debug && &App::in_debug_scope) {
  +      print "This is debug output\n";
  +  }
  +
  +Note: The App::in_debug_scope subroutine also checks $App::debug, but 
checking
  +it in your code allows you to skip the subroutine call if you are not 
debugging.
  +
  +  if (&App::in_debug_scope) {
  +      print "This is debug output\n";
  +  }
  +
  +=cut
  +
  +sub in_debug_scope {
  +    if ($App::debug) {
  +        my ($stacklevel, $calling_package, $file, $line, $subroutine, 
$hasargs, $wantarray, $text);
  +        $stacklevel = 1;
  +        ($calling_package, $file, $line, $subroutine, $hasargs, $wantarray) 
= caller($stacklevel);
  +        while (defined $subroutine && $subroutine eq "(eval)") {
  +            $stacklevel++;
  +            ($calling_package, $file, $line, $subroutine, $hasargs, 
$wantarray) = caller($stacklevel);
  +        }
  +        my ($package, $sub);
  +
  +        # split subroutine into its "package" and the "sub" within the 
package
  +        if ($subroutine =~ /^(.*)::([^:]+)$/) {
  +            $package = $1;
  +            $sub = $2;
  +        }
  +
  +        if (%App::scope) {
  +            if ($App::scope_exclusive) {
  +                return(undef) if ($App::scope{$package} || 
$App::scope{"$package.$sub"});
  +            }
  +            else {
  +                return(undef) if (!$App::scope{$package} && 
!$App::scope{"$package.$sub"});
  +            }
  +        }
  +        return(1);
  +    }
  +    return(undef);
  +}
  +
  +#############################################################################
  +# debug_indent()
  +#############################################################################
  +
  +=head2 debug_indent()
  +
  +    * Signature: &App::debug_indent()
  +    * Signature: App->debug_indent()
  +    * Param:     void
  +    * Return:    $indent_str     string
  +    * Throws:    none
  +    * Since:     0.01
  +
  +This subroutine returns the $indent_str string which should be printed
  +before all debug lines if you wish to line the debug output up with the
  +nested/indented trace output.
  +
  +=cut
  +
  +sub debug_indent {
  +    my $text = ("| " x $calldepth) . "  * ";
  +    return($text);
  +}
  +
   =head1 ACKNOWLEDGEMENTS
   
    * Author:  Stephen Adkins <[EMAIL PROTECTED]>
  
  
  

Reply via email to