| 1 | package Mojo::Weixin::Model::Base; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use Mojo::Weixin::Base -base; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use Data::Dumper; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use Scalar::Util qw(blessed); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use List::Util qw(first); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||
| 7 | 0 | ▶ | sub client { | ||||||||||||||||||||||||||
|
Subroutine
client: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 8 | 0 | return $Mojo::Weixin::_CLIENT; | |||||||||||||||||||||||||||
| 9 | } | ||||||||||||||||||||||||||||
| 10 | 0 | ▶ | sub to_json_hash{ | ||||||||||||||||||||||||||
|
Subroutine
to_json_hash: not called CC=9 SCAR=45.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 11 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 12 | 0 | ▶ | my $is_keep_member = shift || 1; | ||||||||||||||||||||||||||
|
Condition0%0/2
shift() || 1
MC/DC0%0/1
shift() || 1
shift()
Truth table0%0/2
A
A= shift()
| |||||||||||||||||||||||||||||
| 13 | 0 | my $hash = {}; | |||||||||||||||||||||||||||
| 14 | 0 | for(keys %$self){ | |||||||||||||||||||||||||||
| 15 | 0 | ▶ | next if substr($_,0,1) eq "_"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 16 | 0 | ▶ | next if $_ eq "member"; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 17 | 0 | $hash->{$_} = $self->{$_}; | |||||||||||||||||||||||||||
| 18 | 0 | $hash->{displayname} = $self->displayname; | |||||||||||||||||||||||||||
| 19 | } | ||||||||||||||||||||||||||||
| 20 | 0 | ▶ | if($is_keep_member and exists $self->{member} ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$is_keep_member and exists $self->{"member"}
MC/DC0%0/2
$is_keep_member and exists $self->{"member"}
$is_keep_member
exists $self->{"member"}
Truth table0%0/3
A and B
A= $is_keep_memberB= exists $self->{"member"}
| |||||||||||||||||||||||||||||
| 21 | 0 | $hash->{member} = []; | |||||||||||||||||||||||||||
| 22 | 0 | ▶ | if(ref $self->{member} eq "ARRAY"){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 23 | 0 | for my $m(@{$self->{member}}){ | |||||||||||||||||||||||||||
| 24 | 0 | my $member_hash = $m->to_json_hash(); | |||||||||||||||||||||||||||
| 25 | 0 | push @{$hash->{member}},$member_hash; | |||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||
| 27 | } | ||||||||||||||||||||||||||||
| 28 | } | ||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||
| 30 | 0 | return $hash; | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | 0 | ▶ | sub dump{ | ||||||||||||||||||||||||||
|
Subroutine
dump: not called CC=5 SCAR=34.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 33 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 34 | 0 | my $clone = {}; | |||||||||||||||||||||||||||
| 35 | 0 | my $obj_name = blessed($self); | |||||||||||||||||||||||||||
| 36 | 0 | for(keys %$self){ | |||||||||||||||||||||||||||
| 37 | 0 | ▶ | if(my $n=blessed($self->{$_})){ | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 38 | 0 | $clone->{$_} = "Object($n)"; | |||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | ▶ | elsif($_ eq "member" and ref($self->{$_}) eq "ARRAY"){ | |||||||||||||||||||||||||||
|
Condition0%0/3
$_ eq "member" and ref $self->{$_} eq "ARRAY"
MC/DC0%0/2
$_ eq "member" and ref $self->{$_} eq "ARRAY"
$_ eq "member"
ref $self->{$_} eq "ARRAY"
Truth table0%0/3
A and B
A= $_ eq "member"B= ref $self->{$_} eq "ARRAY"
| |||||||||||||||||||||||||||||
| 41 | 0 | my $member_count = @{$self->{$_}}; | |||||||||||||||||||||||||||
| 42 | 0 | $clone->{$_} = [ "$member_count of Object(${obj_name}::Member)" ]; | |||||||||||||||||||||||||||
| 43 | } | ||||||||||||||||||||||||||||
| 44 | else{ | ||||||||||||||||||||||||||||
| 45 | 0 | $clone->{$_} = $self->{$_}; | |||||||||||||||||||||||||||
| 46 | } | ||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||
| 48 | 0 | local $Data::Dumper::Indent = 1; | |||||||||||||||||||||||||||
| 49 | 0 | local $Data::Dumper::Terse = 1; | |||||||||||||||||||||||||||
| 50 | 0 | $self->client->print("Object($obj_name) " . Data::Dumper::Dumper($clone)); | |||||||||||||||||||||||||||
| 51 | 0 | return $self; | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||
| 54 | 0 | ▶ | sub _add{ | ||||||||||||||||||||||||||
|
Subroutine
_add: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 55 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 56 | 0 | my $array_ref = shift; | |||||||||||||||||||||||||||
| 57 | 0 | my $element = shift; | |||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||
| 59 | 0 | ▶ | if(@$array_ref == 0){ push @$array_ref,$element; return 3;} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 60 | 0 | ▶ | my $o = first { $element->id eq $_->id } @$array_ref; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||
| 61 | 0 | ▶ | if(defined $o){ $o->update($element);return 2} | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 62 | 0 | else{ push @$array_ref,$element;return 1} | |||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||
| 64 | 0 | ▶ | sub _remove{ | ||||||||||||||||||||||||||
|
Subroutine
_remove: not called CC=3 SCAR=24.8
| |||||||||||||||||||||||||||||
| 65 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 66 | 0 | my $array_ref = shift; | |||||||||||||||||||||||||||
| 67 | 0 | my $element = shift; | |||||||||||||||||||||||||||
| 68 | 0 | ▶ | for( my $i=0;$i<@$array_ref;$i++ ){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 69 | 0 | ▶ | if($array_ref->[$i]->id eq $element->id){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 70 | 0 | splice @$array_ref,$i,1; | |||||||||||||||||||||||||||
| 71 | 0 | return 1; | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | } | ||||||||||||||||||||||||||||
| 74 | 0 | return 0; | |||||||||||||||||||||||||||
| 75 | } | ||||||||||||||||||||||||||||
| 76 | 0 | ▶ | sub _search{ | ||||||||||||||||||||||||||
|
Subroutine
_search: not called CC=4 SCAR=30.0
| |||||||||||||||||||||||||||||
| 77 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 78 | 0 | my $array_ref = shift; | |||||||||||||||||||||||||||
| 79 | 0 | my %p = @_; | |||||||||||||||||||||||||||
| 80 | 0 | ▶ | return if 0 == grep {defined $p{$_}} keys %p; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 81 | 0 | delete $p{member}; | |||||||||||||||||||||||||||
| 82 | 0 | delete $p{_check_remote}; | |||||||||||||||||||||||||||
| 83 | 0 | ▶ | if(wantarray){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 84 | 0 | ▶ | return grep {my $g = $_;(first {$p{$_} ne $g->$_} grep {defined $p{$_}} keys %p) ? 0 : 1;} @$array_ref; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||
| 86 | else{ | ||||||||||||||||||||||||||||
| 87 | 0 | ▶ | return first {my $g = $_;(first {$p{$_} ne $g->$_} grep {defined $p{$_}} keys %p) ? 0 : 1;} @$array_ref; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=2 SCAR=17.9
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | ▶ | sub is_friend{ | ||||||||||||||||||||||||||
|
Subroutine
is_friend: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 92 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 93 | 0 | ▶ | ref $self eq "Mojo::Weixin::Friend"?1:0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||
| 95 | 0 | ▶ | sub is_group{ | ||||||||||||||||||||||||||
|
Subroutine
is_group: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 96 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 97 | 0 | ▶ | ref $self eq "Mojo::Weixin::Group"?1:0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | 0 | ▶ | sub is_group_member{ | ||||||||||||||||||||||||||
|
Subroutine
is_group_member: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 100 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 101 | 0 | ▶ | ref $self eq "Mojo::Weixin::Group::Member"?1:0; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 102 | } | ||||||||||||||||||||||||||||
| 103 | 0 | ▶ | sub type{ | ||||||||||||||||||||||||||
|
Subroutine
type: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 104 | 0 | my $self = shift; | |||||||||||||||||||||||||||
| 105 | 0 | my %map = ( | |||||||||||||||||||||||||||
| 106 | "Mojo::Weixin::Friend" => "friend", | ||||||||||||||||||||||||||||
| 107 | "Mojo::Weixin::Group" => "group", | ||||||||||||||||||||||||||||
| 108 | "Mojo::Weixin::Group::Member" => "member", | ||||||||||||||||||||||||||||
| 109 | "Mojo::Weixin::User" => "user", | ||||||||||||||||||||||||||||
| 110 | ); | ||||||||||||||||||||||||||||
| 111 | 0 | return $map{ref($self)}; | |||||||||||||||||||||||||||
| 112 | } | ||||||||||||||||||||||||||||
| 113 | |||||||||||||||||||||||||||||
| 114 | 1 | 1; | |||||||||||||||||||||||||||