| 1 | package Mojo::Weixin::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];
}
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];
}
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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 | 97 | ▶ | sub _monkey_patch { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_monkey_patch: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||||
| 21 | 97 | 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 | 97 | *{"${class}::$_"} = $NAME->("${class}::$_", $patch{$_}) for keys %patch; | |||||||||||||||||||||||||||||||||||||||||||||
| 25 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||||||
| 27 | 32 | ▶ | sub attr { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
attr: called CC=11 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||||
| 28 | 32 | my ($self, $attrs, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||||||
| 29 | 32 | ▶ | return unless (my $class = ref $self || $self) && $attrs; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%2/6
my $class = ref $self || $self and $attrs
ref $self || $self
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
| |||||||||||||||||||||||||||||||||||||||||||||||
| 30 | |||||||||||||||||||||||||||||||||||||||||||||||
| 31 | 32 | ▶ | Carp::croak 'Default has to be a code reference or constant value' | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
ref $value and ref $value ne "CODE"
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"
| |||||||||||||||||||||||||||||||||||||||||||||||
| 32 | if ref $value && ref $value ne 'CODE'; | ||||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||||
| 34 | 32 | ▶ | for my $attr (@{ref $attrs eq 'ARRAY' ? $attrs : [$attrs]}) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 35 | 89 | ▶ | Carp::croak qq{Attribute "$attr" invalid} unless $attr =~ /^[a-zA-Z_]\w*$/; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||||||
| 37 | # Very performance sensitive code with lots of micro-optimizations | ||||||||||||||||||||||||||||||||||||||||||||||
| 38 | 89 | ▶ | if (ref $value) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 39 | 0 | ▶ | _monkey_patch $class, $attr, sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
time: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 40 | return | ||||||||||||||||||||||||||||||||||||||||||||||
| 41 | 0 | ▶ | exists $_[0]{$attr} ? $_[0]{$attr} : ($_[0]{$attr} = $value->($_[0])) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 42 | if @_ == 1; | ||||||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | $_[0]{$attr} = $_[1]; | |||||||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||
| 45 | 2 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 47 | elsif (defined $value) { | ||||||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | ▶ | _monkey_patch $class, $attr, sub { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
name: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||||||||||||||||||||
| 49 | 0 | ▶ | return exists $_[0]{$attr} ? $_[0]{$attr} : ($_[0]{$attr} = $value) | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 50 | if @_ == 1; | ||||||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | $_[0]{$attr} = $_[1]; | |||||||||||||||||||||||||||||||||||||||||||||
| 52 | 0 | $_[0]; | |||||||||||||||||||||||||||||||||||||||||||||
| 53 | 11 | }; | |||||||||||||||||||||||||||||||||||||||||||||
| 54 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 55 | else { | ||||||||||||||||||||||||||||||||||||||||||||||
| 56 | _monkey_patch $class, $attr, | ||||||||||||||||||||||||||||||||||||||||||||||
| 57 | 0 | ▶ | sub { return $_[0]{$attr} if @_ == 1; $_[0]{$attr} = $_[1]; $_[0] }; | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
signature: not called CC=2 SCAR=14.6
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 59 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 60 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 61 | |||||||||||||||||||||||||||||||||||||||||||||||
| 62 | 15 | ▶ | sub import { | ||||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
import: called CC=8 SCAR=21.0
| |||||||||||||||||||||||||||||||||||||||||||||||
| 63 | 15 | my $class = shift; | |||||||||||||||||||||||||||||||||||||||||||||
| 64 | 15 | ▶ | return unless my $flag = shift; | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||||||
| 66 | # Base | ||||||||||||||||||||||||||||||||||||||||||||||
| 67 | 8 | ▶ | if ($flag eq '-base') { $flag = $class } | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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")
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")
| |||||||||||||||||||||||||||||||||||||||||||||||
| 74 | 2 | $file =~ s!::|'!/!g; | |||||||||||||||||||||||||||||||||||||||||||||
| 75 | 2 | require "$file.pm"; | |||||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||||||
| 78 | # ISA | ||||||||||||||||||||||||||||||||||||||||||||||
| 79 | 8 | ▶ | if ($flag) { | ||||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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
Condition0%0/3
ref $class || $class
MC/DC0%0/2
ref $class || $class
ref $class
$class
Truth table0%0/3
A || B
A= ref $classB= $class
| |||||||||||||||||||||||||||||||||||||||||||||||
| 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; | |||||||||||||||||||||||||||||||||||||||||||||