File Coverage

blib/lib/Devel/Caller/IgnoreNamespaces.pm
Criterion Covered Total %
statement 20 20 100.0
branch 11 12 91.6
condition 5 5 100.0
subroutine 5 5 100.0
pod 1 1 100.0
total 42 43 97.6


line stmt bran cond sub pod time code
1             package Devel::Caller::IgnoreNamespaces;
2              
3 1     1   5229 use strict;
  1         2  
  1         40  
4 1     1   4 use warnings;
  1         2  
  1         30  
5              
6 1     1   21 use vars qw(@NAMESPACES $VERSION);
  1         1  
  1         241  
7              
8             $VERSION = '1.0';
9              
10 2     2 1 597 sub register { push @NAMESPACES, @_; }
11              
12             *CORE::GLOBAL::caller = sub (;$) {
13 12   100 12   13537 my ($height) = ($_[0]||0);
14 12         16 my $i=1;
15 12         13 my $name_cache;
16 12         14 while (1) {
17 24 100       192 my @caller = CORE::caller($i++) or return;
18 21 100       48 $caller[3] = $name_cache if $name_cache;
19 21 100       31 $name_cache = (grep { $caller[0] eq $_ } @NAMESPACES) # <-- !!!!
  35         115  
20             ? $caller[3]
21             : '';
22 21 100 100     80 next if $name_cache || $height-- != 0;
23 9 100       157 return wantarray ? @_ ? @caller : @caller[0..2] : $caller[0];
    50          
24             }
25             };
26              
27             1;
28              
29             =head1 NAME
30              
31             Devel::Caller::IgnoreNamespaces - make available a magic caller()
32             which can ignore namespaces that you tell it about
33              
34             =head1 SYNOPSIS
35              
36             package Foo::Bar
37              
38             use Devel::Caller::IgnoreNamespaces;
39             Devel::Caller::IgnoreNamespaces::register(__PACKAGE__);
40              
41             =head1 DESCRIPTION
42              
43             If your module should be ignored by caller(), just like Hook::LexWrap
44             is by its magic caller(), then call this module's register() subroutine
45             with its name.
46              
47             =head1 SUBROUTINES
48              
49             =head2 register('packagename', 'anotherpackage', ...)
50              
51             Takes a list of packages that caller() will ignore in future.
52              
53             =head1 BUGS and FEEDBACK
54              
55             Please report any bugs using L. The best bug
56             reports include a file with a test in it that fails with the current
57             code and will pass once the bug is fixed.
58              
59             I welcome feedback, especially constructive criticism, by email.
60              
61             Feature requests are more likely to be accepted if accompanied by a
62             patch and tests.
63              
64             =head1 AUTHORS, COPYRIGHT and LICENCE
65              
66             This module is maintained by David Cantrell Edavid@cantrell.org.ukE
67             and based almost entirely on code by Damian Conway.
68              
69             Copyright 2001-2008 Damian Conway
70              
71             Documentation and tests and some code copyright 2009 David Cantrell
72              
73             You may use, modify and distribute this code under either the Artistic
74             Licence or the GNU GPL version 2. See the ARTISTIC.txt or GPL2.txt files
75             for the full texts of the licences.
76              
77             =cut