Data/Printer/Scoped.pm

filter: Statementstmt 72.4% 21 / 29 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 63.6% 7 / 11 Podpod n/a totaltotal 70.0% 28 / 40 CC 1 SCAR 3.1
CC
1
Cov
72%
import
2.0
scope
2.0
__ANON__
2.0
CRAP 1.4
↑ Summary DDP/S.pm »
1 package Data::Printer::Scoped;
2 # ABSTRACT: silence Data::Printer except in a controlled scope
3 $Data::Printer::Scoped::VERSION = '0.001004';
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 2 ▶use Data::Printer ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8 2 ▶use Import::Into;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use Context::Preserve;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use Class::Method::Modifiers qw(:all);
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 ▶use base qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 our @EXPORT = qw(scope);
15  
16 our $enabled = 0;
17  
18 install_modifier('Data::Printer', 'around', '_print_and_return', sub {
19 my $orig = shift;
20  
21 # noop unless enabled.
22 return $enabled ? $orig->(@_) : ();
23 });
24  
25 0 ▶sub import {
Subroutine import: not called CC=1 SCAR=6.9
26 0 shift->export_to_level(1);
27 0 Data::Printer->import::into(1);
28 }
29  
30 # we only blanket disable Data::Printer if a scope() call has been made.
31 0 ▶sub scope(&) {
Subroutine scope: not called CC=1 SCAR=6.9
32 0 my ($code) = @_;
33  
34 0 $enabled = 0;
35  
36 0 ▶ return preserve_context { $enabled = 1; $code->() }
Subroutine __ANON__: not called CC=1 SCAR=6.9
37 0 ▶ after => sub { $enabled = 0 };
Subroutine __ANON__: not called CC=1 SCAR=6.9
38 }
39  
40 1;
41  
42 __END__
↑ Summary DDP/S.pm »