File Coverage

blib/lib/Carp/Patch/Config.pm
Criterion Covered Total %
statement 23 48 47.9
branch 0 14 0.0
condition 0 15 0.0
subroutine 8 11 72.7
pod 0 1 0.0
total 31 89 34.8


line stmt bran cond sub pod time code
1             package Carp::Patch::Config;
2              
3 1     1   433795 use 5.010001;
  1         5  
4 1     1   6 use strict;
  1         2  
  1         30  
5 1     1   9 no warnings;
  1         3  
  1         69  
6              
7 1     1   715 use Module::Patch qw();
  1         27484  
  1         48  
8 1     1   10 use base qw(Module::Patch);
  1         2  
  1         302  
9              
10             our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
11             our $DATE = '2024-02-16'; # DATE
12             our $DIST = 'Carp-Patch-Config'; # DIST
13             our $VERSION = '0.008'; # VERSION
14              
15             my @oldvals;
16             our %config;
17              
18             sub patch_data {
19             return {
20             v => 3,
21             patches => [
22             ],
23             config => {
24             -MaxArgLen => {
25             schema => 'int*',
26             },
27             -MaxArgNums => {
28             schema => 'int*',
29             },
30             -Dump => {
31             schema => 'str*',
32             description => <<'_',
33              
34             This is not an actual configuration for Carp, but a shortcut for:
35              
36             # when value is 0 or 'none'
37             $Carp::RefArgFormatter = undef;
38              
39             # when value is 1 or 'Data::Dmp'
40             $Carp::RefArgFormatter = sub {
41             require Data::Dmp;
42             Data::Dmp::dmp($_[0]);
43             };
44              
45             # when value is 2 or 'Data::Dump'
46             $Carp::RefArgFormatter = sub {
47             require Data::Dump;
48             Data::Dump::dump($_[0]);
49             };
50              
51             # when value is 3 or 'Data::Dump::ObjectAsString'
52             $Carp::RefArgFormatter = sub {
53             require Data::Dump::ObjectAsString;
54             Data::Dump::ObjectAsString::dump($_[0]);
55             };
56              
57             # when value is 4 or 'Data::Dump::IfSmall'
58             $Carp::RefArgFormatter = sub {
59             require Data::Dump::IfSmall;
60             Data::Dump::IfSmall::dump($_[0]);
61             };
62              
63             _
64             },
65             },
66             after_patch => sub {
67 1     1   9 no strict 'refs'; ## no critic: TestingAndDebugging::ProhibitNoStrict
  1         2  
  1         45  
68 1     1   6 no warnings 'numeric';
  1         3  
  1         638  
69 0     0     my $oldvals = {};
70 0           for my $name (keys %config) {
71 0           (my $carp_config_name = $name) =~ s/\A-//;
72 0           my $carp_config_val = $config{$name};
73 0 0         if ($name =~ /\A-?Dump\z/) {
74 0           $carp_config_name = 'RefArgFormatter';
75             $carp_config_val =
76             $config{$name} eq '0' || $config{$name} eq 'none' ? undef :
77 0           $config{$name} == 1 || $config{$name} eq 'Data::Dmp' ? sub { require Data::Dmp ; Data::Dmp::dmp ($_[0]) } :
  0            
78 0           $config{$name} == 2 || $config{$name} eq 'Data::Dump' ? sub { require Data::Dump; Data::Dump::dump($_[0]) } :
  0            
79 0           $config{$name} == 3 || $config{$name} eq 'Data::Dump::ObjectAsString' ? sub { require Data::Dump::ObjectAsString; Data::Dump::ObjectAsString::dump($_[0]) } :
  0            
80 0           $config{$name} == 4 || $config{$name} eq 'Data::Dump::IfSmall' ? sub { require Data::Dump::IfSmall; Data::Dump::IfSmall::dump($_[0]) } :
  0            
81 0 0 0       die "Unknown value for -Dump, please choose 0/none, 1/Data::Dmp, 2/Data::Dump, 3/Data::Dump::ObjectAsString, 4/Data::Dump::IfSmall";
    0 0        
    0 0        
    0 0        
    0 0        
82             }
83 0           $oldvals->{$carp_config_name} = ${"Carp::$carp_config_name"};
  0            
84 0           ${"Carp::$carp_config_name"} = $carp_config_val;
  0            
85             }
86 0           push @oldvals, $oldvals;
87             },
88             after_unpatch => sub {
89 1     1   12 no strict 'refs'; ## no critic: TestingAndDebugging::ProhibitNoStrict
  1         2  
  1         162  
90 0 0   0     my $oldvals = shift @oldvals or return;
91 0           for (keys %$oldvals) {
92 0           ${"Carp::$_"} = $oldvals->{$_};
  0            
93             }
94             },
95 0     0 0   };
96             }
97              
98             1;
99             # ABSTRACT: Set some Carp variables
100              
101             __END__