Handy.pm

filter: Statementstmt 46.1% 36 / 78 Branchbran 0.0% 0 / 14 Conditioncond 0.0% 0 / 7 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 52.3% 11 / 21 Podpod 100% 6 / 6 totaltotal 40.7% 53 / 130 SCAR 38.9
CC
12
Cov
36%
features
110.0
__ANON__
6.0
_generate_xtags
3.5
CRAP 49.1
« Handy/Util.pm ↑ Summary
1 package Exporter::Handy;
2  
3 2 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
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 # ABSTRACT: An EXPERIMENTAL subclass of <Exporter::Extensible>, which helps create easy-to-extend modules that export symbols
8 2 our $VERSION = '1.000002';
9  
10 2 ▶use Exporter::Extensible -exporter_setup => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 # Generators for exported functions
13 sub _generate_xtags : Export(=xtags) {
14 0 ▶ require Exporter::Handy::Util;
Subroutine _generate_xtags: not called CC=2 SCAR=12.6
15 0 my ($exporter, $symbol, $opts) = @_;
16 0 ▶ my %opts = ( sig => ':', %{; $opts // {} } );
Condition0%0/2
$opts // {}
l!l
00
MC/DC0%0/1
$opts // {}
$opts
Truth table0%0/2
A
A= $opts
Aresult
11
00
17 0 ▶ sub {; Exporter::Handy::Util::xtags_( \%opts, @_ ) } # curried
Subroutine __ANON__: not called CC=1 SCAR=6.9
18 2 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.2
19  
20 sub _generate_expand_xtags : Export(=expand_xtags) {
21 0 ▶ require Exporter::Handy::Util;
Subroutine _generate_expand_xtags: not called CC=1 SCAR=2.6
22 0 my ($exporter, $symbol, $opts) = @_;
23 0 ▶ sub {; Exporter::Handy::Util::expand_xtags_(@_, $opts // { }) } # curried
Subroutine __ANON__: not called CC=2 SCAR=17.9
Condition0%0/2
$opts // {}
l!l
00
MC/DC0%0/1
$opts // {}
$opts
Truth table0%0/2
A
A= $opts
Aresult
11
00
24 2 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.2
25  
26  
27 # PRAGMATA
28 # Remember: Pragmas effect the current compilation context.
29 # No need to keep track of where we are importing into...
30 # They require their ->import() method to be called directly, no matter how deep the call stack happens to be.
31 # Just call ->import() directly, like below, and it will do the right thing.
32 2 ▶sub strict : Export(-) { strict->import }
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine strict: not called CC=1 SCAR=0.2
Pod documented
33 2 ▶sub warnings : Export(-) { warnings->import }
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine warnings: not called CC=1 SCAR=0.2
Pod documented
34 2 ▶sub utf8 : Export(-) { utf8->import }
Subroutine BEGIN: called CC=1 SCAR=0.2
Subroutine utf8: not called CC=1 SCAR=0.2
Pod documented
35  
36 sub strictures : Export(-) {
37 0 ▶ strict->import;
Subroutine strictures: not called CC=1 SCAR=6.9
Pod documented
38 0 warnings->import
39 2 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
40  
41 sub sane : Export(-) {
42 0 ▶ utf8->import;
Subroutine sane: not called CC=1 SCAR=6.9
Pod documented
43 0 strict->import;
44 0 warnings->import;
45 2 ▶}
Subroutine BEGIN: called CC=1 SCAR=0.0
46  
47  
48 # use Exporter::Handy qw(-sane -features), exporter_setup => 1;
49 sub features { # :Export(-?) syntax was not working before version 0.11 of Exporter::Extensible
50 0 ▶ my ($exporter, $arg)= @_;
Subroutine features: not called CC=10 SCAR=47.0
Pod documented
51  
52 # default features to turn on/off
53 0 my %feats = (
54 'current_sub' => 1, # Perl v5.16+ (2012) : enable __SUB__ token that returns a ref to the current subroutine (or undef).
55 'evalbytes' => 1, # Perl v5.16+ (2012) : like string eval, but it treats its argument as a byte string.
56 'fc' => 1, # Perl v5.16+ (2012) : enable the fc function (Unicode casefolding).
57 'lexical_subs' => 1, # Perl v5.18+ (2012) : enable declaration of subroutines via my sub foo, state sub foo and our sub foo syntax.
58 'say' => 1, # Perl v5.10+ (2007) : enable the Raku-inspired "say" function.
59 'state' => 1, # Perl v5.10+ (2007) : enable state variables.
60 'unicode_eval' => 1, # Perl v5.16+ (2012) : changes the behavior of plain string eval to work more consistently, especially in the Unicode world.
61 'unicode_strings' => 1, # Perl v5.12+ (2010) : use Unicode rules in all string operations (unless either use locale or use bytes are also within the scope).
62 );
63  
64 0 my @args = eval { @$arg }; # if $arg is an ARRAY-ref, than it denotes a list of features
65 0 my %args = eval { %$arg }; # if $arg is a HASH-ref, then it denotes individual overrides (1: on, 0:off)
66  
67 0 ▶ if (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 0 0 0
68 0 ▶ if ($args[0] eq '+') { # request to keep defaults.
Branch: 1 branch
BranchTrueFalseTotal
if ($args[0] eq '+') { } 0 0 0
69 0 shift @args;
70 0 %args = map { $_ => 1 } @args;
71 } else { # replace defaults
72 0 %feats = map { $_ => 1 } @args;
73 }
74 }
75  
76 # handle individual overrides
77 0 %feats = (%feats, %args);
78  
79 0 ▶ return unless %feats;
Branch: 1 branch
BranchTrueFalseTotal
unless %feats 0 0 0
80  
81 # determine features to be turned ON or OFF
82 0 my (@on, @off);
83 0 for (keys %feats) {
84 0 ▶ next if m/^-/; # ignore inline args à la <Exporter::Extensible>, if any: -prefix, -as, ...
Branch: 1 branch
BranchTrueFalseTotal
if /^-/ 0 0 0
85  
86 0 ▶ if (defined $feats{$_} && $feats{$_}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $feats{$_} and $feats{$_}) { } 0 0 0
Condition0%0/3
defined $feats{$_} and $feats{$_}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $feats{$_} and $feats{$_}
defined $feats{$_} $feats{$_}
Truth table0%0/3
A and B
A= defined $feats{$_}B= $feats{$_}
ABresult
0X0
100
111
87 0 push @on, $_;
88 } else {
89 0 push @off, $_;
90 }
91 }
92  
93 # Do the actual work
94 0 require feature;
95 0 ▶ feature->import(@on) if @on;
Branch: 1 branch
BranchTrueFalseTotal
if @on 0 0 0
96 0 ▶ feature->unimport(@off) if @off;
Branch: 1 branch
BranchTrueFalseTotal
if @off 0 0 0
97 }
98 2 __PACKAGE__->exporter_register_option('features', \&features, '?');
99  
100 2 1;
101  
102 __END__
« Handy/Util.pm ↑ Summary