| 1 | package Net::Lyskom::TextStat; | ||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use base qw{Net::Lyskom::Object}; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 3 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 5 | |||||||||||||||||||||||||||||
| 6 | 1 | ▶ | use Net::Lyskom::Util qw{:all}; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 7 | 1 | ▶ | use Net::Lyskom::MiscInfo; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 8 | 1 | ▶ | use Net::Lyskom::AuxItem; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 9 | 1 | ▶ | use Carp; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 10 | 1 | ▶ | use Encode; | ||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 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<Net::Lyskom> | ||||||||||||||||||||||||||||
| 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<Net::Lyskom::Time> 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<Net::Lyskom::MiscInfo> 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<Net::Lyskom::AuxInfo> 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 | 1 | ▶ | sub creation_time { | ||||||||||||||||||||||||||
|
Subroutine
creation_time: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 86 | 1 | my $s = shift; | |||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||
| 88 | 1 | return $s->{creation_time}; | |||||||||||||||||||||||||||
| 89 | } | ||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||
| 91 | 0 | ▶ | sub author { | ||||||||||||||||||||||||||
|
Subroutine
author: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 92 | 0 | my $s = shift; | |||||||||||||||||||||||||||
| 93 | |||||||||||||||||||||||||||||
| 94 | 0 | return $s->{author}; | |||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||
| 97 | 0 | ▶ | sub no_of_lines { | ||||||||||||||||||||||||||
|
Subroutine
no_of_lines: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 98 | 0 | my $s =shift; | |||||||||||||||||||||||||||
| 99 | |||||||||||||||||||||||||||||
| 100 | 0 | return $s->{no_of_lines}; | |||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||
| 103 | 0 | ▶ | sub no_of_chars { | ||||||||||||||||||||||||||
|
Subroutine
no_of_chars: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 104 | 0 | my $s = shift; | |||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||
| 106 | 0 | return $s->{no_of_chars}; | |||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||
| 109 | 0 | ▶ | sub no_of_marks { | ||||||||||||||||||||||||||
|
Subroutine
no_of_marks: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 110 | 0 | my $s = shift; | |||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||
| 112 | 0 | return $s->{no_of_marks}; | |||||||||||||||||||||||||||
| 113 | } | ||||||||||||||||||||||||||||
| 114 | |||||||||||||||||||||||||||||
| 115 | 0 | ▶ | sub misc_info { | ||||||||||||||||||||||||||
|
Subroutine
misc_info: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||
| 116 | 0 | my $s =shift; | |||||||||||||||||||||||||||
| 117 | |||||||||||||||||||||||||||||
| 118 | 0 | return @{$s->{misc_info}}; | |||||||||||||||||||||||||||
| 119 | } | ||||||||||||||||||||||||||||
| 120 | |||||||||||||||||||||||||||||
| 121 | 1 | ▶ | sub aux_items { | ||||||||||||||||||||||||||
|
Subroutine
aux_items: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||
| 122 | 1 | my $s =shift; | |||||||||||||||||||||||||||
| 123 | |||||||||||||||||||||||||||||
| 124 | 1 | return @{$s->{aux_item}}; | |||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||
| 126 | |||||||||||||||||||||||||||||
| 127 | 1 | ▶ | sub _fetch_subject_and_body { | ||||||||||||||||||||||||||
|
Subroutine
_fetch_subject_and_body: called CC=4 SCAR=17.9
| |||||||||||||||||||||||||||||
| 128 | 1 | my $s = shift; | |||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||
| 130 | 1 | ▶ | my $raw = $s->{connection}->get_text(text => $s->{textno}) or croak; | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 131 | |||||||||||||||||||||||||||||
| 132 | 0 | my ($ct) = grep {$_->tag == 1} $s->aux_items; | |||||||||||||||||||||||||||
| 133 | 1 | ▶ | if ($ct) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 134 | 0 | my ($charset) = $ct->data =~ m|charset=([^;]+);?|i; | |||||||||||||||||||||||||||
| 135 | 0 | ▶ | if ($charset) { | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 136 | 0 | eval { | |||||||||||||||||||||||||||
| 137 | 0 | $raw = decode($charset, $raw); | |||||||||||||||||||||||||||
| 138 | }; | ||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||
| 140 | } | ||||||||||||||||||||||||||||
| 141 | |||||||||||||||||||||||||||||
| 142 | 1 | my ($subj, $body) = split(/\n/, $raw, 2); | |||||||||||||||||||||||||||
| 143 | 1 | $s->{subject} = $subj; | |||||||||||||||||||||||||||
| 144 | 1 | $s->{body} = $body; | |||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||
| 147 | 1 | ▶ | sub subject { | ||||||||||||||||||||||||||
|
Subroutine
subject: called CC=4 SCAR=15.2
Pod
documented
| |||||||||||||||||||||||||||||
| 148 | 1 | my $s = shift; | |||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||
| 150 | 1 | ▶ | return $s->{subject} if exists($s->{subject}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 151 | 1 | ▶ | return undef unless $s->{connection} && $s->{textno}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition33%1/3
$s->{"connection"} and $s->{"textno"}
MC/DC0%0/2
$s->{"connection"} and $s->{"textno"}
$s->{"connection"}
$s->{"textno"}
Truth table33%1/3
A and B
A= $s->{"connection"}B= $s->{"textno"}
| |||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||
| 153 | 1 | $s->_fetch_subject_and_body(); | |||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||
| 155 | 1 | return $s->{subject}; | |||||||||||||||||||||||||||
| 156 | } | ||||||||||||||||||||||||||||
| 157 | |||||||||||||||||||||||||||||
| 158 | 0 | ▶ | sub body { | ||||||||||||||||||||||||||
|
Subroutine
body: not called CC=4 SCAR=30.0
Pod
documented
| |||||||||||||||||||||||||||||
| 159 | 0 | my $s = shift; | |||||||||||||||||||||||||||
| 160 | |||||||||||||||||||||||||||||
| 161 | 0 | ▶ | return $s->{body} if exists($s->{body}); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 162 | 0 | ▶ | return undef unless $s->{connection} && $s->{textno}; | ||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$s->{"connection"} and $s->{"textno"}
MC/DC0%0/2
$s->{"connection"} and $s->{"textno"}
$s->{"connection"}
$s->{"textno"}
Truth table0%0/3
A and B
A= $s->{"connection"}B= $s->{"textno"}
| |||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||
| 164 | 0 | $s->_fetch_subject_and_body(); | |||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||
| 166 | 0 | return $s->{body}; | |||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||
| 169 | 1 | ▶ | sub new_from_stream { | ||||||||||||||||||||||||||
|
Subroutine
new_from_stream: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||
| 170 | 1 | my $s = {}; | |||||||||||||||||||||||||||
| 171 | 1 | my $class = shift; | |||||||||||||||||||||||||||
| 172 | 1 | my $conn = shift; | |||||||||||||||||||||||||||
| 173 | 1 | my $textno = shift; | |||||||||||||||||||||||||||
| 174 | 1 | my $ref = shift; | |||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||
| 176 | 1 | ▶ | $class = ref($class) if ref($class); | ||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||
| 177 | 1 | bless $s,$class; | |||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||
| 179 | 1 | $s->{creation_time} = Net::Lyskom::Time->new_from_stream($ref); | |||||||||||||||||||||||||||
| 180 | 1 | $s->{author} = shift @{$ref}; | |||||||||||||||||||||||||||
| 181 | 1 | $s->{no_of_lines} = shift @{$ref}; | |||||||||||||||||||||||||||
| 182 | 1 | $s->{no_of_chars} = shift @{$ref}; | |||||||||||||||||||||||||||
| 183 | 1 | $s->{no_of_marks} = shift @{$ref}; | |||||||||||||||||||||||||||
| 184 | 1 | ▶ | $s->{misc_info} = [Net::Lyskom::MiscInfo->compact(parse_array_stream(sub{Net::Lyskom::MiscInfo->new_from_stream(@_)},$ref))]; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||
| 185 | 0 | ▶ | $s->{aux_item} = [parse_array_stream(sub{Net::Lyskom::AuxItem->new_from_stream(@_)},$ref)]; | ||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=1.2
| |||||||||||||||||||||||||||||
| 186 | |||||||||||||||||||||||||||||
| 187 | 1 | $s->{connection} = $conn; | |||||||||||||||||||||||||||
| 188 | 1 | $s->{textno} = $textno; | |||||||||||||||||||||||||||
| 189 | 1 | return $s; | |||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||
| 192 | 1 | return 1; | |||||||||||||||||||||||||||