blib/lib/PMLTQ/Base.pm

filter: Statementstmt 98.2% 55 / 56 Branchbran 90.0% 9 / 10 Conditioncond 33.3% 2 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 86.6% 13 / 15 Podpod n/a totaltotal 86.8% 79 / 91 CC 9 SCAR 12.6
CC
9
Cov
92%
import
8.0
_monkey_patch
2.0
__ANON__
1.1
CRAP 3.5
« blib/lib/PMLTQ/Command/delete.pm ↑ Summary blib/lib/PMLTQ/Command/initdb.pm »
1 package PMLTQ::Base;
2 28 our $AUTHORITY = 'cpan:MATY';
3 28 $PMLTQ::Base::VERSION = '1.2.2';
4 # ABSTRACT: Base class for PMLTQ inspired by L<Mojo::Base> and L<Mojo::Base::XS>
5  
6 35 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 35 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 35 ▶use utf8;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 35 ▶use feature ();
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 # Only Perl 5.14+ requires it on demand
12 35 ▶use IO::Handle ();
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 # Supported on Perl 5.22+
15 my $NAME
16 0 ▶ = eval { require Sub::Util; Sub::Util->can('set_subname') } || sub { $_[1] };
Subroutine __ANON__: not called CC=1 SCAR=0.8
Condition33%1/3
eval { do { require Sub::Util; 'Sub::Util'->can('set_subname') } } || sub { $_[1]; }
l!l&&r!l&&!r
2800
MC/DC0%0/2
eval { do { require Sub::Util; 'Sub::Util'->can('set_subname') } } || sub { $_[1]; }
eval { do { require Sub::Util; 'Sub::Util'->can('set_subname') } } sub { $_[1]; }
Truth table33%1/3
A || B
A= eval { do { require Sub::Util; 'Sub::Util'->can('set_subname') } }B= sub { $_[1]; }
ABresult
1X1
011
000
17  
18 # Protect subclasses using AUTOLOAD
19 ▶sub DESTROY { }
Subroutine DESTROY: not called CC=1 SCAR=0.0
20  
21 sub _monkey_patch {
22 17 ▶ my ($class, %patch) = @_;
Subroutine _monkey_patch: called CC=2 SCAR=6.9
23 35 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
24 35 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
25 17 *{"${class}::$_"} = $NAME->("${class}::$_", $patch{$_}) for keys %patch;
26 }
27  
28 28 require Mojo::Base::XS;
29  
30 28 Mojo::Base::XS::newxs_constructor(__PACKAGE__ . '::new');
31 28 Mojo::Base::XS::newxs_attr(__PACKAGE__ . '::attr');
32  
33 sub import {
34 46 ▶ my $class = shift;
Subroutine import: called CC=8 SCAR=20.8
35 46 ▶ return unless my $flag = shift;
Branch: 1 branch
BranchTrueFalseTotal
unless my $flag = shift() 1 45 46
36  
37 # Base
38 45 ▶ if ($flag eq '-base') { $flag = $class }
Branch: 3 branches
BranchTrueFalseTotal
if ($flag eq '-base') { } 9 36 45
elsif ($flag eq '-strict') { } 28 8 36
elsif (my $file = $flag and not $flag->can('new')) { } 8 0 8
39  
40 # Strict
41 28 elsif ($flag eq '-strict') { $flag = undef }
42  
43 # Module
44 ▶ elsif ((my $file = $flag) && !$flag->can('new')) {
Condition33%1/3
my $file = $flag and not $flag->can("new")
!ll&&!rl&&r
008
MC/DC0%0/2
my $file = $flag and not $flag->can("new")
my $file = $flag not $flag->can("new")
Truth table33%1/3
A and not(B)
A= my $file = $flagB= not $flag->can("new")
ABresult
0X0
100
111
45 8 $file =~ s!::|'!/!g;
46 8 require "$file.pm";
47 }
48  
49 # ISA
50 45 ▶ if ($flag) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flag) 17 28 45
51 17 my $caller = caller;
52 35 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
53 35 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
54  
55 17 push @{"${caller}::ISA"}, $flag;
56 17 ▶ _monkey_patch $caller, 'has', sub { attr($caller, @_) };
Subroutine __ANON__: called CC=1 SCAR=0.0
Subroutine has: called CC=1 SCAR=0.0
57 }
58  
59 # PMLTQ modules are strict!
60 45 $_->import for qw(strict warnings utf8);
61 45 feature->import(':5.10');
62 }
63  
64 28 1;
65  
66 __END__
« blib/lib/PMLTQ/Command/delete.pm ↑ Summary blib/lib/PMLTQ/Command/initdb.pm »