Lyskom/TextMapping.pm

filter: Statementstmt 67.8% 40 / 59 Branchbran 50.0% 3 / 6 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 53.8% 7 / 13 Podpod 85.7% 6 / 7 totaltotal 65.8% 56 / 85 CC 6 SCAR 11.3
CC
6
Cov
66%
new_from_stream
6.3
range_begin
2.0
range_end
2.0
CRAP 3.1
« Lyskom/Object.pm ↑ Summary Lyskom/Member.pm »
1 package Net::Lyskom::TextMapping;
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  
8 =head1 NAME
9  
10 Net::Lyskom::TextMapping - represents a text_mapping
11  
12 =head1 SYNOPSIS
13  
14 $global_no = $obj->global(4711);
15  
16 @globals = $obj->global_text_numbers;
17  
18 @locals = $obj->local_text_numbers;
19  
20 =head1 DESCRIPTION
21  
22 Holds information on mappings between local and global text numbers for
23 a conference.
24  
25 =head2 Methods
26  
27 =over
28  
29 =item ->range_begin()
30  
31 Returns the first local text number that this mapping has information on.
32  
33 =item ->range_end()
34  
35 Returns the first local text number that this mapping does B<not> hold
36 information on.
37  
38 =item ->later_texts_exist()
39  
40 Returns true if the conference has local numbers beyond those detailed
41 in this mapping.
42  
43 =item ->global($no)
44  
45 Takes a local text number and returns the corresponding global text number,
46 or undef if the local number is nonexistant (or just not included in this
47 mapping).
48  
49 =item ->local_text_numbers()
50  
51 Returns a list of all local text numbers in this mapping, in strictly
52 ascending order.
53  
54 =item ->global_text_numbers()
55  
56 Returns a list of all global text numbers in this mapping, in ascending
57 B<local> number order.
58  
59 =back
60  
61 =cut
62  
63 0 ▶sub range_begin {my $s = shift; return $s->{range_begin}};
Subroutine range_begin: not called CC=1 SCAR=6.9
Pod documented
64 0 ▶sub range_end {my $s = shift; return $s->{range_end}};
Subroutine range_end: not called CC=1 SCAR=6.9
Pod documented
65 0 ▶sub later_texts_exist {my $s = shift; return $s->{later_texts_exist}};
Subroutine later_texts_exist: not called CC=1 SCAR=6.9
Pod documented
66  
67 1 ▶sub global {
Subroutine global: called CC=1 SCAR=0.0
Pod documented
68 1 my $s = shift;
69  
70 1 return $s->{_l2ghash}{$_[0]};
71 }
72  
73 0 ▶sub local_text_numbers {
Subroutine local_text_numbers: not called CC=1 SCAR=6.9
Pod documented
74 0 my $s = shift;
75  
76 0 return sort {$a <=> $b} keys %{$s->{_l2ghash}};
77 }
78  
79 0 ▶sub global_text_numbers {
Subroutine global_text_numbers: not called CC=1 SCAR=6.9
Pod documented
80 0 my $s = shift;
81  
82 0 return map {$s->{_l2ghash}{$_}} sort {$a <=> $b} keys %{$s->{_l2ghash}};
83 }
84  
85  
86 1 ▶sub new_from_stream {
Subroutine new_from_stream: called CC=6 SCAR=18.4
Pod undocumented
87 1 my $s = {};
88 1 my $class = shift;
89 1 my $ref = shift;
90 1 my @pairs;
91  
92 1 ▶ $class = ref($class) if ref($class);
Branch: 1 branch
BranchTrueFalseTotal
if ref $class 0 1 1
93 1 bless $s,$class;
94  
95 1 $s->{range_begin} = shift @{$ref};
96 1 $s->{range_end} = shift @{$ref};
97 1 $s->{later_texts_exist} = shift @{$ref};
98  
99 1 ▶ if (shift @{$ref}) {
Branch: 1 branch
BranchTrueFalseTotal
if (shift @{$ref;}) { } 1 0 1
100 # true, so it's a TextList
101 1 my $local_no = shift @{$ref};
102 1 ▶ my @texts = parse_array_stream(sub{shift @{$_[0]}},$ref);
Subroutine __ANON__: called CC=1 SCAR=0.0
103 1 foreach (@texts) {
104 1 ▶ push @pairs,[$local_no,$_] if $_;
Branch: 1 branch
BranchTrueFalseTotal
if $_ 1 0 1
105 1 $local_no++;
106 }
107 } else {
108 # false, so it's an ARRAY of TextNumberPair
109 0 ▶ @pairs = parse_array_stream(sub{[shift @{$_[0]},shift @{$_[0]}]},$ref);
Subroutine __ANON__: not called CC=1 SCAR=6.9
110 }
111  
112 1 foreach (@pairs) {
113 1 $s->{_l2ghash}{$_->[0]} = $_->[1]
114 }
115  
116 1 return $s;
117 }
118  
119 1 1;
« Lyskom/Object.pm ↑ Summary Lyskom/Member.pm »