IPMessenger/MessageCommand.pm

filter: Statementstmt 90.9% 50 / 55 Branchbran 68.1% 15 / 22 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 90.0% 9 / 10 Podpod 100% 4 / 4 totaltotal 85.7% 78 / 91 CC 13 SCAR 14.1
CC
13
Cov
84%
AUTOLOAD
7.8
new
4.1
modename
3.0
CRAP 4.1
« IPMessenger/RecvEventHandler.pm ↑ Summary IPMessenger/EventHandler.pm »
1 package Net::IPMessenger::MessageCommand;
2  
3 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 2 ▶use overload '""' => \&get_command, fallback => 1;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 2 ▶use Scalar::Util qw( looks_like_number );
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 2 our $AUTOLOAD;
9  
10 2 my %COMMAND = (
11 NOOPERATION => 0x00000000,
12 BR_ENTRY => 0x00000001,
13 BR_EXIT => 0x00000002,
14 ANSENTRY => 0x00000003,
15 BR_ABSENCE => 0x00000004,
16 BR_ISGETLIST => 0x00000010,
17 OKGETLIST => 0x00000011,
18 GETLIST => 0x00000012,
19 ANSLIST => 0x00000013,
20 BR_ISGETLIST2 => 0x00000018,
21 SENDMSG => 0x00000020,
22 RECVMSG => 0x00000021,
23 READMSG => 0x00000030,
24 DELMSG => 0x00000031,
25 ANSREADMSG => 0x00000032,
26 GETINFO => 0x00000040,
27 SENDINFO => 0x00000041,
28 GETABSENCEINFO => 0x00000050,
29 SENDABSENCEINFO => 0x00000051,
30 GETFILEDAT => 0x00000060,
31 RELEASEFIL => 0x00000061,
32 GETDIRFILE => 0x00000062,
33 GETPUBKEY => 0x00000072,
34 ANSPUBKEY => 0x00000073,
35 );
36  
37 2 my $MODE = 0x000000ff;
38 2 my %SEND_OPT = (
39 ABSENCE => 0x00000100,
40 SERVER => 0x00000200,
41 DIALUP => 0x00010000,
42 SENDCHECK => 0x00000100,
43 SECRET => 0x00000200,
44 BROADCAST => 0x00000400,
45 MULTICAST => 0x00000800,
46 NOPOPUP => 0x00001000,
47 AUTORET => 0x00002000,
48 RETRY => 0x00004000,
49 PASSWORD => 0x00008000,
50 NOLOG => 0x00020000,
51 NEWMUTI => 0x00040000,
52 NOADDLIST => 0x00080000,
53 READCHECK => 0x00100000,
54 FILEATTACH => 0x00200000,
55 ENCRYPT => 0x00400000,
56 );
57  
58 20 ▶sub new {
Subroutine new: called CC=4 SCAR=14.1
Pod documented
59 20 my $class = shift;
60 20 my $name = shift;
61 20 ▶ return unless defined $name;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $name 0 20 20
62  
63 20 my $command;
64 20 ▶ if ( looks_like_number($name) ) {
Branch: 2 branches
BranchTrueFalseTotal
if (&looks_like_number($name)) { } 16 4 20
elsif (exists $COMMAND{$name}) { } 4 0 4
65 16 $command = $name;
66 }
67 elsif ( exists $COMMAND{$name} ) {
68 4 $command = $COMMAND{$name};
69 }
70 else {
71 0 return;
72 }
73  
74 20 my $self = { _command => $command };
75 20 bless $self, $class;
76 }
77  
78 14 ▶sub AUTOLOAD {
Subroutine AUTOLOAD: called CC=7 SCAR=20.5
79 14 my $self = shift;
80 14 ▶ return unless ref $self;
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self 0 14 14
81  
82 14 my $command = $self->{_command};
83 14 my $name = $AUTOLOAD;
84 14 $name =~ s/.*://;
85  
86 14 ▶ if ( $name =~ /^get_(.+)/ ) {
Branch: 2 branches
BranchTrueFalseTotal
if ($name =~ /^get_(.+)/) { } 12 2 14
elsif ($name =~ /^set_(.+)/) { } 2 0 2
87 12 my $opt = uc $1;
88 12 ▶ if ( exists $SEND_OPT{$opt} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $SEND_OPT{$opt}) { } 12 0 12
89 12 ▶ return ( $command & $SEND_OPT{$opt} ? 1 : 0 );
Branch: 1 branch
BranchTrueFalseTotal
$command & $SEND_OPT{$opt} ? : 4 8 12
90 }
91 else {
92 0 return;
93 }
94 }
95 elsif ( $name =~ /^set_(.+)/ ) {
96 2 my $opt = uc $1;
97 2 ▶ if ( exists $SEND_OPT{$opt} ) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $SEND_OPT{$opt}) { } 2 0 2
98 2 $self->{_command} = $command | $SEND_OPT{$opt};
99 2 return $self;
100 }
101 else {
102 0 return;
103 }
104 }
105 else {
106 0 return;
107 }
108 }
109  
110 19 ▶sub mode {
Subroutine mode: called CC=2 SCAR=7.0
Pod documented
111 19 my $self = shift;
112 19 my $command = $self->{_command};
113  
114 19 ▶ return (0) unless defined $command;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $command 0 19 19
115 19 return ( $command & $MODE );
116 }
117  
118 19 ▶sub modename {
Subroutine modename: called CC=3 SCAR=11.0
Pod documented
119 19 my $self = shift;
120 19 my $mode = $self->mode;
121  
122 19 for my $key ( keys %COMMAND ) {
123 280 ▶ if ( $mode eq $COMMAND{$key} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($mode eq $COMMAND{$key}) 19 261 280
124 19 return $key;
125 }
126 }
127 0 return $mode;
128 }
129  
130 4 ▶sub get_command {
Subroutine get_command: called CC=1 SCAR=0.0
Pod documented
131 4 my $self = shift;
132 4 return $self->{_command};
133 }
134  
135 0 ▶sub DESTROY {
Subroutine DESTROY: not called CC=1 SCAR=0.0
136 }
137  
138 2 1;
139 __END__
« IPMessenger/RecvEventHandler.pm ↑ Summary IPMessenger/EventHandler.pm »