File Coverage

blib/lib/Mojo/Weixin/Friend.pm
Criterion Covered Total %
statement 6 48 12.5
branch 0 24 0.0
condition 0 11 0.0
subroutine 2 10 20.0
pod 0 8 0.0
total 8 101 7.9


line stmt bran cond sub pod time code
1             package Mojo::Weixin::Friend;
2 1     1   6 use Mojo::Weixin::Base 'Mojo::Weixin::Model::Base';
  1         1  
  1         6  
3 1     1   5 use List::Util qw(first);
  1         2  
  1         751  
4             has name => '';
5             has [qw(
6             account
7             province
8             city
9             sex
10             id
11             uid
12             signature
13             display
14             markname
15             _avatar
16             _verifyflag
17             )];
18             has 'category' => '好友'; #系统帐号|公众号|好友
19              
20             my %special_id = map {$_=>undef} ("filehelper","fmessage","newsapp","weibo", "qqmail", "tmessage", "qmessage", "qqsync", "floatbottle", "lbsapp", "shakeapp", "medianote", "qqfriend", "readerapp", "blogapp", "facebookapp", "masssendapp", "meishiapp", "feedsapp", "voip", "blogappweixin", "brandsessionholder", "weixinreminder", "wxid_novlwrv3lqwv11", "gh_22b87fa7cb3c", "officialaccounts", "notification_messages");
21              
22             sub new {
23 0     0 0   my $self = shift;
24 0           $self = $self->Mojo::Weixin::Base::new(@_);
25 0           $self->client->emoji_convert(\$self->{name},$self->client->emoji_to_text);
26 0           $self->client->emoji_convert(\$self->{display},$self->client->emoji_to_text);
27 0           $self->client->emoji_convert(\$self->{markname},$self->client->emoji_to_text);
28 0 0 0       if(exists $special_id{$self->id}){
    0          
29 0           $self->category("系统帐号");
30             }
31             elsif(defined $self->_verifyflag and $self->_verifyflag & 8){
32 0           $self->category("公众号");
33             }
34 0           else{$self->category("好友");}
35 0 0         $self->uid("") if not $self->uid;
36 0           $self;
37             }
38             sub get_avatar{
39 0     0 0   my $self = shift;
40 0           $self->client->get_avatar($self,@_);
41             }
42              
43             sub displayname{
44 0     0 0   my $self = shift;
45 0   0       return $self->display || $self->markname || $self->name || '昵称未知';
46             }
47              
48             sub update{
49 0     0 0   my $self = shift;
50 0           my $hash = shift;
51 0           for(grep {substr($_,0,1) ne "_"} keys %$hash){
  0            
52 0 0         if(exists $hash->{$_}){
53 0 0         $self->client->emoji_convert(\$hash->{$_},$self->client->emoji_to_text) if $_ eq "name";
54 0 0         $self->client->emoji_convert(\$hash->{$_},$self->client->emoji_to_text) if $_ eq "display";
55 0 0         $self->client->emoji_convert(\$hash->{$_},$self->client->emoji_to_text) if $_ eq "markname";
56 0 0 0       if(defined $hash->{$_} and defined $self->{$_}){
    0 0        
57 0 0         if($hash->{$_} ne $self->{$_}){
58 0           my $old_property = $self->{$_};
59 0           my $new_property = $hash->{$_};
60 0           $self->{$_} = $hash->{$_};
61 0 0         $self->client->emit("friend_property_change"=>$self,$_,$old_property,$new_property) if defined $self->client;
62             }
63             }
64             elsif( ! (!defined $hash->{$_} and !defined $self->{$_}) ){
65 0           my $old_property = $self->{$_};
66 0           my $new_property = $hash->{$_};
67 0           $self->{$_} = $hash->{$_};
68 0 0         $self->client->emit("friend_property_change"=>$self,$_,$old_property,$new_property) if defined $self->client;
69             }
70             }
71             }
72 0           $self;
73              
74             }
75              
76             sub send{
77 0     0 0   my $self = shift;
78 0           $self->client->send_message($self,@_);
79             }
80             sub send_media{
81 0     0 0   my $self = shift;
82 0           $self->client->send_media($self,@_);
83             }
84             sub set_markname {
85 0     0 0   my $self = shift;
86 0           $self->client->set_markname($self,@_);
87             }
88             sub stick{
89 0     0 0   my $self = shift;
90 0           $self->client->stick($self,@_);
91             }
92             1;