Webqq/Base.pm

filter: Statementstmt 76.3% 55 / 72 Branchbran 47.2% 17 / 36 Conditioncond 38.8% 7 / 18 MC/DCmcdc 9.0% 1 / 11 Subroutinesub 63.1% 12 / 19 Podpod 0.0% 0 / 3 totaltotal 57.8% 92 / 159 CC 28 SCAR 25.4
CC
28
Cov
63%
attr
30.1
new
20.0
member
12.0
CRAP 12.7
« Webqq/Plugin/StockInfo.pm ↑ Summary Webqq/Cache.pm »
1 package Mojo::Webqq::Base;
2 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
3 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 1 ▶use feature ();
Subroutine BEGIN: called CC=1 SCAR=0.0
5
6 # No imports because we get subclassed, a lot!
7 1 ▶use Carp ();
Subroutine BEGIN: called CC=1 SCAR=0.0
8
9 # Only Perl 5.14+ requires it on demand
10 1 ▶use IO::Handle ();
Subroutine BEGIN: called CC=1 SCAR=0.0
11
12 # Supported on Perl 5.22+
13 my $NAME
14 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
100
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
15
16 # Protect subclasses using AUTOLOAD
17 0 ▶sub DESTROY { }
Subroutine DESTROY: not called CC=1 SCAR=0.0
18
19 # Declared here to avoid circular require problems in Mojo::Util
20 88 ▶sub _monkey_patch {
Subroutine _monkey_patch: called CC=2 SCAR=6.9
21 88 my ($class, %patch) = @_;
22 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
23 1 ▶ no warnings 'redefine';
Subroutine BEGIN: called CC=1 SCAR=0.0
24 88 *{"${class}::$_"} = $NAME->("${class}::$_", $patch{$_}) for keys %patch;
25 }
26
27 12 ▶sub attr {
Subroutine attr: called CC=11 SCAR=34.0
Pod undocumented
28 12 my ($self, $attrs, $value) = @_;
29 12 ▶ return unless (my $class = ref $self || $self) && $attrs;
Branch: 1 branch
BranchTrueFalseTotal
unless my $class = ref $self || $self and $attrs 0 12 12
Condition33%2/6
my $class = ref $self || $self and $attrs
!ll&&!rl&&r
0012
ref $self || $self
l!l&&r!l&&!r
0120
MC/DC0%0/3
my $class = ref $self || $self and $attrs
ref $self $self $attrs
Truth table20%1/5
A || B and C
A= ref $selfB= $selfC= $attrs
ABCresult
00X0
1X00
0100
1X11
0111
30
31 12 ▶ Carp::croak 'Default has to be a code reference or constant value'
Branch: 1 branch
BranchTrueFalseTotal
if ref $value and ref $value ne "CODE" 0 12 12
Condition66%2/3
ref $value and ref $value ne "CODE"
!ll&&!rl&&r
750
MC/DC0%0/2
ref $value and ref $value ne "CODE"
ref $value ref $value ne "CODE"
Truth table66%2/3
A and B
A= ref $valueB= ref $value ne "CODE"
ABresult
0X0
100
111
32 if ref $value && ref $value ne 'CODE';
33
34 12 ▶ for my $attr (@{ref $attrs eq 'ARRAY' ? $attrs : [$attrs]}) {
Branch: 1 branch
BranchTrueFalseTotal
ref $attrs eq 'ARRAY' ? : 6 6 12
35 80 ▶ Carp::croak qq{Attribute "$attr" invalid} unless $attr =~ /^[a-zA-Z_]\w*$/;
Branch: 1 branch
BranchTrueFalseTotal
unless $attr =~ /^[a-zA-Z_]\w*$/ 0 80 80
36
37 # Very performance sensitive code with lots of micro-optimizations
38 80 ▶ if (ref $value) {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $value) { } 5 75 80
elsif (defined $value) { } 1 74 75
39 0 ▶ _monkey_patch $class, $attr, sub {
Subroutine member: not called CC=3 SCAR=24.8
40 return
41 0 ▶ exists $_[0]{$attr} ? $_[0]{$attr} : ($_[0]{$attr} = $value->($_[0]))
Branch: 2 branches
BranchTrueFalseTotal
if @_ == 1 0 0 0
exists $_[0]{$attr} ? : 0 0 0
42 if @_ == 1;
43 0 $_[0]{$attr} = $_[1];
44 0 $_[0];
45 5 };
46 }
47 elsif (defined $value) {
48 0 ▶ _monkey_patch $class, $attr, sub {
Subroutine __ANON__: not called CC=3 SCAR=24.8
49 0 ▶ return exists $_[0]{$attr} ? $_[0]{$attr} : ($_[0]{$attr} = $value)
Branch: 2 branches
BranchTrueFalseTotal
if @_ == 1 0 0 0
exists $_[0]{$attr} ? : 0 0 0
50 if @_ == 1;
51 0 $_[0]{$attr} = $_[1];
52 0 $_[0];
53 1 };
54 }
55 else {
56 _monkey_patch $class, $attr,
57 0 ▶ sub { return $_[0]{$attr} if @_ == 1; $_[0]{$attr} = $_[1]; $_[0] };
Subroutine max_admin: not called CC=2 SCAR=14.6
Branch: 1 branch
BranchTrueFalseTotal
if @_ == 1 0 0 0
58 }
59 }
60 }
61
62 16 ▶sub import {
Subroutine import: called CC=8 SCAR=21.0
63 16 my $class = shift;
64 16 ▶ return unless my $flag = shift;
Branch: 1 branch
BranchTrueFalseTotal
unless my $flag = shift() 8 8 16
65
66 # Base
67 8 ▶ if ($flag eq '-base') { $flag = $class }
Branch: 3 branches
BranchTrueFalseTotal
if ($flag eq '-base') { } 1 7 8
elsif ($flag eq '-strict') { } 0 7 7
elsif (my $file = $flag and not $flag->can('new')) { } 1 6 7
68
69 # Strict
70 0 elsif ($flag eq '-strict') { $flag = undef }
71
72 # Module
73 ▶ elsif ((my $file = $flag) && !$flag->can('new')) {
Condition66%2/3
my $file = $flag and not $flag->can("new")
!ll&&!rl&&r
061
MC/DC50%1/2
my $file = $flag and not $flag->can("new")
my $file = $flag not $flag->can("new")
Truth table66%2/3
A and not(B)
A= my $file = $flagB= not $flag->can("new")
ABresult
0X0
100
111
74 1 $file =~ s!::|'!/!g;
75 1 require "$file.pm";
76 }
77
78 # ISA
79 8 ▶ if ($flag) {
Branch: 1 branch
BranchTrueFalseTotal
if ($flag) 8 0 8
80 8 my $caller = caller;
81 1 ▶ no strict 'refs';
Subroutine BEGIN: called CC=1 SCAR=0.0
82 8 push @{"${caller}::ISA"}, $flag;
83 8 ▶ _monkey_patch $caller, 'has', sub { attr($caller, @_) };
Subroutine has: called CC=1 SCAR=0.0
84 }
85
86 # Mojo modules are strict!
87 8 $_->import for qw(strict warnings);
88 8 feature->import(':5.10');
89 }
90
91 0 ▶sub new {
Subroutine new: not called CC=4 SCAR=30.0
Pod undocumented
92 0 my $class = shift;
93 0 ▶ bless @_ ? @_ > 1 ? {@_} : {%{$_[0]}} : {}, ref $class || $class;
Branch: 2 branches
BranchTrueFalseTotal
@_ ? : 0 0 0
@_ > 1 ? : 0 0 0
Condition0%0/3
ref $class || $class
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table0%0/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
94 }
95
96 0 ▶sub tap {
Subroutine tap: not called CC=2 SCAR=17.9
Pod undocumented
97 0 my ($self, $cb) = (shift, shift);
98 0 $_->$cb(@_) for $self;
99 0 return $self;
100 }
101
102 1 1;
« Webqq/Plugin/StockInfo.pm ↑ Summary Webqq/Cache.pm »