blib/lib/Function/Fallback/CoreOrPP.pm

filter: Statementstmt 66.0% 37 / 56 Branchbran 50.0% 13 / 26 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 77.7% 7 / 9 Podpod 100% 4 / 4 totaltotal 64.2% 61 / 95 CC 15 SCAR 18.3
CC
15
Cov
61%
clone
12.0
_unbless_fallback
7.2
uniq
7.1
CRAP 6.3
↑ Summary
1 package Function::Fallback::CoreOrPP;
2  
3 2 our $AUTHORITY = 'cpan:PERLANCAR'; # AUTHORITY
4 2 our $DATE = '2020-02-03'; # DATE
5 2 our $DIST = 'Function-Fallback-CoreOrPP'; # DIST
6 2 our $VERSION = '0.090'; # VERSION
7  
8 2 ▶use 5.010001;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 2 our $USE_NONCORE_XS_FIRST = 1;
13  
14 2 require Exporter;
15 2 our @ISA = qw(Exporter);
16 2 our @EXPORT_OK = qw(
17 clone
18 clone_list
19 unbless
20 uniq
21 );
22  
23 0 ▶sub clone {
Subroutine clone: not called CC=3 SCAR=24.8
Pod documented
24 0 my $data = shift;
25 0 ▶ goto FALLBACK unless $USE_NONCORE_XS_FIRST;
Branch: 1 branch
BranchTrueFalseTotal
unless $Function::Fallback::CoreOrPP::USE_NONCORE_XS_FIRST 0 0 0
26 0 ▶ goto FALLBACK unless eval { require Data::Clone; 1 };
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { require Data::Clone; 1 } } 0 0 0
27  
28 0 STANDARD:
29 return Data::Clone::clone($data);
30  
31 0 FALLBACK:
32 require Clone::PP;
33 0 return Clone::PP::clone($data);
34 }
35  
36 0 ▶sub clone_list {
Subroutine clone_list: not called CC=1 SCAR=6.9
Pod documented
37 0 map { clone($_) } @_;
38 }
39  
40 4 ▶sub _unbless_fallback {
Subroutine _unbless_fallback: called CC=7 SCAR=19.8
41 4 my $ref = shift;
42  
43 4 my $r = ref($ref);
44 # not a reference
45 4 ▶ return $ref unless $r;
Branch: 1 branch
BranchTrueFalseTotal
unless $r 0 4 4
46  
47 # return if not a blessed ref
48 4 ▶ my ($r2, $r3) = "$ref" =~ /(.+)=(.+?)\(/
Branch: 1 branch
BranchTrueFalseTotal
() = "$ref" =~ /(.+)=(.+?)\(/ or return $ref 4 0 4
49 or return $ref;
50  
51 4 ▶ if ($r3 eq 'HASH') {
Branch: 4 branches
BranchTrueFalseTotal
if ($r3 eq 'HASH') { } 1 3 4
elsif ($r3 eq 'ARRAY') { } 1 2 3
elsif ($r3 eq 'SCALAR') { } 1 1 2
elsif ($r3 eq 'CODE') { } 1 0 1
52 1 return { %$ref };
53 } elsif ($r3 eq 'ARRAY') {
54 1 return [ @$ref ];
55 } elsif ($r3 eq 'SCALAR') {
56 1 return \( my $copy = ${$ref} );
57 } elsif ($r3 eq 'CODE') {
58 1 ▶ return sub { goto &$ref };
Subroutine __ANON__: called CC=1 SCAR=0.0
59 } else {
60 0 die "Can't handle $ref";
61 }
62 }
63  
64 4 ▶sub unbless {
Subroutine unbless: called CC=3 SCAR=16.7
Pod documented
65 4 my $ref = shift;
66  
67 4 ▶ goto FALLBACK unless $USE_NONCORE_XS_FIRST;
Branch: 1 branch
BranchTrueFalseTotal
unless $Function::Fallback::CoreOrPP::USE_NONCORE_XS_FIRST 4 0 4
68 0 ▶ goto FALLBACK unless eval { require Acme::Damn; 1 };
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { require Acme::Damn; 1 } } 0 0 0
69  
70 0 STANDARD:
71 return Acme::Damn::damn($ref);
72  
73 4 FALLBACK:
74 return _unbless_fallback($ref);
75 }
76  
77 1 ▶sub uniq {
Subroutine uniq: called CC=5 SCAR=19.6
Pod documented
78 1 ▶ goto FALLBACK unless $USE_NONCORE_XS_FIRST;
Branch: 1 branch
BranchTrueFalseTotal
unless $Function::Fallback::CoreOrPP::USE_NONCORE_XS_FIRST 1 0 1
79 0 ▶ goto FALLBACK unless eval { require List::MoreUtils; 1 };
Branch: 1 branch
BranchTrueFalseTotal
unless eval { do { require List::MoreUtils; 1 } } 0 0 0
80  
81 0 STANDARD:
82 return List::MoreUtils::uniq(@_);
83  
84 1 FALLBACK:
85 my %h;
86 1 my @res;
87 1 for (@_) {
88 6 ▶ push @res, $_ unless $h{$_}++;
Branch: 1 branch
BranchTrueFalseTotal
unless $h{$_}++ 4 2 6
89 }
90 1 return @res;
91 }
92  
93 2 1;
94 # ABSTRACT: Functions that use non-core XS module but provide pure-Perl/core fallback
95  
96 __END__
↑ Summary