#!perl # THIS IS A WORK IN PROGRESS # IT SHOULD BE CONSIDERED ALPHA # BUT I EXPECT IT TO IMPROVE # THIS IS A RE-IMPLEMENTATION OF PREVIOUS CODE THAT WAS WRITTEN # ON-THE-FLY AS NEEDED. use strict; use warnings; use Test::More; use Data::Dumper; use Smart::Comments; our $VERSION = 0.04; my $IS_CPAN_VERSION = 1; BEGIN { ### - ### ----------- ### - ### TESTS BEGIN ### - ### ----------- ### - use_ok ( 'File::Copy' ); use_ok ( 'Carp' ); use_ok ( 'Debug::Xray', qw( start_sub end_sub dprint set_debug_verbose watch_subs add_watch_var errorHandler warnHandler is_carp_debug debug_warn_handling default_warn_handling debug_error_handling default_error_handling ) ) or die 'Can\'t use Debug::Xray'; use_ok ( 'IO::CaptureOutput', qw(capture capture_exec) ); #use_ok ( 'Debug::Xray::WatchScalar' ) or die 'Can\t use Debug::Xray::WatchScalar'; use_ok ( 'PadWalker', qw(var_name) ) or die 'Can\'t use PadWalker'; }; ### Validate my module construction by trying out skeletal modules if (!$IS_CPAN_VERSION) { use_ok ( 'Minimal', qw(i_am_here) ) or die 'Something wrong with module access'; # Can I even use a module in this directory? use_ok ( 'Minimal2::Minimal3', qw(i_am_here_3) ) or die 'Something wrong with module access'; # Can I even use a module in this directory? can_ok ( 'Minimal' , 'i_am_here' ) or die 'Something wrong with module access - exiting'; can_ok ( 'main' , 'i_am_here' ) or die 'Something wrong with module access - exiting'; is ( Minimal::i_am_here() , 'I am here' ) or die 'Something wrong with module access - exiting'; is ( i_am_here() , 'I am here' ) or die 'Something wrong with module access - exiting'; can_ok ( 'Minimal2::Minimal3' , 'i_am_here_3' ) or die 'Something wrong with module access - exiting'; can_ok ( 'main' , 'i_am_here_3' ) or die 'Something wrong with module access - exiting'; is ( Minimal2::Minimal3::i_am_here_3() , 'I am here 3' ) or die 'Something wrong with module access - exiting'; is ( i_am_here_3() , 'I am here 3' ) or die 'Something wrong with module access - exiting'; ### Minimal module tests passed } ### Validate subroutine access... { can_ok ('Debug::Xray', 'start_sub' ) or die 'Can\'t start_sub - exiting'; can_ok ('main', 'start_sub' ) or die 'Can\'t start_sub - exiting'; can_ok ('Debug::Xray', 'set_debug_verbose' ) or die 'Can\'t set_debug_verbose - exiting'; can_ok ('main', 'set_debug_verbose' ) or die 'Can\'t set_debug_verbose - exiting'; can_ok ('Debug::Xray', 'dprint' ) or die 'Can\'t dprint - exiting'; can_ok ('main', 'dprint' ) or die 'Can\'t dprint - exiting'; } ### Die if Debug is not configured to run this script... { is ( Debug::Xray::is_verbose() , 1 , 'Debug::Xray is verbose' ) or die 'Debug::Xray must be verbose'; is ( Debug::Xray::dprint('this is a test'), 'this is a test', 'Debug::Xray::dprint ok' ) or die 'Can\t dprint'; is ( Debug::Xray::dprint('this is a test'), 'this is a test', 'Debug::Xray::dprint ok' ) or die 'Can\t dprint'; ok ( is_carp_debug, 'Carp::Assert on' ) or die 'Carp::Assert must be turned on in Xray to run tests'; } ### Test Hooks... { { my $expected_sub_1_output = <new(); # or my $stack = caller_stack(); # Get all callers my @callers = $stack->all_list(); # Limit to specific callers: $stack->filter( 'line', 100 ); $stack->filter( 'subroutine', qr/mysub$/ ); $stack->filter( 'package', 'My::Package' ); #my @specific_callers = $stack->filtered_list() while ( my $level = $stack->next ) { warn $level; } } ### End of test script... done_testing(); sub sub_1 { start_sub(); dprint ('this is sub 1'); sub_2(); end_sub(); } sub sub_2 { start_sub(); dprint ('this is sub 2'); sub_3(); end_sub(); } sub sub_3 { start_sub(); dprint ('this is sub 3'); end_sub(); } sub sub_4 { start_sub(); dprint ('this is sub 4'); end_sub(); } sub sub_10 { dprint ('this is sub 10'); sub_20(); } sub sub_20 { dprint ('this is sub 20'); sub_30(); } sub sub_30 { dprint ('this is sub 30'); sub_40(); } sub sub_40 { } =pod CHANGE LOG =============================== Version 0.03 ------------ 12/17/2011 : Streamlined watch_vars to only take a reference to a scalar and figure out the variable name from that. (Need to implement on arrays and hashes.) : More consistent naming. Routines with the word 'hook' in the name are changed to 'watch' to be more consistent with the watch variables routines. Version 0.04 ------------ 12/18/2011 : Fixed signal trapping so it could be turned off and on. It passes tests, but needs a better workout. =cut