File Coverage

blib/lib/Devel/Caller/IgnoreNamespaces.pm
Criterion Covered Total %
statement 27 28 96.4
branch 18 20 90.0
condition 5 5 100.0
subroutine 6 6 100.0
pod 1 1 100.0
total 57 60 95.0


line stmt bran cond sub pod time code
1             package Devel::Caller::IgnoreNamespaces;
2              
3 3     3   6763 use strict;
  3         19  
  3         103  
4 3     3   19 use warnings;
  3         9  
  3         129  
5 3     3   20 no warnings 'redefine';
  3         8  
  3         151  
6              
7 3     3   19 use vars qw(@NAMESPACES $VERSION);
  3         8  
  3         2675  
8              
9             $VERSION = '1.1';
10              
11 2     2 1 582 sub register { push @NAMESPACES, @_; }
12              
13             my $orig_global_caller;
14             if(defined(&CORE::GLOBAL::caller)) {
15             $orig_global_caller = \&CORE::GLOBAL::caller
16             }
17              
18             *CORE::GLOBAL::caller = sub (;$) {
19 122   100 122   87378 my ($height) = ($_[0]||0);
20 122         266 my $i=1;
21 122         216 my $name_cache;
22 122         216 while (1) {
23 677         1208 my @caller;
24             # can't just take a reference to &CORE::caller on perl < 5.16 and put
25             # it in $orig_global_caller, hence the hateful repetition here
26 677 100       1403 if($orig_global_caller) {
27             @caller = $orig_global_caller->() eq 'DB'
28 1 50       3 ? do { package # break this up so PAUSE etc don't whine
    50          
29 0         0 DB; $orig_global_caller->($i++) }
30             : $orig_global_caller->($i++)
31             or return;
32             } else {
33             @caller = CORE::caller() eq 'DB'
34 676 100       4012 ? do { package # break this up so PAUSE etc don't whine
    100          
35 21         97 DB; CORE::caller($i++) }
36             : CORE::caller($i++)
37             or return;
38             }
39 667 100       1742 $caller[3] = $name_cache if $name_cache;
40 667 100       1570 $name_cache = (grep { $caller[0] eq $_ } @NAMESPACES) # <-- !!!!
  37         159  
41             ? $caller[3]
42             : '';
43 667 100 100     2840 next if $name_cache || $height-- != 0;
44 112 100       821 return wantarray ? @_ ? @caller : @caller[0..2] : $caller[0];
    100          
45             }
46             };
47              
48             1;
49              
50             =head1 NAME
51              
52             Devel::Caller::IgnoreNamespaces - make available a magic caller()
53             which can ignore namespaces that you tell it about
54              
55             =head1 SYNOPSIS
56              
57             package Foo::Bar
58              
59             use Devel::Caller::IgnoreNamespaces;
60             Devel::Caller::IgnoreNamespaces::register(__PACKAGE__);
61              
62             =head1 DESCRIPTION
63              
64             If your module should be ignored by caller(), just like Hook::LexWrap
65             is by its magic caller(), then call this module's register() subroutine
66             with its name.
67              
68             =head1 SUBROUTINES
69              
70             =head2 register('packagename', 'anotherpackage', ...)
71              
72             Takes a list of packages that caller() will ignore in future.
73              
74             =head1 BUGS and FEEDBACK
75              
76             Please report any bugs using L. The best bug
77             reports include a file with a test in it that fails with the current
78             code and will pass once the bug is fixed.
79              
80             I welcome feedback, especially constructive criticism, by email.
81              
82             Feature requests are more likely to be accepted if accompanied by a
83             patch and tests.
84              
85             =head1 AUTHORS, COPYRIGHT and LICENCE
86              
87             This module is maintained by David Cantrell Edavid@cantrell.org.ukE
88             and based almost entirely on code by Damian Conway.
89              
90             Copyright 2001-2008 Damian Conway
91              
92             Documentation and tests and some code copyright 2009 David Cantrell
93              
94             You may use, modify and distribute this code under either the Artistic
95             Licence or the GNU GPL version 2. See the ARTISTIC.txt or GPL2.txt files
96             for the full texts of the licences.
97              
98             =cut