File Coverage

blib/lib/Acme/AtIncPolice.pm
Criterion Covered Total %
statement 66 86 76.7
branch 24 60 40.0
condition 3 26 11.5
subroutine 9 9 100.0
pod n/a
total 102 181 56.3


line stmt bran cond sub pod time code
1             package Acme::AtIncPolice;
2 2     2   72369 use 5.008001;
  2         18  
3 2     2   11 use strict;
  2         3  
  2         38  
4 2     2   8 use warnings;
  2         4  
  2         42  
5 2     2   10 use Carp;
  2         2  
  2         183  
6              
7             our $VERSION = "0.02";
8              
9             BEGIN {
10 2     2   1023 use Tie::Trace qw/watch/;
  2         34251  
  2         123  
11 2     2   14 no warnings 'redefine';
  2         4  
  2         2139  
12              
13             *Tie::Trace::_output_message = sub {
14 2     2   7 my ($self, $class, $value, $args) = @_;
15 2 100       5 if (!$value) {
16 1         3 return;
17             }
18              
19 1         3 my ($msg, @msg) = ('');
20              
21 1         2 my $caller = $self->{options}->{caller};
22 1         1 my $_caller_n = 1;
23 1         14 while (my $c = (caller $_caller_n)[0]) {
24 3 50       122 if (not $c) {
    100          
25 0         0 last;
26             } elsif ($c !~ /^Tie::Trace/) {
27 1         2 last;
28             }
29 2         7 $_caller_n++;
30             }
31              
32 1 50       6 my @caller = map $_ + $_caller_n, ref $caller ? @{$caller} : $caller;
  0         0  
33 1         2 my(@filename, @line);
34 1         3 foreach(@caller){
35 1         11 my($f, $l) = (caller($_))[1, 2];
36 1 50 33     44 next unless $f and $l;
37              
38 1         3 push @filename, $f;
39 1         2 push @line, $l;
40              
41             }
42              
43 1 50       6 my $location = @line == 1 ? " at $filename[0] line $line[0]." :
44             join "\n", map " at $filename[$_] line $line[$_].", (0 .. $#filename);
45 1         6 my($_p, $p) = ($self, $self->parent);
46 1         9 while($p){
47 0         0 my $s_type = ref $p->{storage};
48 0         0 my $s = $p->{storage};
49 0 0       0 if($s_type eq 'HASH'){
    0          
50 0         0 push @msg, "{$_p->{__key}}";
51             }elsif($s_type eq 'ARRAY'){
52 0         0 push @msg, "[$_p->{__point}]";
53             }
54 0         0 $_p = $p;
55 0 0 0     0 last if ! ref $p or ! ($p = $p->parent);
56             }
57 1 50       5 $msg = @msg > 0 ? ' => ' . join "", reverse @msg : "";
58              
59              
60 1 50       3 $value = '' unless defined $value;
61 1 50       4 if ($class eq 'Scalar') {
    50          
    0          
62 0         0 return("${msg} => $value$location");
63             } elsif ($class eq 'Array') {
64 1 50       4 unless(defined $args->{point}){
65 1         2 $msg =~ s/^( => )(.+)$/$1\@\{$2\}/;
66 1         5 return("$msg => $value$location");
67             }else{
68 0         0 return("${msg}[$args->{point}] => $value$location");
69             }
70             } elsif ($class eq 'Hash') {
71 0 0 0     0 return("${msg}" . (! $self->{options}->{pkg} || @msg ? "" : " => "). "{$args->{key}} => $value$location");
72             }
73 2     2   131 };
74              
75              
76             *Tie::Trace::_carpit = sub {
77 2     2   1064 my ($self, %args) = @_;
78 2 50       7 return if $Tie::Trace::QUIET;
79            
80 2         9 my $class = (split /::/, ref $self)[2];
81 2   50     7 my $op = $self->{options} || {};
82            
83             # key/value checking
84 2 50 33     11 if ($op->{key} or $op->{value}) {
85 0         0 my $key = $self->_matching($self->{options}->{key}, $args{key});
86 0         0 my $value = $self->_matching($self->{options}->{value}, $args{value});
87 0 0 0     0 if (($args{key} and $op->{key}) and $op->{value}) {
    0 0        
    0 0        
88 0 0 0     0 return unless $key or $value;
89             } elsif($args{key} and $op->{key}) {
90 0 0       0 return unless $key;
91             } elsif($op->{value}) {
92 0 0       0 return unless $value;
93             }
94             }
95            
96             # debug type
97 2         9 my $value = $self->_debug_message($args{value}, $op->{debug}, $args{filter});
98             # debug_value checking
99 2 50       16 return unless $self->_matching($self->{options}->{debug_value}, $value);
100             # use scalar/array/hash ?
101 2 50       18 return unless grep lc($class) eq lc($_) , @{$op->{use}};
  2         12  
102             # create warning message
103 2         6 my $watch_msg = '';
104 2         16 my $msg = $self->_output_message($class, $value, \%args);
105 2 50       8 if(defined $self->{options}->{pkg}){
106 0         0 $watch_msg = sprintf("%s:: %s", @{$self->{options}}{qw/pkg var/});
  0         0  
107             } else {
108 2 100       9 $msg =~ s/^ => // if $msg;
109             }
110 2 100       6 if ($msg) {
111 1         16 croak $watch_msg . $msg . "\n";
112             }
113 2         62 };
114              
115             watch @INC, (
116             debug => sub {
117 2         17 my ($self, $things) = @_;
118 2         4 for my $thing (@$things) {
119 2         5 my $ref = ref($thing);
120 2 100       7 if ($ref) {
121 1         3 return "Acme::AtIncPolice does not allow contamination of \@INC";
122             }
123             }
124             },
125 2         16 r => 0,
126             );
127             };
128              
129              
130             1;
131             __END__