| 1 | package Mojo::IRC::Server::Chinese::Channel; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use Mojo::IRC::Server::Chinese::Base 'Mojo::IRC::Server::Chinese::Object'; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use List::Util qw(first); | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | has 'name'; | |||||||||||||||||||||||||||
| 5 | 0 | ▶ | has id => sub {lc $_[0]->name}; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 6 | 0 | ▶ | has topic => sub {"欢迎来到 " . $_[0]->name}; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 7 | 0 | ▶ | has ctime => sub {time()}; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 8 | 1 | has mode => 'i'; | |||||||||||||||||||||||||||
| 9 | 1 | has pass => undef; | |||||||||||||||||||||||||||
| 10 | 0 | ▶ | has user => sub {[]}; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||
| 12 | 0 | ▶ | sub count { | ||||||||||||||||||||||||||
|
Subroutine
count: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 13 | 0 | my $s = shift; | |||||||||||||||||||||||||||
| 14 | 0 | 0+@{$s->user}; | |||||||||||||||||||||||||||
| 15 | } | ||||||||||||||||||||||||||||
| 16 | 0 | ▶ | sub add_user{ | ||||||||||||||||||||||||||
|
Subroutine
add_user: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 17 | 0 | my $s = shift; | |||||||||||||||||||||||||||
| 18 | 0 | ▶ | my $uid = ref($_[0]) eq "Mojo::IRC::Server::Chinese::User"?$_[0]->id:$_[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 19 | 0 | ▶ | push @{$s->user},$uid if not $s->is_has_user($uid); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 20 | } | ||||||||||||||||||||||||||||
| 21 | 0 | ▶ | sub remove_user{ | ||||||||||||||||||||||||||
|
Subroutine
remove_user: not called CC=6 SCAR=37.4
Pod
undocumented
| |||||||||||||||||||||||||||||
| 22 | 0 | my $s = shift; | |||||||||||||||||||||||||||
| 23 | 0 | ▶ | my $uid = ref($_[0]) eq "Mojo::IRC::Server::Chinese::User"?$_[0]->id:$_[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 24 | 0 | ▶ | for(my $i=0;$i<@{$s->user};$i++){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 25 | 0 | ▶ | if($uid eq $s->user->[$i]){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 26 | 0 | splice @{$s->user},$i,1; | |||||||||||||||||||||||||||
| 27 | 0 | ▶ | if(@{$s->user} == 0 and $s->mode !~/P/){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
@{$s->user;} == 0 and not $s->mode =~ /P/
MC/DC0%0/2
@{$s->user;} == 0 and not $s->mode =~ /P/
@{$s->user;} == 0
not $s->mode =~ /P/
Truth table0%0/3
A and not(B)
A= @{$s->user;} == 0B= not $s->mode =~ /P/
| |||||||||||||||||||||||||||||
| 28 | 0 | $s->{_server}->remove_channel($s); | |||||||||||||||||||||||||||
| 29 | } | ||||||||||||||||||||||||||||
| 30 | 0 | return; | |||||||||||||||||||||||||||
| 31 | } | ||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||
| 33 | } | ||||||||||||||||||||||||||||
| 34 | 0 | ▶ | sub is_has_user{ | ||||||||||||||||||||||||||
|
Subroutine
is_has_user: not called CC=4 SCAR=30.0
Pod
undocumented
| |||||||||||||||||||||||||||||
| 35 | 0 | my $s = shift; | |||||||||||||||||||||||||||
| 36 | 0 | ▶ | my $uid = ref($_[0]) eq "Mojo::IRC::Server::Chinese::User"?$_[0]->id:$_[0]; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 37 | 0 | ▶ | if(defined $uid){ | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 38 | 0 | ▶ | return (first {$uid eq $_} @{$s->user})?1:0; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 39 | } | ||||||||||||||||||||||||||||
| 40 | else{ | ||||||||||||||||||||||||||||
| 41 | 0 | return 0+@{$s->user}; | |||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||
| 44 | } | ||||||||||||||||||||||||||||
| 45 | 0 | ▶ | sub set_topic{ | ||||||||||||||||||||||||||
|
Subroutine
set_topic: not called CC=1 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 46 | 0 | my $s = shift; | |||||||||||||||||||||||||||
| 47 | 0 | my $user = shift; | |||||||||||||||||||||||||||
| 48 | 0 | my $topic = shift; | |||||||||||||||||||||||||||
| 49 | 0 | $s->topic($topic); | |||||||||||||||||||||||||||
| 50 | 0 | $s->broadcast($user->ident,"TOPIC",$s->name,$topic); | |||||||||||||||||||||||||||
| 51 | 0 | $s->info($s->name . " 主题设置为: " . $s->topic); | |||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||
| 53 | 0 | ▶ | sub set_mode{ | ||||||||||||||||||||||||||
|
Subroutine
set_mode: not called CC=8 SCAR=42.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 54 | 0 | my $s = shift; | |||||||||||||||||||||||||||
| 55 | 0 | my $user = shift; | |||||||||||||||||||||||||||
| 56 | 0 | my $mode = shift; | |||||||||||||||||||||||||||
| 57 | 0 | ▶ | $mode = "+" . $mode if (substr($mode,0,1) ne '+' and substr($mode,0,1) ne '-'); | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
substr($mode, 0, 1) ne "+" and substr($mode, 0, 1) ne "-"
MC/DC0%0/2
substr($mode, 0, 1) ne "+" and substr($mode, 0, 1) ne "-"
substr($mode, 0, 1) ne "+"
substr($mode, 0, 1) ne "-"
Truth table0%0/3
A and B
A= substr($mode, 0, 1) ne "+"B= substr($mode, 0, 1) ne "-"
| |||||||||||||||||||||||||||||
| 58 | 0 | my %mode = map {$_=>1} split //,$s->mode; | |||||||||||||||||||||||||||
| 59 | 0 | ▶ | if(substr($mode,0,1) eq "+"){ | ||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||
| 60 | 0 | $mode{$_}=1 for split //,substr($mode,1,); | |||||||||||||||||||||||||||
| 61 | } | ||||||||||||||||||||||||||||
| 62 | elsif(substr($mode,0,1) eq "-"){ | ||||||||||||||||||||||||||||
| 63 | 0 | delete $mode{$_} for split //,substr($mode,1,); | |||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||
| 65 | else{ | ||||||||||||||||||||||||||||
| 66 | 0 | %mode = (); | |||||||||||||||||||||||||||
| 67 | 0 | $mode{$_}=1 for split //,$mode; | |||||||||||||||||||||||||||
| 68 | } | ||||||||||||||||||||||||||||
| 69 | 0 | $s->mode(join "",keys %mode); | |||||||||||||||||||||||||||
| 70 | 0 | $s->broadcast($user->ident,"MODE",$s->name,$mode); | |||||||||||||||||||||||||||
| 71 | 0 | $s->info("[" . $s->name . "] 模式设置为: " . $s->mode); | |||||||||||||||||||||||||||
| 72 | } | ||||||||||||||||||||||||||||
| 73 | |||||||||||||||||||||||||||||
| 74 | 0 | ▶ | sub users{ | ||||||||||||||||||||||||||
|
Subroutine
users: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 75 | 0 | my $s = shift; | |||||||||||||||||||||||||||
| 76 | 0 | my @users = (); | |||||||||||||||||||||||||||
| 77 | 0 | for my $uid (@{$s->user}){ | |||||||||||||||||||||||||||
| 78 | 0 | my $user = $s->search_user(id=>$uid); | |||||||||||||||||||||||||||
| 79 | 0 | ▶ | push @users ,$user if defined $user; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 80 | } | ||||||||||||||||||||||||||||
| 81 | 0 | return @users; | |||||||||||||||||||||||||||
| 82 | } | ||||||||||||||||||||||||||||
| 83 | |||||||||||||||||||||||||||||
| 84 | 0 | ▶ | sub broadcast { | ||||||||||||||||||||||||||
|
Subroutine
broadcast: not called CC=2 SCAR=17.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 85 | 0 | my $s = shift; | |||||||||||||||||||||||||||
| 86 | 0 | for my $user ($s->users){ | |||||||||||||||||||||||||||
| 87 | 0 | $user->send(@_); | |||||||||||||||||||||||||||
| 88 | } | ||||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | ▶ | sub forward { | ||||||||||||||||||||||||||
|
Subroutine
forward: not called CC=3 SCAR=24.8
Pod
undocumented
| |||||||||||||||||||||||||||||
| 92 | 0 | my $s = shift; | |||||||||||||||||||||||||||
| 93 | 0 | my $except_user = shift; | |||||||||||||||||||||||||||
| 94 | 0 | for my $user ($s->users){ | |||||||||||||||||||||||||||
| 95 | 0 | ▶ | next if $user->id eq $except_user->id; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 96 | 0 | $user->send(@_); | |||||||||||||||||||||||||||
| 97 | } | ||||||||||||||||||||||||||||
| 98 | } | ||||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 1 | 1; | |||||||||||||||||||||||||||