blib/lib/Devel/DebugHooks/KillPrint.pm untested

filter: Statementstmt 0.0% 0 / 35 Branchbran 0.0% 0 / 10 Conditioncond 0.0% 0 / 8 MC/DCmcdc n/a Subroutinesub 0.0% 0 / 7 Podpod 0.0% 0 / 5 totaltotal 0.0% 0 / 65 CC 6 SCAR 22.3
CC
6
Cov
0%
filter
20.0
trace_load
6.0
import
6.0
CRAP 9.3
1 package Devel::DebugHooks::KillPrint;
2  
3  
4  
5 my $actions = {};
6 my @profiles = ();
7  
8  
9 #FIX: Do this after script is compiled. Look for some hook...
10 sub trace_load {
11 if( $_[1] eq "*main::_<$0" ) { #<-- This is tricky
12 while( my( $key, $value ) = each %$actions ) {
13 #TODO: call process here
14 $DB::commands->{ a }->( "$key $value" );
15 }
16 }
17 }
18  
19  
20  
21 use Devel::DebugHooks();
22 BEGIN{
23 push @ISA, 'Devel::DebugHooks';
24 my $handler = DB::reg( 'trace_load', 'kill_print' );
25 $$handler->{ context } = $DB::dbg;
26 $$handler->{ code } = $DB::dbg->can( 'trace_load' );
27 }
28 use Filter::Util::Call;
29  
30  
31  
32 sub import {
33 # Pay attention to $actions, because it is module global
34 # We do not expect here that we would be used twice or more times!
35 filter_add( bless $actions );
36  
37 my $class = shift;
38  
39 while( @_ && $_[0] ne '--' ) {
40 push @profiles, shift;
41 }
42  
43 shift if @_; # Remove '--'. Here the @_ exists only if '--' was supplied
44  
45 $class->SUPER::import( @_ );
46 }
47  
48  
49  
50 sub filter {
51 my( $self ) = @_;
52  
53 my $status;
54 if( ( $status = filter_read() ) > 0 ) {
55  
56 if( /#DBG:(\w*) (.*) #$/ ) {
57 my $profile = $1 || 'default';
58 if( !@profiles || grep{ $_ eq $profile } @profiles ) {
59 my( $file, $line ) = (caller 0)[1,2];
60 $self->{ "$file:$line" } = $2;
61  
62 s/^(\s*)(#DBG:\w* .* #)$/${1}1; $2/;
63 }
64 }
65 }
66  
67 $status;
68 }
69  
70  
71 sub Devel::DebugHooks::Commands::interact { 0 }
72  
73 1;