Lyskom/MiscInfo.pm

filter: Statementstmt 69.1% 65 / 94 Branchbran 65.3% 34 / 52 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 69.2% 9 / 13 Podpod 77.7% 7 / 9 totaltotal 68.4% 115 / 168 CC 28 SCAR 26.1
CC
28
Cov
68%
compact
20.5
new_from_stream
19.3
new
3.1
CRAP 13.6
« Lyskom/Simple.pm ↑ Summary Lyskom/Time.pm »
1 package Net::Lyskom::MiscInfo;
2 1 ▶use base qw{Net::Lyskom::Object};
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
5 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
6 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
7  
8 =head1 NAME
9  
10 Net::Lyskom::MiscInfo - objects holding misc_info data for texts.
11  
12 =head1 SYNOPSIS
13  
14 $mi = Net::Lyskom::MiscInfo->new(type => "recpt", data => 6);
15  
16 =head1 DESCRIPTION
17  
18 Object that holds misc_info information.
19  
20 =head2 Methods
21  
22 =over
23  
24 =item ->type()
25  
26 Returns the type of the misc_info. Can be one of the following strings:
27  
28 recpt, cc_recpt, comm_to, comm_in, footn_to, footn_in, loc_no,
29 rec_time, sent_by, sent_at, bcc_recpt
30  
31 =item ->data()
32  
33 The data corresponding to the type. Numbers in all cases except for
34 C<rec_time>, where it is a L<Net::Lyskom::Time> object.
35  
36 =item ->loc_no()
37  
38 The local text number. Exists in the C<compact> versions of the
39 C<recpt> types.
40  
41 =item ->rec_time()
42  
43 As above, but for C<rec_time>.
44  
45 =item ->sent_by()
46  
47 As above, but for C<sent_by>.
48  
49 =item ->sent_at()
50  
51 As above, but for C<sent_by>.
52  
53 =item ->compact()
54  
55 Class method rather than object method. Takes a misc_info list and
56 puts the recipient metadata in the recipient type objects. This makes
57 it very much easier to process misc_info arrays with C<foreach>,
58 C<map> and other such functions.
59  
60 =cut
61  
62 1 our %type = (
63 recpt => 0,
64 cc_recpt => 1,
65 comm_to => 2,
66 comm_in => 3,
67 footn_to => 4,
68 footn_in => 5,
69 loc_no => 6,
70 rec_time => 7,
71 sent_by => 8,
72 sent_at => 9,
73 bcc_recpt => 15
74 );
75  
76 1 our %epyt = reverse %type;
77  
78 1 ▶sub new {
Subroutine new: called CC=3 SCAR=11.3
Pod undocumented
79 1 my $s = {};
80 1 my $class = shift;
81 1 my %a = @_;
82  
83 1 ▶ $class = ref($class) if ref($class);
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 1 1
84 1 bless $s,$class;
85  
86 1 ▶ if (!defined($type{$a{type}})) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $Net::Lyskom::MiscInfo::type{$a{"type"}}) 0 1 1
87 0 croak "Unknown MiscInfo type: $a{type}\n";
88 }
89 1 $s->{type} = $type{$a{type}};
90 1 $s->{data} = $a{data};
91  
92 1 return $s;
93 }
94  
95 15 ▶sub new_from_stream {
Subroutine new_from_stream: called CC=13 SCAR=29.6
Pod undocumented
96 15 my $s = {};
97 15 my $class = shift;
98 15 my $arg = $_[0];
99  
100 15 ▶ $class = ref($class) if ref($class);
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 15 15
101 15 bless $s, $class;
102  
103 15 $s->{type} = shift @{$arg};
104  
105 15 ▶ if ($s->{type} == $type{recpt}) {
Branch: 11 branches
BranchTrueFalseTotal
if ($s->{'type'} == $Net::Lyskom::MiscInfo::type{'recpt'}) { } 2 13 15
elsif ($s->{'type'} == $Net::Lyskom::MiscInfo::type{'cc_recpt'}) { } 2 11 13
elsif ($s->{'type'} == $Net::Lyskom::MiscInfo::type{'comm_to'}) { } 0 11 11
elsif ($s->{'type'} == $Net::Lyskom::MiscInfo::type{'comm_in'}) { } 1 10 11
elsif ($s->{'type'} == $Net::Lyskom::MiscInfo::type{'footn_to'}) { } 0 10 10
elsif ($s->{'type'} == $Net::Lyskom::MiscInfo::type{'footn_in'}) { } 0 10 10
elsif ($s->{'type'} == $Net::Lyskom::MiscInfo::type{'loc_no'}) { } 4 6 10
elsif ($s->{'type'} == $Net::Lyskom::MiscInfo::type{'rec_time'}) { } 0 6 6
elsif ($s->{'type'} == $Net::Lyskom::MiscInfo::type{'sent_by'}) { } 3 3 6
elsif ($s->{'type'} == $Net::Lyskom::MiscInfo::type{'sent_at'}) { } 3 0 3
elsif ($s->{'type'} == $Net::Lyskom::MiscInfo::type{'bcc_recpt'}) { } 0 0 0
106 2 $s->{data} = shift @{$arg};
107 } elsif ($s->{type} == $type{cc_recpt}) {
108 2 $s->{data} = shift @{$arg};
109 } elsif ($s->{type} == $type{comm_to}) {
110 0 $s->{data} = shift @{$arg};
111 } elsif ($s->{type} == $type{comm_in}) {
112 1 $s->{data} = shift @{$arg};
113 } elsif ($s->{type} == $type{footn_to}) {
114 0 $s->{data} = shift @{$arg};
115 } elsif ($s->{type} == $type{footn_in}) {
116 0 $s->{data} = shift @{$arg};
117 } elsif ($s->{type} == $type{loc_no}) {
118 4 $s->{data} = shift @{$arg};
119 } elsif ($s->{type} == $type{rec_time}) {
120 0 $s->{data} = Net::Lyskom::Time->new_from_stream($arg);
121 } elsif ($s->{type} == $type{sent_by}) {
122 3 $s->{data} = shift @{$arg};
123 } elsif ($s->{type} == $type{sent_at}) {
124 3 $s->{data} = Net::Lyskom::Time->new_from_stream($arg);
125 } elsif ($s->{type} == $type{bcc_recpt}) {
126 0 $s->{data} = shift @{$arg};
127 } else {
128 0 croak "Unknown misc_info type recieved from server: $s->{type}";
129 }
130 15 return $s;
131 }
132  
133 1 ▶sub type {
Subroutine type: called CC=1 SCAR=0.0
Pod documented
134 1 my $s = shift;
135  
136 1 return $epyt{$s->{type}};
137 }
138  
139 1 ▶sub data {
Subroutine data: called CC=2 SCAR=7.1
Pod documented
140 1 my $s = shift;
141  
142 1 ▶ $s->{data} = $_[0] if $_[0];
Branch: 1 branch
BranchTrueFalseTotal
if $_[0] 0 1 1
143 1 return $s->{data};
144 }
145  
146 0 ▶sub loc_no {my $s = shift; return $s->{loc_no}}
Subroutine loc_no: not called CC=1 SCAR=6.9
Pod documented
147 0 ▶sub rec_time {my $s = shift; return $s->{rec_time}}
Subroutine rec_time: not called CC=1 SCAR=6.9
Pod documented
148 0 ▶sub sent_by {my $s = shift; return $s->{sent_by}}
Subroutine sent_by: not called CC=1 SCAR=6.9
Pod documented
149 0 ▶sub sent_at {my $s = shift; return $s->{sent_at}}
Subroutine sent_at: not called CC=1 SCAR=6.9
Pod documented
150  
151 1 ▶sub compact {
Subroutine compact: called CC=13 SCAR=30.2
Pod documented
152 1 my $s = shift;
153 1 my @res;
154 my $last;
155  
156 1 $last = shift @_;
157 1 foreach my $s (@_) {
158 14 ▶ if ($s->{type} == $type{recpt}) {
Branch: 11 branches
BranchTrueFalseTotal
if ($s->{'type'} == $Net::Lyskom::MiscInfo::type{'recpt'}) { } 1 13 14
elsif ($s->{'type'} == $Net::Lyskom::MiscInfo::type{'cc_recpt'}) { } 2 11 13
elsif ($s->{'type'} == $Net::Lyskom::MiscInfo::type{'comm_to'}) { } 0 11 11
elsif ($s->{'type'} == $Net::Lyskom::MiscInfo::type{'comm_in'}) { } 1 10 11
elsif ($s->{'type'} == $Net::Lyskom::MiscInfo::type{'footn_to'}) { } 0 10 10
elsif ($s->{'type'} == $Net::Lyskom::MiscInfo::type{'footn_in'}) { } 0 10 10
elsif ($s->{'type'} == $Net::Lyskom::MiscInfo::type{'loc_no'}) { } 4 6 10
elsif ($s->{'type'} == $Net::Lyskom::MiscInfo::type{'rec_time'}) { } 0 6 6
elsif ($s->{'type'} == $Net::Lyskom::MiscInfo::type{'sent_by'}) { } 3 3 6
elsif ($s->{'type'} == $Net::Lyskom::MiscInfo::type{'sent_at'}) { } 3 0 3
elsif ($s->{'type'} == $Net::Lyskom::MiscInfo::type{'bcc_recpt'}) { } 0 0 0
159 1 push @res,$last;
160 1 $last = $s;
161 } elsif ($s->{type} == $type{cc_recpt}) {
162 2 push @res,$last;
163 2 $last = $s;
164 } elsif ($s->{type} == $type{comm_to}) {
165 0 push @res,$last;
166 0 $last = $s;
167 } elsif ($s->{type} == $type{comm_in}) {
168 1 push @res,$last;
169 1 $last = $s;
170 } elsif ($s->{type} == $type{footn_to}) {
171 0 push @res,$last;
172 0 $last = $s;
173 } elsif ($s->{type} == $type{footn_in}) {
174 0 push @res,$last;
175 0 $last = $s;
176 } elsif ($s->{type} == $type{loc_no}) {
177 4 $last->{loc_no} = $s->{data};
178 } elsif ($s->{type} == $type{rec_time}) {
179 0 $last->{rec_time} = $s->{data};
180 } elsif ($s->{type} == $type{sent_by}) {
181 3 $last->{sent_by} = $s->{data};
182 } elsif ($s->{type} == $type{sent_at}) {
183 3 $last->{sent_at} = $s->{data};
184 } elsif ($s->{type} == $type{bcc_recpt}) {
185 0 push @res,$last;
186 0 $last = $s;
187 } else {
188 0 croak "Unknown misc_info type in compact(): $s->{type}";
189 }
190 }
191 1 push @res,$last;
192 1 return @res;
193 }
194  
195 1 return 1;
« Lyskom/Simple.pm ↑ Summary Lyskom/Time.pm »