line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Net::Lyskom::TextStat; |
2
|
1
|
|
|
1
|
|
23
|
use base qw{Net::Lyskom::Object}; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
87
|
|
3
|
1
|
|
|
1
|
|
6
|
use strict; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
41
|
|
4
|
1
|
|
|
1
|
|
6
|
use warnings; |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
39
|
|
5
|
|
|
|
|
|
|
|
6
|
1
|
|
|
1
|
|
6
|
use Net::Lyskom::Util qw{:all}; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
200
|
|
7
|
1
|
|
|
1
|
|
6
|
use Net::Lyskom::MiscInfo; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
31
|
|
8
|
1
|
|
|
1
|
|
5
|
use Net::Lyskom::AuxItem; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
20
|
|
9
|
1
|
|
|
1
|
|
5
|
use Carp; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
77
|
|
10
|
1
|
|
|
1
|
|
5
|
use Encode; |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
1028
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
=head1 NAME |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
Net::Lyskom::TextStat - text information object. |
15
|
|
|
|
|
|
|
|
16
|
|
|
|
|
|
|
=head1 SYNOPSIS |
17
|
|
|
|
|
|
|
|
18
|
|
|
|
|
|
|
print localtime($obj->creation_time); |
19
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
print "This text has the subject: ",$obj->subject,"\n"; |
21
|
|
|
|
|
|
|
|
22
|
|
|
|
|
|
|
|
23
|
|
|
|
|
|
|
=head1 DESCRIPTION |
24
|
|
|
|
|
|
|
|
25
|
|
|
|
|
|
|
Object returned by the get_text_stat method in the main L |
26
|
|
|
|
|
|
|
class. Also fronts for get_text(), since one often wants the text mass |
27
|
|
|
|
|
|
|
after getting the text meta-information. |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
=head2 Methods |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=over |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=item ->creation_time() |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
Returns the creation time as a L object. |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=item ->author() |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
Returns the person number of the author. |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
=item ->no_of_lines() |
42
|
|
|
|
|
|
|
|
43
|
|
|
|
|
|
|
Returns the number of lines. |
44
|
|
|
|
|
|
|
|
45
|
|
|
|
|
|
|
=item ->no_of_chars() |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
Returns the number of characters. |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=item ->no_of_marks() |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
Returns the number of marks. |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
=item ->misc_info() |
54
|
|
|
|
|
|
|
|
55
|
|
|
|
|
|
|
Returns a compacted list of L object. See the |
56
|
|
|
|
|
|
|
documentation for the class for the meaning of "compacted". |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
=item ->aux_items() |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Returns a list of L objects. |
61
|
|
|
|
|
|
|
|
62
|
|
|
|
|
|
|
=item ->subject() |
63
|
|
|
|
|
|
|
|
64
|
|
|
|
|
|
|
Returns the subject line of the text. Calls get_text(), and caches |
65
|
|
|
|
|
|
|
both the subject and body internally. Both this method and the |
66
|
|
|
|
|
|
|
following one always fetch the entire text. If you want something |
67
|
|
|
|
|
|
|
else, call get_text() yourself. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
If the fetched text has a content-type AuxItem, and the running Perl |
70
|
|
|
|
|
|
|
instance knows how to convert from that encoding, the subject will be |
71
|
|
|
|
|
|
|
decoded into Perl's internal representation before being returned. If |
72
|
|
|
|
|
|
|
there is no declared content type or the running Perl can't deal with |
73
|
|
|
|
|
|
|
it, the content will be left untouched. |
74
|
|
|
|
|
|
|
|
75
|
|
|
|
|
|
|
=item ->body() |
76
|
|
|
|
|
|
|
|
77
|
|
|
|
|
|
|
As above, but return the body instead of the subject. |
78
|
|
|
|
|
|
|
|
79
|
|
|
|
|
|
|
=back |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
=cut |
82
|
|
|
|
|
|
|
|
83
|
|
|
|
|
|
|
# Acessors |
84
|
|
|
|
|
|
|
|
85
|
|
|
|
|
|
|
sub creation_time { |
86
|
1
|
|
|
1
|
1
|
579
|
my $s = shift; |
87
|
|
|
|
|
|
|
|
88
|
1
|
|
|
|
|
7
|
return $s->{creation_time}; |
89
|
|
|
|
|
|
|
} |
90
|
|
|
|
|
|
|
|
91
|
|
|
|
|
|
|
sub author { |
92
|
0
|
|
|
0
|
1
|
0
|
my $s = shift; |
93
|
|
|
|
|
|
|
|
94
|
0
|
|
|
|
|
0
|
return $s->{author}; |
95
|
|
|
|
|
|
|
} |
96
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub no_of_lines { |
98
|
0
|
|
|
0
|
1
|
0
|
my $s =shift; |
99
|
|
|
|
|
|
|
|
100
|
0
|
|
|
|
|
0
|
return $s->{no_of_lines}; |
101
|
|
|
|
|
|
|
} |
102
|
|
|
|
|
|
|
|
103
|
|
|
|
|
|
|
sub no_of_chars { |
104
|
0
|
|
|
0
|
1
|
0
|
my $s = shift; |
105
|
|
|
|
|
|
|
|
106
|
0
|
|
|
|
|
0
|
return $s->{no_of_chars}; |
107
|
|
|
|
|
|
|
} |
108
|
|
|
|
|
|
|
|
109
|
|
|
|
|
|
|
sub no_of_marks { |
110
|
0
|
|
|
0
|
1
|
0
|
my $s = shift; |
111
|
|
|
|
|
|
|
|
112
|
0
|
|
|
|
|
0
|
return $s->{no_of_marks}; |
113
|
|
|
|
|
|
|
} |
114
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
sub misc_info { |
116
|
0
|
|
|
0
|
1
|
0
|
my $s =shift; |
117
|
|
|
|
|
|
|
|
118
|
0
|
|
|
|
|
0
|
return @{$s->{misc_info}}; |
|
0
|
|
|
|
|
0
|
|
119
|
|
|
|
|
|
|
} |
120
|
|
|
|
|
|
|
|
121
|
|
|
|
|
|
|
sub aux_items { |
122
|
1
|
|
|
1
|
1
|
3
|
my $s =shift; |
123
|
|
|
|
|
|
|
|
124
|
1
|
|
|
|
|
4
|
return @{$s->{aux_item}}; |
|
1
|
|
|
|
|
5
|
|
125
|
|
|
|
|
|
|
} |
126
|
|
|
|
|
|
|
|
127
|
|
|
|
|
|
|
sub _fetch_subject_and_body { |
128
|
1
|
|
|
1
|
|
2
|
my $s = shift; |
129
|
|
|
|
|
|
|
|
130
|
1
|
50
|
|
|
|
7
|
my $raw = $s->{connection}->get_text(text => $s->{textno}) or croak; |
131
|
|
|
|
|
|
|
|
132
|
1
|
|
|
|
|
8
|
my ($ct) = grep {$_->tag == 1} $s->aux_items; |
|
0
|
|
|
|
|
0
|
|
133
|
1
|
50
|
|
|
|
5
|
if ($ct) { |
134
|
0
|
|
|
|
|
0
|
my ($charset) = $ct->data =~ m|charset=([^;]+);?|i; |
135
|
0
|
0
|
|
|
|
0
|
if ($charset) { |
136
|
0
|
|
|
|
|
0
|
eval { |
137
|
0
|
|
|
|
|
0
|
$raw = decode($charset, $raw); |
138
|
|
|
|
|
|
|
}; |
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
} |
141
|
|
|
|
|
|
|
|
142
|
1
|
|
|
|
|
6
|
my ($subj, $body) = split(/\n/, $raw, 2); |
143
|
1
|
|
|
|
|
3
|
$s->{subject} = $subj; |
144
|
1
|
|
|
|
|
4
|
$s->{body} = $body; |
145
|
|
|
|
|
|
|
} |
146
|
|
|
|
|
|
|
|
147
|
|
|
|
|
|
|
sub subject { |
148
|
1
|
|
|
1
|
1
|
2
|
my $s = shift; |
149
|
|
|
|
|
|
|
|
150
|
1
|
50
|
|
|
|
6
|
return $s->{subject} if exists($s->{subject}); |
151
|
1
|
50
|
33
|
|
|
11
|
return undef unless $s->{connection} && $s->{textno}; |
152
|
|
|
|
|
|
|
|
153
|
1
|
|
|
|
|
6
|
$s->_fetch_subject_and_body(); |
154
|
|
|
|
|
|
|
|
155
|
1
|
|
|
|
|
11
|
return $s->{subject}; |
156
|
|
|
|
|
|
|
} |
157
|
|
|
|
|
|
|
|
158
|
|
|
|
|
|
|
sub body { |
159
|
0
|
|
|
0
|
1
|
0
|
my $s = shift; |
160
|
|
|
|
|
|
|
|
161
|
0
|
0
|
|
|
|
0
|
return $s->{body} if exists($s->{body}); |
162
|
0
|
0
|
0
|
|
|
0
|
return undef unless $s->{connection} && $s->{textno}; |
163
|
|
|
|
|
|
|
|
164
|
0
|
|
|
|
|
0
|
$s->_fetch_subject_and_body(); |
165
|
|
|
|
|
|
|
|
166
|
0
|
|
|
|
|
0
|
return $s->{body}; |
167
|
|
|
|
|
|
|
} |
168
|
|
|
|
|
|
|
|
169
|
|
|
|
|
|
|
sub new_from_stream { |
170
|
1
|
|
|
1
|
0
|
10
|
my $s = {}; |
171
|
1
|
|
|
|
|
4
|
my $class = shift; |
172
|
1
|
|
|
|
|
3
|
my $conn = shift; |
173
|
1
|
|
|
|
|
2
|
my $textno = shift; |
174
|
1
|
|
|
|
|
3
|
my $ref = shift; |
175
|
|
|
|
|
|
|
|
176
|
1
|
50
|
|
|
|
5
|
$class = ref($class) if ref($class); |
177
|
1
|
|
|
|
|
4
|
bless $s,$class; |
178
|
|
|
|
|
|
|
|
179
|
1
|
|
|
|
|
10
|
$s->{creation_time} = Net::Lyskom::Time->new_from_stream($ref); |
180
|
1
|
|
|
|
|
3
|
$s->{author} = shift @{$ref}; |
|
1
|
|
|
|
|
3
|
|
181
|
1
|
|
|
|
|
3
|
$s->{no_of_lines} = shift @{$ref}; |
|
1
|
|
|
|
|
3
|
|
182
|
1
|
|
|
|
|
2
|
$s->{no_of_chars} = shift @{$ref}; |
|
1
|
|
|
|
|
4
|
|
183
|
1
|
|
|
|
|
2
|
$s->{no_of_marks} = shift @{$ref}; |
|
1
|
|
|
|
|
2
|
|
184
|
1
|
|
|
15
|
|
14
|
$s->{misc_info} = [Net::Lyskom::MiscInfo->compact(parse_array_stream(sub{Net::Lyskom::MiscInfo->new_from_stream(@_)},$ref))]; |
|
15
|
|
|
|
|
49
|
|
185
|
1
|
|
|
0
|
|
24
|
$s->{aux_item} = [parse_array_stream(sub{Net::Lyskom::AuxItem->new_from_stream(@_)},$ref)]; |
|
0
|
|
|
|
|
0
|
|
186
|
|
|
|
|
|
|
|
187
|
1
|
|
|
|
|
4
|
$s->{connection} = $conn; |
188
|
1
|
|
|
|
|
4
|
$s->{textno} = $textno; |
189
|
1
|
|
|
|
|
11
|
return $s; |
190
|
|
|
|
|
|
|
} |
191
|
|
|
|
|
|
|
|
192
|
|
|
|
|
|
|
return 1; |