line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::Weixin::Model::Base; |
2
|
1
|
|
|
1
|
|
9
|
use Mojo::Weixin::Base -base; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
8
|
|
3
|
1
|
|
|
1
|
|
8
|
use Data::Dumper; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
71
|
|
4
|
1
|
|
|
1
|
|
7
|
use Scalar::Util qw(blessed); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
47
|
|
5
|
1
|
|
|
1
|
|
6
|
use List::Util qw(first); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1214
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
sub client { |
8
|
0
|
|
|
0
|
0
|
|
return $Mojo::Weixin::_CLIENT; |
9
|
|
|
|
|
|
|
} |
10
|
|
|
|
|
|
|
sub to_json_hash{ |
11
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
12
|
0
|
|
0
|
|
|
|
my $is_keep_member = shift || 1; |
13
|
0
|
|
|
|
|
|
my $hash = {}; |
14
|
0
|
|
|
|
|
|
for(keys %$self){ |
15
|
0
|
0
|
|
|
|
|
next if substr($_,0,1) eq "_"; |
16
|
0
|
0
|
|
|
|
|
next if $_ eq "member"; |
17
|
0
|
|
|
|
|
|
$hash->{$_} = $self->{$_}; |
18
|
0
|
|
|
|
|
|
$hash->{displayname} = $self->displayname; |
19
|
|
|
|
|
|
|
} |
20
|
0
|
0
|
0
|
|
|
|
if($is_keep_member and exists $self->{member} ){ |
21
|
0
|
|
|
|
|
|
$hash->{member} = []; |
22
|
0
|
0
|
|
|
|
|
if(ref $self->{member} eq "ARRAY"){ |
23
|
0
|
|
|
|
|
|
for my $m(@{$self->{member}}){ |
|
0
|
|
|
|
|
|
|
24
|
0
|
|
|
|
|
|
my $member_hash = $m->to_json_hash(); |
25
|
0
|
|
|
|
|
|
push @{$hash->{member}},$member_hash; |
|
0
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
} |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
} |
29
|
|
|
|
|
|
|
|
30
|
0
|
|
|
|
|
|
return $hash; |
31
|
|
|
|
|
|
|
} |
32
|
|
|
|
|
|
|
sub dump{ |
33
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
34
|
0
|
|
|
|
|
|
my $clone = {}; |
35
|
0
|
|
|
|
|
|
my $obj_name = blessed($self); |
36
|
0
|
|
|
|
|
|
for(keys %$self){ |
37
|
0
|
0
|
0
|
|
|
|
if(my $n=blessed($self->{$_})){ |
|
|
0
|
|
|
|
|
|
38
|
0
|
|
|
|
|
|
$clone->{$_} = "Object($n)"; |
39
|
|
|
|
|
|
|
} |
40
|
|
|
|
|
|
|
elsif($_ eq "member" and ref($self->{$_}) eq "ARRAY"){ |
41
|
0
|
|
|
|
|
|
my $member_count = @{$self->{$_}}; |
|
0
|
|
|
|
|
|
|
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
|
|
|
|
|
|
|
sub _add{ |
55
|
0
|
|
|
0
|
|
|
my $self = shift; |
56
|
0
|
|
|
|
|
|
my $array_ref = shift; |
57
|
0
|
|
|
|
|
|
my $element = shift; |
58
|
|
|
|
|
|
|
|
59
|
0
|
0
|
|
|
|
|
if(@$array_ref == 0){ push @$array_ref,$element; return 3;} |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
60
|
0
|
|
|
0
|
|
|
my $o = first { $element->id eq $_->id } @$array_ref; |
|
0
|
|
|
|
|
|
|
61
|
0
|
0
|
|
|
|
|
if(defined $o){ $o->update($element);return 2} |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
62
|
0
|
|
|
|
|
|
else{ push @$array_ref,$element;return 1} |
|
0
|
|
|
|
|
|
|
63
|
|
|
|
|
|
|
} |
64
|
|
|
|
|
|
|
sub _remove{ |
65
|
0
|
|
|
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++ ){ |
69
|
0
|
0
|
|
|
|
|
if($array_ref->[$i]->id eq $element->id){ |
70
|
0
|
|
|
|
|
|
splice @$array_ref,$i,1; |
71
|
0
|
|
|
|
|
|
return 1; |
72
|
|
|
|
|
|
|
} |
73
|
|
|
|
|
|
|
} |
74
|
0
|
|
|
|
|
|
return 0; |
75
|
|
|
|
|
|
|
} |
76
|
|
|
|
|
|
|
sub _search{ |
77
|
0
|
|
|
0
|
|
|
my $self = shift; |
78
|
0
|
|
|
|
|
|
my $array_ref = shift; |
79
|
0
|
|
|
|
|
|
my %p = @_; |
80
|
0
|
0
|
|
|
|
|
return if 0 == grep {defined $p{$_}} keys %p; |
|
0
|
|
|
|
|
|
|
81
|
0
|
|
|
|
|
|
delete $p{member}; |
82
|
0
|
|
|
|
|
|
delete $p{_check_remote}; |
83
|
0
|
0
|
|
|
|
|
if(wantarray){ |
84
|
0
|
0
|
|
0
|
|
|
return grep {my $g = $_;(first {$p{$_} ne $g->$_} grep {defined $p{$_}} keys %p) ? 0 : 1;} @$array_ref; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
} |
86
|
|
|
|
|
|
|
else{ |
87
|
0
|
0
|
|
0
|
|
|
return first {my $g = $_;(first {$p{$_} ne $g->$_} grep {defined $p{$_}} keys %p) ? 0 : 1;} @$array_ref; |
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub is_friend{ |
92
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
93
|
0
|
0
|
|
|
|
|
ref $self eq "Mojo::Weixin::Friend"?1:0; |
94
|
|
|
|
|
|
|
} |
95
|
|
|
|
|
|
|
sub is_group{ |
96
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
97
|
0
|
0
|
|
|
|
|
ref $self eq "Mojo::Weixin::Group"?1:0; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
sub is_group_member{ |
100
|
0
|
|
|
0
|
0
|
|
my $self = shift; |
101
|
0
|
0
|
|
|
|
|
ref $self eq "Mojo::Weixin::Group::Member"?1:0; |
102
|
|
|
|
|
|
|
} |
103
|
|
|
|
|
|
|
sub type{ |
104
|
0
|
|
|
0
|
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; |