File Coverage

blib/lib/namespace/clean/_Util.pm
Criterion Covered Total %
statement 16 16 100.0
branch n/a
condition 1 3 33.3
subroutine 6 6 100.0
pod n/a
total 23 25 92.0


line stmt bran cond sub pod time code
1             ### !!!ACHTUNG!!!
2             #
3             # This module is to be loaded at configure time straight from the Makefile.PL
4             # in order to get access to some of the constants / utils
5             # None of the dependencies will be available yet at this point, so make
6             # sure to never use anything beyond what the minimum supported perl came with
7             # (no, relying on configure_requires is not ok)
8              
9             package # hide from the pauses
10             namespace::clean::_Util;
11              
12 11     11   57 use warnings;
  11         17  
  11         324  
13 11     11   55 use strict;
  11         20  
  11         287  
14              
15 11     11   56 use base 'Exporter';
  11         47  
  11         1206  
16             our @EXPORT_OK = qw( DEBUGGER_NEEDS_CV_RENAME DEBUGGER_NEEDS_CV_PIVOT );
17              
18 11   33 11   60 use constant DEBUGGER_NEEDS_CV_RENAME => ( ( $] > 5.008_008 ) and ( $] < 5.013_006 ) );
  11         77  
  11         1071  
19 11     11   65 use constant DEBUGGER_NEEDS_CV_PIVOT => ( ( ! DEBUGGER_NEEDS_CV_RENAME ) and ( $] < 5.015_005 ) );
  11         29  
  11         958  
20              
21             # FIXME - ideally this needs to be provided by some abstraction lib
22             # but we don't have that yet
23             BEGIN {
24 11     11   224 DEBUGGER_NEEDS_CV_RENAME and ( eval <<'EOS' or die $@ );
25             {
26             my( $sub_name_loaded, $sub_util_loaded );
27              
28             sub _namer_load_error {
29             my $err = '';
30              
31             return $err if $sub_util_loaded or $sub_name_loaded;
32              
33             local $@;
34              
35             # prefer Sub::Name to Sub::Util
36             # this is rather arbitrary but remember this code exists only
37             # on perls 5.8.9 ~ 5.13.5
38              
39             # when changing version also change in Makefile.PL
40             my $sn_ver = 0.04;
41              
42             eval {
43             require Sub::Name;
44             Sub::Name->VERSION($sn_ver);
45             $sub_name_loaded = 1;
46             }
47             or
48             eval {
49             require Sub::Util;
50             $sub_util_loaded = 1;
51             }
52             or
53             $err = "When running under -d on this perl $], namespace::clean requires either Sub::Name $sn_ver or Sub::Util to be installed"
54             ;
55              
56             $err;
57             }
58              
59             sub set_subname {
60             if( my $err = _namer_load_error() ) {
61             die $err;
62             }
63             elsif( $sub_name_loaded ) {
64             &Sub::Name::subname;
65             }
66             elsif( $sub_util_loaded ) {
67             &Sub::Util::set_subname;
68             }
69             else {
70             die "How the fuck did we get here? Read source and debug please!";
71             }
72             }
73              
74             sub get_subname {
75             if(
76             _namer_load_error()
77             or
78             ! $sub_util_loaded
79             ) {
80             require B;
81             my $gv = B::svref_2object( $_[0] )->GV;
82             join '::', $gv->STASH->NAME, $gv->NAME;
83             }
84             else {
85             &Sub::Util::subname;
86             }
87             }
88             }
89             1;
90             EOS
91              
92             }
93              
94             1;