blib/lib/Bible/Reference.pm

filter: Statementstmt 99.2% 407 / 410 Branchbran 89.0% 162 / 182 Conditioncond 77.6% 97 / 125 MC/DCmcdc 53.8% 35 / 65 Subroutinesub 97.2% 35 / 36 Podpod 100% 17 / 17 totaltotal 90.1% 753 / 835 CC 167 SCAR 28.6
CC
167
Cov
93%
as_array
35.6
__ANON__
26.2
in
25.0
CRAP 17.5
↑ Summary
1 package Bible::Reference;
2 # ABSTRACT: Simple Bible reference parser, tester, and canonicalizer
3  
4 3 ▶use 5.022;
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 3 ▶use exact;
Subroutine BEGIN: called CC=1 SCAR=0.0
7 3 ▶use exact::class;
Subroutine BEGIN: called CC=1 SCAR=0.0
8  
9 3 our $VERSION = '1.20'; # VERSION
10  
11 3 has acronyms => 0;
12 3 has sorting => 1;
13 3 has require_chapter_match => 0;
14 3 has require_verse_match => 0;
15 3 has require_book_ucfirst => 0;
16 3 has minimum_book_length => 3;
17 3 has add_detail => 0;
18 3 has simplify => 0;
19  
20 3 my $bibles = {
21 ESV => [
22 [
23 [ 'Genesis', 'Ge', 'Gn', 'Gen' ],
24 [ 'Exodus', 'Ex', 'Exo' ],
25 [ 'Leviticus', 'Lv', 'Lev' ],
26 [ 'Numbers', 'Nu', 'Nm', 'Num' ],
27 [ 'Deuteronomy', 'Dt', 'Deu' ],
28 [ 'Joshua', 'Jsh', 'Jos', 'Josh' ],
29 [ 'Judges', 'Jdg', 'Judg' ],
30 [ 'Ruth', 'Ru', 'Rut' ],
31 [ '1 Samuel', '1Sa', '1Sm', '1Sam' ],
32 [ '2 Samuel', '2Sa', '2Sm', '2Sam' ],
33 [ '1 Kings', '1Ki', '1Kg', '1Kgs', '1Kin' ],
34 [ '2 Kings', '2Ki', '2Kg', '2Kgs', '2Kin' ],
35 [ '1 Chronicles', '1Ch', '1Cr', '1Chr' ],
36 [ '2 Chronicles', '2Ch', '2Cr', '2Chr' ],
37 [ 'Ezra', 'Ezr' ],
38 [ 'Nehemiah', 'Ne', 'Neh' ],
39 [ 'Esther', 'Est', 'Esth' ],
40 [ 'Job', 'Jb', 'Jo', 'Job' ],
41 [ 'Psalm', 'Ps', 'Psa', 'Psalms' ],
42 [ 'Proverbs', 'Pr', 'Prv', 'Pro', 'Prov' ],
43 [ 'Ecclesiastes', 'Ec', 'Ecc', 'Eccl' ],
44 [ 'Song of Solomon', 'SS', 'SoS', 'Song of Songs' ],
45 [ 'Isaiah', 'Is', 'Isa' ],
46 [ 'Jeremiah', 'Jr', 'Jer' ],
47 [ 'Lamentations', 'Lm', 'La', 'Lam' ],
48 [ 'Ezekiel', 'Ezk', 'Ez', 'Eze', 'Ezek' ],
49 [ 'Daniel', 'Da', 'Dn', 'Dan' ],
50 [ 'Hosea', 'Ho', 'Hs', 'Hos' ],
51 [ 'Joel', 'Jl', 'Joe', 'Joel' ],
52 [ 'Amos', 'Am', 'Amo' ],
53 [ 'Obadiah', 'Ob', 'Oba' ],
54 [ 'Jonah', 'Jnh', 'Jon', 'Jona' ],
55 [ 'Micah', 'Mi', 'Mic' ],
56 [ 'Nahum', 'Na', 'Nah' ],
57 [ 'Habakkuk', 'Hab' ],
58 [ 'Zephaniah', 'Zp', 'Zep', 'Zph', 'Zeph' ],
59 [ 'Haggai', 'Hg', 'Hag' ],
60 [ 'Zechariah', 'Zec', 'Zch', 'Zech' ],
61 [ 'Malachi', 'Ml', 'Mal' ],
62 [ 'Matthew', 'Mt', 'Mat', 'Matt' ],
63 [ 'Mark', 'Mk', 'Mr', 'Mc', 'Mark' ],
64 [ 'Luke', 'Lk', 'Lu', 'Luk' ],
65 [ 'John', 'Joh' ],
66 [ 'Acts', 'Ac', 'Act' ],
67 [ 'Romans', 'Ro', 'Rm', 'Rom', 'Roms' ],
68 [ '1 Corinthians', '1Co', '1Cor' ],
69 [ '2 Corinthians', '2Co', '2Cor' ],
70 [ 'Galatians', 'Ga', 'Gl', 'Gal' ],
71 [ 'Ephesians', 'Ep', 'Eph' ],
72 [ 'Philippians', 'Php', 'Phil' ],
73 [ 'Colossians', 'Cl', 'Col' ],
74 [ '1 Thessalonians', '1Th', '1The' ],
75 [ '2 Thessalonians', '2Th', '2The' ],
76 [ '1 Timothy', '1Ti', '1Tm', '1Tim' ],
77 [ '2 Timothy', '2Ti', '2Tm', '2Tim' ],
78 [ 'Titus', 'Ti', 'Tt' ],
79 [ 'Philemon', 'Phm', 'Phlm', 'Phile' ],
80 [ 'Hebrews', 'He', 'Heb' ],
81 [ 'James', 'Jam', 'Jms', 'Jas' ],
82 [ '1 Peter', '1Pt', '1Pe', '1Pet' ],
83 [ '2 Peter', '2Pt', '2Pe', '2Pet' ],
84 [ '1 John', '1Jn', '1Jo', '1Joh' ],
85 [ '2 John', '2Jn', '2Jo', '2Joh' ],
86 [ '3 John', '3Jn', '3Jo', '3Joh' ],
87 [ 'Jude', 'Jud', 'Jude' ],
88 [ 'Revelation', 'Rv', 'Rev' ],
89 ],
90 [
91 [
92 31, 25, 24, 26, 32, 22, 24, 22, 29, 32, 32, 20, 18, 24, 21, 16, 27, 33, 38, 18, 34, 24, 20,
93 67, 34, 35, 46, 22, 35, 43, 55, 32, 20, 31, 29, 43, 36, 30, 23, 23, 57, 38, 34, 34, 28, 34,
94 31, 22, 33, 26,
95 ],
96 [
97 22, 25, 22, 31, 23, 30, 25, 32, 35, 29, 10, 51, 22, 31, 27, 36, 16, 27, 25, 26, 36, 31, 33,
98 18, 40, 37, 21, 43, 46, 38, 18, 35, 23, 35, 35, 38, 29, 31, 43, 38,
99 ],
100 [
101 17, 16, 17, 35, 19, 30, 38, 36, 24, 20, 47, 8, 59, 57, 33, 34, 16, 30, 37, 27, 24, 33, 44,
102 23, 55, 46, 34,
103 ],
104 [
105 54, 34, 51, 49, 31, 27, 89, 26, 23, 36, 35, 16, 33, 45, 41, 50, 13, 32, 22, 29, 35, 41, 30,
106 25, 18, 65, 23, 31, 40, 16, 54, 42, 56, 29, 34, 13,
107 ],
108 [
109 46, 37, 29, 49, 33, 25, 26, 20, 29, 22, 32, 32, 18, 29, 23, 22, 20, 22, 21, 20, 23, 30, 25,
110 22, 19, 19, 26, 68, 29, 20, 30, 52, 29, 12,
111 ],
112 [
113 18, 24, 17, 24, 15, 27, 26, 35, 27, 43, 23, 24, 33, 15, 63, 10, 18, 28, 51, 9, 45, 34, 16,
114 33,
115 ],
116 [ 36, 23, 31, 24, 31, 40, 25, 35, 57, 18, 40, 15, 25, 20, 20, 31, 13, 31, 30, 48, 25 ],
117 [ 22, 23, 18, 22 ],
118 [
119 28, 36, 21, 22, 12, 21, 17, 22, 27, 27, 15, 25, 23, 52, 35, 23, 58, 30, 24, 42, 15, 23, 29,
120 22, 44, 25, 12, 25, 11, 31, 13,
121 ],
122 [
123 27, 32, 39, 12, 25, 23, 29, 18, 13, 19, 27, 31, 39, 33, 37, 23, 29, 33, 43, 26, 22, 51, 39,
124 25,
125 ],
126 [ 53, 46, 28, 34, 18, 38, 51, 66, 28, 29, 43, 33, 34, 31, 34, 34, 24, 46, 21, 43, 29, 53 ],
127 [
128 18, 25, 27, 44, 27, 33, 20, 29, 37, 36, 21, 21, 25, 29, 38, 20, 41, 37, 37, 21, 26, 20, 37,
129 20, 30,
130 ],
131 [
132 54, 55, 24, 43, 26, 81, 40, 40, 44, 14, 47, 40, 14, 17, 29, 43, 27, 17, 19, 8, 30, 19, 32,
133 31, 31, 32, 34, 21, 30,
134 ],
135 [
136 17, 18, 17, 22, 14, 42, 22, 18, 31, 19, 23, 16, 22, 15, 19, 14, 19, 34, 11, 37, 20, 12, 21,
137 27, 28, 23, 9, 27, 36, 27, 21, 33, 25, 33, 27, 23,
138 ],
139 [ 11, 70, 13, 24, 17, 22, 28, 36, 15, 44 ],
140 [ 11, 20, 32, 23, 19, 19, 73, 18, 38, 39, 36, 47, 31 ],
141 [ 22, 23, 15, 17, 14, 14, 10, 17, 32, 3 ],
142 [
143 22, 13, 26, 21, 27, 30, 21, 22, 35, 22, 20, 25, 28, 22, 35, 22, 16, 21, 29, 29, 34, 30, 17,
144 25, 6, 14, 23, 28, 25, 31, 40, 22, 33, 37, 16, 33, 24, 41, 30, 24, 34, 17,
145 ],
146 [
147 6, 12, 8, 8, 12, 10, 17, 9, 20, 18, 7, 8, 6, 7, 5, 11, 15, 50, 14, 9, 13, 31, 6,
148 10, 22, 12, 14, 9, 11, 12, 24, 11, 22, 22, 28, 12, 40, 22, 13, 17, 13, 11, 5, 26, 17, 11,
149 9, 14, 20, 23, 19, 9, 6, 7, 23, 13, 11, 11, 17, 12, 8, 12, 11, 10, 13, 20, 7, 35, 36,
150 5, 24, 20, 28, 23, 10, 12, 20, 72, 13, 19, 16, 8, 18, 12, 13, 17, 7, 18, 52, 17, 16, 15,
151 5, 23, 11, 13, 12, 9, 9, 5, 8, 28, 22, 35, 45, 48, 43, 13, 31, 7, 10, 10, 9, 8, 18,
152 19, 2, 29, 176, 7, 8, 9, 4, 8, 5, 6, 5, 6, 8, 8, 3, 18, 3, 3, 21, 26, 9, 8,
153 24, 13, 10, 7, 12, 15, 21, 10, 20, 14, 9, 6,
154 ],
155 [
156 33, 22, 35, 27, 23, 35, 27, 36, 18, 32, 31, 28, 25, 35, 33, 33, 28, 24, 29, 30, 31, 29, 35,
157 34, 28, 28, 27, 28, 27, 33, 31,
158 ],
159 [ 18, 26, 22, 16, 20, 12, 29, 17, 18, 20, 10, 14 ],
160 [ 17, 17, 11, 16, 16, 13, 13, 14 ],
161 [
162 31, 22, 26, 6, 30, 13, 25, 22, 21, 34, 16, 6, 22, 32, 9, 14, 14, 7, 25, 6, 17, 25, 18,
163 23, 12, 21, 13, 29, 24, 33, 9, 20, 24, 17, 10, 22, 38, 22, 8, 31, 29, 25, 28, 28, 25, 13,
164 15, 22, 26, 11, 23, 15, 12, 17, 13, 12, 21, 14, 21, 22, 11, 12, 19, 12, 25, 24,
165 ],
166 [
167 19, 37, 25, 31, 31, 30, 34, 22, 26, 25, 23, 17, 27, 22, 21, 21, 27, 23, 15, 18, 14, 30, 40,
168 10, 38, 24, 22, 17, 32, 24, 40, 44, 26, 22, 19, 32, 21, 28, 18, 16, 18, 22, 13, 30, 5, 28,
169 7, 47, 39, 46, 64, 34,
170 ],
171 [ 22, 22, 66, 22, 22 ],
172 [
173 28, 10, 27, 17, 17, 14, 27, 18, 11, 22, 25, 28, 23, 23, 8, 63, 24, 32, 14, 49, 32, 31, 49,
174 27, 17, 21, 36, 26, 21, 26, 18, 32, 33, 31, 15, 38, 28, 23, 29, 49, 26, 20, 27, 31, 25, 24,
175 23, 35,
176 ],
177 [ 21, 49, 30, 37, 31, 28, 28, 27, 27, 21, 45, 13 ],
178 [ 11, 23, 5, 19, 15, 11, 16, 14, 17, 15, 12, 14, 16, 9 ],
179 [ 20, 32, 21 ],
180 [ 15, 16, 15, 13, 27, 14, 17, 14, 15 ],
181 [ 21 ],
182 [ 17, 10, 10, 11 ],
183 [ 16, 13, 12, 13, 15, 16, 20 ],
184 [ 15, 13, 19 ],
185 [ 17, 20, 19 ],
186 [ 18, 15, 20 ],
187 [ 15, 23 ],
188 [ 21, 13, 10, 14, 11, 15, 14, 23, 17, 12, 17, 14, 9, 21 ],
189 [ 14, 17, 18, 6 ],
190 [
191 25, 23, 17, 25, 48, 34, 29, 34, 38, 42, 30, 50, 58, 36, 39, 28, 27, 35, 30, 34, 46, 46, 39,
192 51, 46, 75, 66, 20,
193 ],
194 [ 45, 28, 35, 41, 43, 56, 37, 38, 50, 52, 33, 44, 37, 72, 47, 20 ],
195 [
196 80, 52, 38, 44, 39, 49, 50, 56, 62, 42, 54, 59, 35, 35, 32, 31, 37, 43, 48, 47, 38, 71, 56,
197 53,
198 ],
199 [ 51, 25, 36, 54, 47, 71, 53, 59, 41, 42, 57, 50, 38, 31, 27, 33, 26, 40, 42, 31, 25 ],
200 [
201 26, 47, 26, 37, 42, 15, 60, 40, 43, 48, 30, 25, 52, 28, 41, 40, 34, 28, 41, 38, 40, 30, 35,
202 27, 27, 32, 44, 31,
203 ],
204 [ 32, 29, 31, 25, 21, 23, 25, 39, 33, 21, 36, 21, 14, 23, 33, 27 ],
205 [ 31, 16, 23, 21, 13, 20, 40, 13, 27, 33, 34, 31, 13, 40, 58, 24 ],
206 [ 24, 17, 18, 18, 21, 18, 16, 24, 15, 18, 33, 21, 14 ],
207 [ 24, 21, 29, 31, 26, 18 ],
208 [ 23, 22, 21, 32, 33, 24 ],
209 [ 30, 30, 21, 23 ],
210 [ 29, 23, 25, 18 ],
211 [ 10, 20, 13, 18, 28 ],
212 [ 12, 17, 18 ],
213 [ 20, 15, 16, 16, 25, 21 ],
214 [ 18, 26, 17, 22 ],
215 [ 16, 15, 15 ],
216 [ 25 ],
217 [ 14, 18, 19, 16, 14, 20, 28, 13, 28, 39, 40, 29, 25 ],
218 [ 27, 26, 18, 17, 20 ],
219 [ 25, 25, 22, 19, 14 ],
220 [ 21, 22, 18 ],
221 [ 10, 29, 24, 21, 21 ],
222 [ 13 ],
223 [ 15 ],
224 [ 25 ],
225 [ 20, 29, 22, 11, 14, 17, 17, 13, 21, 11, 19, 17, 18, 20, 8, 21, 18, 24, 21, 15, 27, 21 ],
226 ],
227 ],
228 };
229  
230 7 ▶sub _build_bible_template ( $source_name, $new_name, $bibles, $books_cb = undef, $verses_cb = undef ) {
Subroutine _build_bible_template: called CC=5 SCAR=16.1
231 7 $bibles->{$new_name} = [ map { [ map { [@$_] } @$_ ] } @{ $bibles->{$source_name} } ];
232 7 ▶ $books_cb->( $bibles->{$new_name}[0] ) if ($books_cb);
Branch: 1 branch
BranchTrueFalseTotal
if $books_cb 6 1 7
233 7 ▶ $verses_cb->( $bibles->{$new_name}[1] ) if ($verses_cb);
Branch: 1 branch
BranchTrueFalseTotal
if $verses_cb 6 1 7
234 7 return;
235 }
236  
237 _build_bible_template(
238 'ESV' => 'RSVCE',
239 $bibles,
240 3 ▶ sub ($books) {
Subroutine __ANON__: called CC=1 SCAR=0.0
241 3 splice( @$books, 25, 0,
242 [ 'Baruch', 'Ba', 'Br', 'Bar' ],
243 );
244  
245 3 splice( @$books, 22, 0,
246 [ 'Wisdom', 'Wi', 'Ws', 'Wis' ],
247 [ 'Sirach', 'Si', 'Sr', 'Sir' ],
248 );
249  
250 3 splice( @$books, 17, 0,
251 [ '1 Maccabees', '1Ma', '1Mac' ],
252 [ '2 Maccabees', '2Ma', '2Mac' ],
253 );
254  
255 3 splice( @$books, 16, 0,
256 [ 'Tobit', 'Tb', 'Tob' ],
257 [ 'Judith', 'Judi' ],
258 );
259 },
260 3 ▶ sub ($verses) {
Subroutine __ANON__: called CC=1 SCAR=0.0
261 3 push( @{ $verses->[26] }, 64, 42 );
262 3 splice( @$verses, 25, 0, [ 21, 35, 37, 37, 9, 73 ] );
263 3 splice( @$verses, 22, 0,
264 [ 16, 24, 19, 20, 23, 25, 30, 21, 18, 21, 26, 27, 19, 31, 19, 29, 21, 25, 22 ],
265 [
266 30, 18, 31, 31, 15, 37, 36, 19, 18, 31, 34, 18, 26, 27, 20, 30, 32, 33, 30, 31, 28, 27, 27,
267 34, 26, 29, 30, 26, 28, 25, 31, 24, 31, 26, 20, 26, 31, 34, 35, 30, 23, 25, 33, 23, 26, 20,
268 25, 25, 16, 29, 30,
269 ],
270 );
271 3 splice( @$verses, 16, 1,
272 [ 22, 14, 17, 21, 22, 17, 18, 21, 6, 12, 19, 22, 18, 15 ],
273 [ 16, 28, 10, 15, 24, 21, 32, 36, 14, 23, 23, 20, 20, 19, 13, 25 ],
274 [ 22, 23, 15, 19, 14, 14, 10, 17, 32, 1 ],
275 [ 64, 70, 60, 61, 68, 63, 50, 32, 73, 89, 74, 53, 53, 49, 41, 24 ],
276 [ 36, 32, 40, 50, 27, 31, 42, 36, 29, 38, 38, 45, 26, 46, 39 ],
277 );
278 },
279 3 );
280  
281 _build_bible_template(
282 'ESV' => 'RSV',
283 $bibles,
284 3 ▶ sub ($books) {
Subroutine __ANON__: called CC=1 SCAR=0.0
285 3 push( @$books,
286 [ 'Tobit', 'Tb', 'Tob' ],
287 [ 'Judith', 'Judi', 'Jdt' ],
288 [ 'Greek Esther', 'GkEsth' ],
289 [ 'Wisdom', 'Wi', 'Ws', 'Wis', 'Wisdom of Solomon' ],
290 [ 'Sirach', 'Si', 'Sr', 'Sir', 'Ben Sira', 'Wisdom of Ben Sira' ],
291 [ 'Baruch', 'Ba', 'Br', 'Bar' ],
292 [ 'Letter of Jeremiah', 'LJ', 'Let', 'EpJer' ],
293 [ 'Song of the Three Young Men', 'SgThr', 'Three', 'Prayer of Azariah' ],
294 [ 'Susanna', 'Sus' ],
295 [ 'Bel and the Dragon', 'Bel' ],
296 [ '1 Maccabees', '1Ma', '1Mac', '1Macc' ],
297 [ '2 Maccabees', '2Ma', '2Mac', '2Macc' ],
298 [ '1 Esdras', '1Es', '1Esd', '1Esdr' ],
299 [ 'Prayer of Manasseh', 'PM', 'Pra', 'Man', 'PrMan' ],
300 [ 'Psalm 151', 'Ps151', 'Psa151' ],
301 [ '3 Maccabees', '3Ma', '3Mac', '3Macc' ],
302 [ '2 Esdras', '2Es', '2Esd', '2Esdr' ],
303 [ '4 Maccabees', '4Ma', '4Mac', '4Macc' ],
304 );
305 },
306 3 ▶ sub ($verses) {
Subroutine __ANON__: called CC=1 SCAR=0.0
307 3 push( @$verses,
308 [ 22, 14, 17, 21, 21, 17, 18, 21, 6, 12, 19, 22, 18, 15 ],
309 [ 16, 28, 10, 15, 24, 21, 32, 36, 14, 23, 23, 20, 20, 19, 13, 25 ],
310 [ 22, 23, 15, 19, 14, 14, 10, 17, 32, 1 ],
311 [ 16, 24, 19, 20, 23, 25, 30, 21, 18, 21, 26, 27, 19, 31, 19, 29, 21, 25, 22 ],
312 [
313 30, 18, 31, 31, 15, 37, 36, 19, 18, 31, 34, 18, 26, 27, 20, 30, 32, 33, 30, 31, 28, 27, 27,
314 34, 26, 29, 30, 26, 28, 25, 31, 24, 31, 26, 20, 26, 31, 34, 35, 30, 23, 25, 33, 23, 26, 20,
315 25, 25, 16, 29, 30,
316 ],
317 [ 21, 35, 37, 37, 9 ],
318 [ 73 ],
319 [ 68 ],
320 [ 64 ],
321 [ 42 ],
322 [ 64, 70, 60, 61, 68, 63, 50, 32, 73, 89, 74, 53, 53, 49, 41, 24 ],
323 [ 36, 32, 40, 50, 27, 31, 42, 36, 29, 38, 38, 45, 26, 46, 39 ],
324 [ 58, 30, 24, 63, 73, 34, 15, 96, 55 ],
325 [ 15 ],
326 [ 7 ],
327 [ 29, 33, 30, 21, 51, 41, 23 ],
328 [ 40, 48, 36, 52, 56, 59, 140, 63, 47, 59, 46, 51, 58, 48, 63, 78 ],
329 [ 35, 24, 21, 26, 38, 35, 23, 29, 32, 21, 27, 19, 27, 20, 32, 25, 24, 24 ],
330 );
331 },
332 3 );
333  
334 3 $bibles->{Protestant} = $bibles->{ESV};
335 3 $bibles->{Catholic} = $bibles->{RSVCE};
336 3 $bibles->{Orthodox} = $bibles->{RSV};
337  
338 3 has _bible => 'Protestant';
339 0 ▶has _bible_data => sub { {} };
Subroutine __ANON__: not called CC=1 SCAR=1.2
340 2 ▶has _data => sub { [] };
Subroutine __ANON__: called CC=1 SCAR=0.0
341 4 ▶has _cache => sub { {} };
Subroutine __ANON__: called CC=1 SCAR=0.0
342 4 ▶has _bibles => sub {
Subroutine __ANON__: called CC=1 SCAR=0.0
343 4 return { map { $_ => [ map { [ map { [ @$_] } @$_ ] } @{ $bibles->{$_} } ] } keys %$bibles };
344 3 };
345  
346 27 ▶sub bible ( $self, $name = undef ) {
Subroutine bible: called CC=19 SCAR=29.4
Pod documented
347 27 ▶ return $self->_bible unless ($name);
Branch: 1 branch
BranchTrueFalseTotal
unless $name 6 21 27
348  
349 21 ▶ my $input = lc( $name || '' );
Condition50%1/2
$name || ''
l!l
210
MC/DC0%0/1
$name || ''
$name
Truth table50%1/2
A
A= $name
Aresult
11
00
350 21 my ($bible) = grep { lc $_ eq $input } keys %{ $self->_bibles };
351  
352 21 ▶ croak "Could not determine a valid Bible type from input" unless ($bible);
Branch: 1 branch
BranchTrueFalseTotal
unless $bible 1 20 21
353 20 $self->_bible($bible);
354  
355 20 my $books = [ map { [@$_] } @{ $self->_bibles->{ $self->_bible }[0] } ];
356  
357 20 my $bible_data;
358 20 for my $book_data (@$books) {
359 1418 my ( $book, @acronyms ) = @$book_data;
360  
361 1418 $bible_data->{book_to_acronym}{$book} = $acronyms[0];
362 1418 push( @{ $bible_data->{books} }, $book );
363 }
364 20 my $book_count;
365 20 $bible_data->{book_order} = { map { $_ => ++$book_count } @{ $bible_data->{books} } };
366  
367 20 my $canonical = [ map { $_->[0] } @$books ];
368 20 my $options = { map { shift @$_ => $_ } @$books };
369 my $re_map = { map {
370 20 my $book = $_;
371 1418 my $book_str = $_;
372 1418 ▶ my @prefix = (
Branch: 5 branches
BranchTrueFalseTotal
$book_str =~ s/^(\d)\s//u ? : 369 1049 1418
$1 == 1 ? : 170 199 369
$1 == 2 ? : 170 29 199
$1 == 3 ? : 24 5 29
$1 == 4 ? : 5 0 5
373 ( $book_str =~ s/^(\d)\s// ) ? (
374 (
375 (
376 ( $1 == 1 ) ? ( qw( I First ) ) :
377 ( $1 == 2 ) ? ( qw( II Second ) ) :
378 ( $1 == 3 ) ? ( qw( III Third ) ) :
379 ( $1 == 4 ) ? ( qw( IV Fourth ) ) : ()
380 ),
381 $1 . '*',
382 ),
383 $1,
384 ) : ()
385 );
386  
387 1418 my @letters = split( '', $book_str );
388 1418 my $unique;
389 1418 ▶ while (@letters) {
Branch: 1 branch
BranchTrueFalseTotal
if (@letters) 4463 5 4468
390 4463 $unique .= shift @letters;
391 last if (
392 length $unique >= $self->minimum_book_length
393 and (
394 not @prefix and
395 91922 ▶ scalar( grep { index( $_, $unique ) == 0 } @$canonical ) == 1 or
Condition66%2/3
@prefix and scalar grep({index($_, $prefix[-1] . ' ' . $unique) == 0;} @$canonical) == 1
!ll&&!rl&&r
2140369
MC/DC50%1/2
@prefix and scalar grep({index($_, $prefix[-1] . ' ' . $unique) == 0;} @$canonical) == 1
@prefix scalar grep({index($_, $prefix[-1] . ' ' . $unique) == 0;} @$canonical) == 1
Truth table66%2/3
A and B
A= @prefixB= scalar grep({index($_, $prefix[-1] . ' ' . $unique) == 0;} @$canonical) == 1
ABresult
0X0
100
111
396 @prefix and
397 4463 ▶ scalar( grep { index( $_, $prefix[-1] . ' ' . $unique ) == 0 } @$canonical ) == 1
Branch: 1 branch
BranchTrueFalseTotal
if length $unique >= $self->minimum_book_length and !@prefix && scalar grep({index($_, $unique) == 0;} @$canonical) == 1 || @prefix && scalar grep({index($_, $prefix[-1] . ' ' . $unique) == 0;} @$canonical) == 1 1413 3050 4463
Condition100%9/9
length $unique >= $self->minimum_book_length and !@prefix && scalar grep({index($_, $unique) == 0;} @$canonical) == 1 || @prefix && scalar grep({index($_, $prefix[-1] . ' ' . $unique) == 0;} @$canonical) == 1
!ll&&!rl&&r
28362141413
not @prefix and scalar grep({index($_, $unique) == 0;} @$canonical) == 1 or @prefix and scalar grep({index($_, $prefix[-1] . ' ' . $unique) == 0;} @$canonical) == 1
l!l&&r!l&&!r
1044369214
not @prefix and scalar grep({index($_, $unique) == 0;} @$canonical) == 1
!ll&&!rl&&r
3692141044
MC/DC50%2/4
length $unique >= $self->minimum_book_length and !@prefix && scalar grep({index($_, $unique) == 0;} @$canonical) == 1 || @prefix && scalar grep({index($_, $prefix[-1] . ' ' . $unique) == 0;} @$canonical) == 1
length $unique >= $self->minimum_book_length not @prefix scalar grep({index($_, $unique) == 0;} @$canonical) == 1 @prefix and scalar grep({index($_, $prefix[-1] . ' ' . $unique) == 0;} @$canonical) == 1
Truth table66%4/6
A and not(B) and C or D
A= length $unique >= $self->minimum_book_lengthB= not @prefixC= scalar grep({index($_, $unique) == 0;} @$canonical) == 1D= @prefix and scalar grep({index($_, $prefix[-1] . ' ' . $unique) == 0;} @$canonical) == 1
ABCDresult
0XXX0
10X00
11000
111X1
10X11
11011
398 )
399 );
400 }
401  
402 1418 my @matches = $unique;
403 1418 ▶ push( @matches, $unique .= shift @letters ) while (@letters);
Branch: 1 branch
BranchTrueFalseTotal
@letters and do { push @matches, $unique .= shift(@letters) } 5772 1418 7190
404  
405 @matches = map {
406 1418 my $match = $_;
407  
408 7190 $match .= ')i?(';
409 7190 $match =~ s/^(\w)/$1)i-?(/;
410  
411 7190 ▶ (@prefix) ? ( map { ')' . $_ . ':i?(' . ' ' . $match } @prefix ) : $match;
Branch: 1 branch
BranchTrueFalseTotal
@prefix ? : 2028 5162 7190
412 } @matches;
413  
414 map {
415 16906 my $re = reverse $_;
416  
417 16906 $re =~ s/\*/'[A-z]+'/ge;
418 16906 $re =~ s/\s+/'[\s_]*'/ge;
419  
420 16906 $re => $book;
421 1418 } @matches, @{ $options->{$book} };
422 } @$canonical };
423  
424 20 my @re_parts = sort { length $b <=> length $a } keys %$re_map;
425  
426 20 my $re_refs = '(?i:[\d:,;\s\-]|\bdna\b|\bro\b|&)*\.?';
427 20 my $re_refs_req =
428 '(?i:[\d:,;\s\-]|\bdna\b|\bro\b|&)*' .
429 '(?:\d\s*:\s*\d)' .
430 '(?i:[\d:,;\s\-]|\bdna\b|\bro\b|&)*\.?';
431  
432 20 my $re_refs_string = '\b(' . join( '|', map { $re_refs . $_ } @re_parts ) . ')\b';
433 20 my $re_refs_req_string = '\b(' . join( '|', map { $re_refs_req . $_ } @re_parts ) . ')\b';
434  
435 20 $bible_data->{re_refs_s} = qr/$re_refs_string/;
436 20 $bible_data->{re_refs_sr} = qr/$re_refs_req_string/;
437 20 $bible_data->{re_books_s} = [ map { [ qr/\b$_\b/, $re_map->{$_} ] } @re_parts ];
438  
439 20 $re_refs_string =~ s/\(\?\-?i\)//g;
440 20 $re_refs_req_string =~ s/\(\?\-?i\)//g;
441  
442 20 $bible_data->{re_refs_i} = qr/$re_refs_string/i;
443 20 $bible_data->{re_refs_ir} = qr/$re_refs_req_string/i;
444 $bible_data->{re_books_i} = [ map {
445 20 my $this_book = $re_map->{$_};
446 16906 s/\(\?\-?i\)//g;
447 16906 [ qr/\b$_\b/i, $this_book ];
448 } @re_parts ];
449  
450 $bible_data->{lengths} = {
451 map {
452 1418 $bible_data->{books}[$_] => [ @{ $self->_bibles->{$bible}[1][$_] } ]
453 20 } 0 .. @{ $bible_data->{books} } - 1
454 };
455  
456 20 $self->_bible_data($bible_data);
457 20 return $bible;
458 }
459  
460 4 ▶sub new ( $self, %params ) {
Subroutine new: called CC=2 SCAR=7.6
Pod documented
461 4 $self = $self->SUPER::new(%params);
462 4 ▶ $self->bible( $params{bible} || $self->_bible );
Condition33%1/3
$params{'bible'} || $self->_bible
l!l&&r!l&&!r
040
MC/DC0%0/2
$params{'bible'} || $self->_bible
$params{'bible'} $self->_bible
Truth table33%1/3
A || B
A= $params{'bible'}B= $self->_bible
ABresult
1X1
011
000
463 4 return $self;
464 }
465  
466 213 ▶sub _list ( $start, $stop ) {
Subroutine _list: called CC=4 SCAR=14.0
467 213 ▶ $start++ if ( $start == 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $start == 0 0 213 213
468 213 ▶ $stop++ if ( $stop == 0 );
Branch: 1 branch
BranchTrueFalseTotal
if $stop == 0 0 213 213
469  
470 213 my ( $x, $y ) = sort { $a <=> $b } $start, $stop;
471 213 my @list = $x .. $y;
472 213 ▶ @list = reverse(@list) if ( $x < $start );
Branch: 1 branch
BranchTrueFalseTotal
if $x < $start 11 202 213
473  
474 213 return @list;
475 };
476  
477 187 ▶sub expand_ranges ( $self, $book, $text, $compress = 0 ) {
Subroutine expand_ranges: called CC=3 SCAR=11.0
Pod documented
478 189 ▶ my $expand = sub ( $start, $stop ) {
Subroutine __ANON__: called CC=26 SCAR=32.6
479 189 ▶ my $start_ch = ( $start =~ s/(\d+):// ) ? $1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$start =~ s/(\d+)://u ? : 77 112 189
480 189 ▶ my $stop_ch = ( $stop =~ s/(\d+):// ) ? $1 : 0;
Branch: 1 branch
BranchTrueFalseTotal
$stop =~ s/(\d+)://u ? : 19 170 189
481  
482 189 ▶ if ( not $start_ch and $stop_ch and $start > $stop_ch ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $start_ch and $stop_ch and $start > $stop_ch) 1 188 189
Condition100%6/6
not $start_ch and $stop_ch and $start > $stop_ch
!ll&&!rl&&r
178101
not $start_ch and $stop_ch
!ll&&!rl&&r
7710111
MC/DC100%3/3
not $start_ch and $stop_ch and $start > $stop_ch
not $start_ch $stop_ch $start > $stop_ch
Truth table100%4/4
not(A) and B and C
A= not $start_chB= $stop_chC= $start > $stop_ch
ABCresult
0XX0
10X0
1100
1111
483 # A: "5-3:4" = translated to "5:1-3:4"
484  
485 1 $start_ch = $start;
486 1 $start = 1;
487 }
488  
489 189 my $skip_chapter_assumption_check = 0;
490 189 ▶ if ( $start_ch and $stop_ch and $start and $stop and $start_ch == $stop_ch ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($start_ch and $stop_ch and $start and $stop and $start_ch == $stop_ch) 2 187 189
Condition83%10/12
$start_ch and $stop_ch and $start and $stop and $start_ch == $stop_ch
!ll&&!rl&&r
18072
$start_ch and $stop_ch and $start and $stop
!ll&&!rl&&r
18009
$start_ch and $stop_ch and $start
!ll&&!rl&&r
18009
$start_ch and $stop_ch
!ll&&!rl&&r
111699
MC/DC60%3/5
$start_ch and $stop_ch and $start and $stop and $start_ch == $stop_ch
$start_ch $stop_ch $start $stop $start_ch == $stop_ch
Truth table66%4/6
A and B and C and D and E
A= $start_chB= $stop_chC= $startD= $stopE= $start_ch == $stop_ch
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
491 2 ▶ if ( $start <= $stop ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($start <= $stop) { } 1 1 2
492 # B: "3:4-3:7" = translated to "3:4-7"
493  
494 1 $stop_ch = 0;
495 }
496 else {
497 # Q: "3:37-3:4" is the reverse of 3:4-3:37
498  
499 1 $stop_ch = 0;
500 1 $skip_chapter_assumption_check = 1;
501 }
502 }
503  
504 189 my $expance = '';
505  
506 189 ▶ if ( not $start_ch and not $stop_ch ) {
Branch: 4 branches
BranchTrueFalseTotal
if (not $start_ch || $stop_ch) { } 101 88 189
elsif ($start_ch and not $stop_ch) { } 71 17 88
elsif (not $start_ch and $stop_ch) { } 10 7 17
elsif ($start_ch and $stop_ch) { } 7 0 7
Condition100%3/3
$start_ch || $stop_ch
l!l&&r!l&&!r
7810101
MC/DC100%2/2
$start_ch || $stop_ch
$start_ch $stop_ch
Truth table100%3/3
A || B
A= $start_chB= $stop_ch
ABresult
1X1
011
000
507 # C: "3-3" = consider as "3"
508 # D: "3-5" = consider as a simple range
509 # E: "5-3" = consider as a simple reversed range
510  
511 101 $expance = join( ',', _list( $start, $stop ) );
512 }
513  
514 ▶ elsif ( $start_ch and not $stop_ch ) {
Condition100%3/3
$start_ch and not $stop_ch
!ll&&!rl&&r
10771
MC/DC100%2/2
$start_ch and not $stop_ch
$start_ch not $stop_ch
Truth table100%3/3
A and not(B)
A= $start_chB= not $stop_ch
ABresult
0X0
100
111
515 # F: "1:3-15" = consider 3-15 as verses
516 # G: "1:15-3" = consider 3 a chapter
517 # H: "1:3-3" = consider the second 3 a chapter
518 # I: "3:2-3" = consider 2-3 as verses
519 # J: "3:3-2" = consider 3-2 as verses
520  
521 71 ▶ if ( $start >= $stop and $stop > $start_ch and not $skip_chapter_assumption_check ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($start >= $stop and $stop > $start_ch and not $skip_chapter_assumption_check) 4 67 71
Condition100%6/6
$start >= $stop and $stop > $start_ch and not $skip_chapter_assumption_check
!ll&&!rl&&r
6614
$start >= $stop and $stop > $start_ch
!ll&&!rl&&r
6515
MC/DC100%3/3
$start >= $stop and $stop > $start_ch and not $skip_chapter_assumption_check
$start >= $stop $stop > $start_ch not $skip_chapter_assumption_check
Truth table100%4/4
A and B and not(C)
A= $start >= $stopB= $stop > $start_chC= not $skip_chapter_assumption_check
ABCresult
0XX0
10X0
1100
1111
522 4 $stop_ch = $stop;
523 4 $stop = $self->_bible_data->{lengths}{$book}[ $start_ch - 1 ];
524 }
525  
526 71 ▶ $expance = join( ';', grep { defined }
Branch: 1 branch
BranchTrueFalseTotal
$stop_ch ? : 4 67 71
527 $start_ch . ':' . join( ',', _list( $start, $stop ) ),
528 ( ($stop_ch) ? join( ';', _list( $start_ch + 1, $stop_ch ) ) : undef ),
529 );
530 }
531  
532 ▶ elsif ( not $start_ch and $stop_ch ) {
Condition66%2/3
not $start_ch and $stop_ch
!ll&&!rl&&r
7010
MC/DC50%1/2
not $start_ch and $stop_ch
not $start_ch $stop_ch
Truth table66%2/3
not(A) and B
A= not $start_chB= $stop_ch
ABresult
0X0
100
111
533 # K: "3-5:2" = 3-4 are full chapters; plus 5:1-5:2
534 # L: "3-3:2" = interpretted as "3:1-2"
535  
536 10 $start_ch = $start;
537 10 $start = 1;
538  
539 10 $expance = join( ':',
540 join( ';', _list( $start_ch, $stop_ch ) ),
541 join( ',', _list( $start, $stop ) ),
542 );
543 }
544  
545 ▶ elsif ( $start_ch and $stop_ch ) {
Condition33%1/3
$start_ch and $stop_ch
!ll&&!rl&&r
007
MC/DC0%0/2
$start_ch and $stop_ch
$start_ch $stop_ch
Truth table33%1/3
A and B
A= $start_chB= $stop_ch
ABresult
0X0
100
111
546 # M: "3:4-4:7" becomes "3:4-*;4:1-7"
547 # N: "4:7-3:4" becomes reverse of "3:4-*;4:1-7"
548 # O: "3:4-5:2" becomes "3:4-*;4;5:1-2"
549 # P: "5:2-3:4" becomes reverse of "3:4-*;4;5:2-*"
550  
551 7 my $reversed = 0;
552 7 ▶ if ( $start_ch >= $stop_ch ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($start_ch >= $stop_ch) 3 4 7
553 3 ( $start_ch, $stop_ch, $start, $stop ) = ( $stop_ch, $start_ch, $stop, $start );
554 3 $reversed = 1;
555 }
556  
557 7 ▶ my $reverse = sub { ($reversed) ? reverse(@_) : @_ };
Subroutine __ANON__: called CC=2 SCAR=6.9
Branch: 1 branch
BranchTrueFalseTotal
$reversed ? : 11 13 24
558  
559 21 ▶ $expance = join( ';', grep { defined }
Branch: 1 branch
BranchTrueFalseTotal
$stop_ch - $start_ch > 1 ? : 3 4 7
560 $reverse->(
561 $start_ch . ':' . join( ',', $reverse->( _list(
562 $start,
563 7 $self->_bible_data->{lengths}{$book}[ $start_ch - 1 ],
564 ) ) ),
565 (
566 ( $stop_ch - $start_ch > 1 )
567 ? join( ',', $reverse->( _list( $start_ch + 1, $stop_ch - 1 ) ) )
568 : undef
569 ),
570 $stop_ch . ':' . join( ',', $reverse->( _list( 1, $stop ) ) ),
571 ),
572 );
573 }
574  
575 189 $expance;
576 187 };
577  
578 187 $text =~ s/[\s,]+/,/g;
579 187 $text =~ s/^,//g;
580 187 $text =~ s/(\d+(?::\d+)?)\-(\d+(?::\d+)?)/ $expand->( $1, $2 ) /ge;
581 187 ▶ $text =~ s/([,;])/$1 /g unless $compress;
Branch: 1 branch
BranchTrueFalseTotal
unless $compress 0 187 187
582  
583 187 return $text;
584 };
585  
586 26 ▶sub in ( $self, @input ) {
Subroutine in: called CC=25 SCAR=32.2
Pod documented
587 26 ▶ return $self unless (@input);
Branch: 1 branch
BranchTrueFalseTotal
unless @input 0 26 26
588  
589 my $re_refs = $self->_bible_data->{
590 26 ▶ 're_refs_' .
Branch: 2 branches
BranchTrueFalseTotal
$self->require_book_ucfirst ? : 1 25 26
$self->require_verse_match ? : 1 25 26
591 ( ( $self->require_book_ucfirst ) ? 's' : 'i' ) .
592 ( ( $self->require_verse_match ) ? 'r' : '' )
593 };
594  
595 my $re_books = ( $self->require_book_ucfirst )
596 ? $self->_bible_data->{re_books_s}
597 26 ▶ : $self->_bible_data->{re_books_i};
Branch: 1 branch
BranchTrueFalseTotal
$self->require_book_ucfirst ? : 1 25 26
598  
599 26 for my $string (@input) {
600 175 ▶ $string = scalar( reverse $string // '' );
Condition100%2/2
$string // ""
l!l
1678
MC/DC100%1/1
$string // ""
$string
Truth table100%2/2
A
A= $string
Aresult
11
00
601 175 my @processed;
602 175 while (1) {
603 516 my ( $pre, $ref, $post ) = split( /$re_refs/, $string, 2 );
604 516 ▶ last unless ($ref);
Branch: 1 branch
BranchTrueFalseTotal
unless $ref 175 341 516
605  
606 341 $ref =~ s/(\d)([[:alpha:]])/$1 $2/;
607  
608 341 $string = $post;
609  
610 341 ▶ my $space = ( $ref =~ s/^((?i:\W|\bdna\b|\bro\b|&)+)// ) ? $1 : '';
Branch: 1 branch
BranchTrueFalseTotal
$ref =~ s/^((?i:\W|\bdna\b|\bro\b|&)+)//u ? : 129 212 341
611 341 $ref =~ s/\s+/ /g;
612 341 $pre = $pre . $space;
613 341 push( @processed, $pre );
614  
615 341 my $orig_ref = $ref;
616  
617 341 my $book;
618 341 for (@$re_books) {
619 154492 ▶ if ( $ref =~ /$_->[0]/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref =~ /$_->[0]/u) 341 154151 154492
620 341 $book = $_->[1];
621 341 last;
622 }
623 }
624  
625 341 my $ref_out = [$book];
626 341 my $numbers = [];
627  
628 341 $ref =~ s/(?:\bdna\b|\bro\b|&)/,/g;
629 341 $ref = scalar reverse $ref;
630  
631 341 ▶ if ( $ref =~ /([\d:,;\s\-]+)$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($ref =~ /([\d:,;\s\-]+)$/u) 166 175 341
632 166 my $range = $self->expand_ranges( $book, $1, 1 );
633  
634 166 my $verse_context = 0;
635 166 my $last_d = 0;
636  
637 166 ▶ while ( $range =~ s/^(\d+)([:,;]?)\D*//g ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($range =~ s/^(\d+)([:,;]?)\D*//gu) 1422 166 1588
638 1422 ▶ my ( $d, $s ) = ( $1, $2 || '' );
Condition100%2/2
$2 || ''
l!l
1256166
MC/DC100%1/1
$2 || ''
$2
Truth table100%2/2
A
A= $2
Aresult
11
00
639  
640 1422 ▶ $verse_context = 0 if ( $s eq ':' or $d <= $last_d );
Branch: 1 branch
BranchTrueFalseTotal
if $s eq ":" or $d <= $last_d 154 1268 1422
Condition100%3/3
$s eq ":" or $d <= $last_d
l!l&&r!l&&!r
138161268
MC/DC100%2/2
$s eq ":" or $d <= $last_d
$s eq ":" $d <= $last_d
Truth table100%3/3
A or B
A= $s eq ":"B= $d <= $last_d
ABresult
1X1
011
000
641  
642 1422 ▶ unless ($verse_context) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verse_context) { } 737 685 1422
643 685 push( @$numbers, [$d] );
644 }
645 else {
646 737 ▶ push( @{ $numbers->[-1] }, [] ) unless ( @{ $numbers->[-1] } > 1 );
Branch: 1 branch
BranchTrueFalseTotal
unless @{$numbers->[-1];} > 1 138 599 737
647 737 push( @{ $numbers->[-1][-1] }, $d );
648 }
649  
650 1422 ▶ $last_d = ($verse_context) ? $d : 0;
Branch: 1 branch
BranchTrueFalseTotal
$verse_context ? : 737 685 1422
651  
652 1422 ▶ $verse_context = 1 if ( $s eq ':' );
Branch: 1 branch
BranchTrueFalseTotal
if $s eq ":" 138 1284 1422
653 1422 ▶ $verse_context = 0 if ( $s eq ';' );
Branch: 1 branch
BranchTrueFalseTotal
if $s eq ";" 23 1399 1422
654 }
655 }
656  
657 341 ▶ if ( @$numbers or not $self->require_chapter_match ) {
Branch: 1 branch
BranchTrueFalseTotal
if (@$numbers or not $self->require_chapter_match) { } 340 1 341
Condition100%3/3
@$numbers or not $self->require_chapter_match
l!l&&r!l&&!r
1661741
MC/DC100%2/2
@$numbers or not $self->require_chapter_match
@$numbers not $self->require_chapter_match
Truth table100%3/3
A or not(B)
A= @$numbersB= not $self->require_chapter_match
ABresult
1X1
011
000
658 340 ▶ push( @$ref_out, $numbers ) if (@$numbers);
Branch: 1 branch
BranchTrueFalseTotal
if @$numbers 166 174 340
659 340 push( @processed, $ref_out );
660 }
661 else {
662 1 $processed[-1] .= $orig_ref;
663 }
664 }
665  
666 175 push( @processed, $string );
667 push(
668 175 @{ $self->_data },
669 175 ▶ [ grep { length } map { ( ref $_ ) ? $_ : scalar reverse $_ } reverse @processed ],
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 340 516 856
670 );
671 }
672  
673 26 return $self;
674 }
675  
676 23 ▶sub clear ($self) {
Subroutine clear: called CC=1 SCAR=0.0
Pod documented
677 23 $self->_data([]);
678 23 return $self;
679 }
680  
681 4 ▶sub books ($self) {
Subroutine books: called CC=2 SCAR=7.2
Pod documented
682 4 ▶ return (wantarray) ? @{ $self->_bible_data->{books} } : $self->_bible_data->{books};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 4 0 4
683 }
684  
685 60 ▶sub as_array ( $self, $data = undef ) {
Subroutine as_array: called CC=34 SCAR=35.7
Pod documented
686 60 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if ($data or not $self->_cache->{"data"} or not $self->_cache->{"sorting"} && $self->_cache->{"sorting"} == $self->sorting && $self->_cache->{"acronyms"} && $self->_cache->{"acronyms"} == $self->acronyms) 60 0 60
Condition53%8/15
$data or not $self->_cache->{"data"} or not $self->_cache->{"sorting"} && $self->_cache->{"sorting"} == $self->sorting && $self->_cache->{"acronyms"} && $self->_cache->{"acronyms"} == $self->acronyms
l!l&&r!l&&!r
44160
$data or not $self->_cache->{"data"}
l!l&&r!l&&!r
40416
$self->_cache->{'sorting'} && $self->_cache->{'sorting'} == $self->sorting && $self->_cache->{'acronyms'} && $self->_cache->{'acronyms'} == $self->acronyms
!ll&&!rl&&r
1600
$self->_cache->{"sorting"} and $self->_cache->{"sorting"} == $self->sorting and $self->_cache->{"acronyms"}
!ll&&!rl&&r
1600
$self->_cache->{"sorting"} and $self->_cache->{"sorting"} == $self->sorting
!ll&&!rl&&r
1600
MC/DC0%0/6
$data or not $self->_cache->{"data"} or not $self->_cache->{"sorting"} && $self->_cache->{"sorting"} == $self->sorting && $self->_cache->{"acronyms"} && $self->_cache->{"acronyms"} == $self->acronyms
$data not $self->_cache->{"data"} $self->_cache->{"sorting"} $self->_cache->{"sorting"} == $self->sorting $self->_cache->{"acronyms"} $self->_cache->{'acronyms'} == $self->acronyms
Truth table42%3/7
A or not(B) or not(C and D and E && F)
A= $dataB= not $self->_cache->{"data"}C= $self->_cache->{"sorting"}D= $self->_cache->{"sorting"} == $self->sortingE= $self->_cache->{"acronyms"}F= $self->_cache->{'acronyms'} == $self->acronyms
ABCDEFresult
1XXXXX1
01XXXX1
000XXX1
0010XX1
00110X1
0011101
0011110
687 $data or
688 not $self->_cache->{data} or
689 not (
690 $self->_cache->{sorting} and $self->_cache->{sorting} == $self->sorting and
691 $self->_cache->{acronyms} and $self->_cache->{acronyms} == $self->acronyms
692 )
693 ) {
694 60 ▶ $data //= [ map { grep { ref } @$_ } @{ $self->_data } ];
Condition100%2/2
$data //= [map({grep {ref $_;} @$_;} @{$self->_data;})]
l!l
4020
MC/DC100%1/1
$data //= [map({grep {ref $_;} @$_;} @{$self->_data;})]
$data
Truth table100%2/2
A
A= $data
Aresult
11
00
695 $data = [
696 60 map { [
697 map {
698 450 ( ref $_ ) ? [
699 map {
700 666 ▶ ( ref $_ ) ? [
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 216 450 666
701 map {
702 923 ▶ ( ref $_ ) ? [
Branch: 2 branches
BranchTrueFalseTotal
ref $_ ? : 923 0 923
ref $_ ? : 176 923 1099
703 @$_
704 ] : $_
705 } @$_
706 ] : $_
707 } @$_
708 ] : $_
709 } @$_
710 ] }
711 @$data
712 ];
713  
714 $data = [ map {
715 60 ▶ my $book = $_->[0];
Branch: 1 branch
BranchTrueFalseTotal
if $self->add_detail 3 57 60
716  
717 43 ▶ if ( ref $_->[1] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $_->[1]) { } 23 20 43
718 $_->[1] = [ map {
719 100 ▶ $_->[1] //= [ 1 .. ( $self->_bible_data->{lengths}{$book}[ $_->[0] - 1 ] || 0 ) ];
Condition100%4/4
$_->[1] //= [1 .. $self->_bible_data->{"lengths"}{$book}[$_->[0] - 1] || 0]
l!l
2476
$self->_bible_data->{'lengths'}{$book}[$_->[0] - 1] || 0
l!l
751
MC/DC100%1/1
$_->[1] //= [1 .. $self->_bible_data->{"lengths"}{$book}[$_->[0] - 1] || 0]
$_->[1]
MC/DC100%1/1
$self->_bible_data->{'lengths'}{$book}[$_->[0] - 1] || 0
$self->_bible_data->{'lengths'}{$book}[$_->[0] - 1]
Truth table100%2/2
A
A= $_->[1]
Aresult
11
00
Truth table100%2/2
A
A= $self->_bible_data->{'lengths'}{$book}[$_->[0] - 1]
Aresult
11
00
720 100 $_;
721 23 } @{ $_->[1] } ];
722 }
723 else {
724 20 my $chapter;
725 20 $_->[1] = [ map { [ ++$chapter, [ 1 .. $_ ] ] } @{ $self->_bible_data->{lengths}{$book} } ];
726 }
727  
728 43 $_;
729 } @$data ] if ( $self->add_detail );
730  
731 60 ▶ if ( $self->sorting ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->sorting) 58 2 60
732 58 my $data_by_book = {};
733 58 ▶ push( @{ $data_by_book->{ $_->[0] } }, @{ $_->[1] || [] } ) for (@$data);
Condition100%2/2
$_->[1] || []
l!l
216194
MC/DC100%1/1
$_->[1] || []
$_->[1]
Truth table100%2/2
A
A= $_->[1]
Aresult
11
00
734  
735 $data = [
736 map {
737 257 my $book = [ $_->[1] ];
738  
739 257 my $dedup;
740 257 for my $chapter ( @{ $data_by_book->{ $_->[1] } } ) {
741 1049 ▶ $dedup->{ $chapter->[0] } //= {};
Condition100%2/2
$$dedup{$chapter->[0]} //= {}
l!l
121928
MC/DC100%1/1
$$dedup{$chapter->[0]} //= {}
$$dedup{$chapter->[0]}
Truth table100%2/2
A
A= $$dedup{$chapter->[0]}
Aresult
11
00
742 1049 $dedup->{ $chapter->[0] }{$_} = 1 for ( @{ $chapter->[1] } );
743 }
744  
745 my $chapters = [
746 map {
747 928 my $chapter = [$_];
748 928 my @verses = keys %{ $dedup->{$_} };
749 928 ▶ push( @$chapter, [ sort { $a <=> $b } @verses ] ) if @verses;
Branch: 1 branch
BranchTrueFalseTotal
if @verses 331 597 928
750 928 $chapter;
751 }
752 257 sort { $a <=> $b }
753 keys %$dedup
754 ];
755  
756 257 ▶ push( @$book, $chapters ) if (@$chapters);
Branch: 1 branch
BranchTrueFalseTotal
if @$chapters 127 130 257
757  
758 257 $book;
759 }
760 201 sort { $a->[0] <=> $b->[0] }
761 58 map { [ $self->_bible_data->{book_order}{$_}, $_ ] }
762 keys %$data_by_book
763 ];
764 }
765  
766 $data = [ map {
767 60 ▶ my $book = $_->[0];
Branch: 1 branch
BranchTrueFalseTotal
if $self->simplify 2 58 60
768  
769 4 ▶ if ( my $chapters = $_->[1] ) {
Branch: 1 branch
BranchTrueFalseTotal
if (my $chapters = $_->[1]) 4 0 4
770 4 for my $chapter (@$chapters) {
771 pop @$chapter if (
772 $chapter->[1] and
773 18 ▶ join( ',', @{ $chapter->[1] } ) eq
Condition50%1/2
$self->_bible_data->{'lengths'}{$book}[$chapter->[0] - 1] || 0
l!l
180
MC/DC0%0/1
$self->_bible_data->{'lengths'}{$book}[$chapter->[0] - 1] || 0
$self->_bible_data->{'lengths'}{$book}[$chapter->[0] - 1]
Truth table50%1/2
A
A= $self->_bible_data->{'lengths'}{$book}[$chapter->[0] - 1]
Aresult
11
00
774 18 ▶ join( ',', 1 .. ( $self->_bible_data->{lengths}{$book}[ $chapter->[0] - 1 ] || 0 ) )
Branch: 1 branch
BranchTrueFalseTotal
if $chapter->[1] and join(",", @{$chapter->[1];}) eq join(",", 1 .. $self->_bible_data->{"lengths"}{$book}[$chapter->[0] - 1] || 0) 18 0 18
Condition33%1/3
$chapter->[1] and join(",", @{$chapter->[1];}) eq join(",", 1 .. $self->_bible_data->{"lengths"}{$book}[$chapter->[0] - 1] || 0)
!ll&&!rl&&r
0018
MC/DC0%0/2
$chapter->[1] and join(",", @{$chapter->[1];}) eq join(",", 1 .. $self->_bible_data->{"lengths"}{$book}[$chapter->[0] - 1] || 0)
$chapter->[1] join(",", @{$chapter->[1];}) eq join(",", 1 .. $self->_bible_data->{"lengths"}{$book}[$chapter->[0] - 1] || 0)
Truth table33%1/3
A and B
A= $chapter->[1]B= join(",", @{$chapter->[1];}) eq join(",", 1 .. $self->_bible_data->{"lengths"}{$book}[$chapter->[0] - 1] || 0)
ABresult
0X0
100
111
775 );
776 }
777  
778 pop @$_ if (
779 18 join( ',', map { $_->[0] } grep { @$_ == 1 } @$chapters ) eq
780 4 ▶ join( ',', 1 .. scalar @{ $self->_bible_data->{lengths}{$book} } )
Branch: 1 branch
BranchTrueFalseTotal
if join(",", map({$_->[0];} grep({@$_ == 1;} @$chapters))) eq join(",", 1 .. scalar @{$self->_bible_data->{"lengths"}{$book};}) 2 2 4
781 );
782 }
783  
784 4 $_;
785 } @$data ] if ( $self->simplify );
786  
787 60 ▶ if ( $self->acronyms ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->acronyms) 1 59 60
788 1 for (@$data) {
789 22 $_->[0] = $self->_bible_data->{book_to_acronym}{ $_->[0] };
790 }
791 }
792  
793 60 $self->_cache->{data} = $data;
794 }
795  
796 60 ▶ return (wantarray) ? @{ $self->_cache->{data} } : $self->_cache->{data};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 59 60
797 }
798  
799 1 ▶sub as_hash ( $self, $data = undef ) {
Subroutine as_hash: called CC=6 SCAR=17.9
Pod documented
800 1 my $build = {};
801  
802 1 for my $book_block ( $self->as_array($data) ) {
803 22 my ( $book_name, $chapters ) = @$book_block;
804  
805 22 $build->{$book_name} = {};
806 22 for (@$chapters) {
807 77 ▶ push( @{ $build->{$book_name}{ $_->[0] } }, @{ $_->[1] || [] } );
Condition100%2/2
$_->[1] || []
l!l
1166
MC/DC100%1/1
$_->[1] || []
$_->[1]
Truth table100%2/2
A
A= $_->[1]
Aresult
11
00
808 }
809 }
810  
811 1 ▶ return (wantarray) ? %$build : $build;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 1 1
812 }
813  
814 88 ▶sub _compress_range ( $items = [] ) {
Subroutine _compress_range: called CC=6 SCAR=17.9
815 88 my ( $last, @items, @range );
816  
817 202 ▶ my $flush_range = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
818 202 ▶ if (@range) {
Branch: 1 branch
BranchTrueFalseTotal
if (@range) 74 128 202
819 74 pop @items;
820 74 push( @items, join( '-', $range[0], $range[-1] ) );
821 74 @range = ();
822 }
823 88 };
824  
825 88 for my $item (@$items) {
826 504 ▶ if ( not $last or $last + 1 != $item ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not $last or $last + 1 != $item) { } 114 390 504
Condition100%3/3
not $last or $last + 1 != $item
l!l&&r!l&&!r
8826390
MC/DC100%2/2
not $last or $last + 1 != $item
not $last $last + 1 != $item
Truth table100%3/3
not(A) or B
A= not $lastB= $last + 1 != $item
ABresult
1X1
011
000
827 114 $flush_range->();
828 114 push( @items, $item );
829 }
830 else {
831 390 push( @range, $last, $item );
832 }
833  
834 504 $last = $item;
835 }
836 88 $flush_range->();
837  
838 88 ▶ return (wantarray) ? @items : join( ', ', @items );
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 88 0 88
839 }
840  
841 55 ▶sub _as_type ( $self, $type, $data = undef ) {
Subroutine _as_type: called CC=10 SCAR=23.0
842 55 $data = $self->as_array($data);
843  
844 return [
845 map {
846 55 my $book = $_->[0];
847  
848 170 ▶ if ( $_->[1] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->[1]) { } 74 96 170
849 74 my ( @build, @buffer );
850  
851 83 ▶ my $flush_buffer = sub {
Subroutine __ANON__: called CC=2 SCAR=6.9
852 83 ▶ if (@buffer) {
Branch: 1 branch
BranchTrueFalseTotal
if (@buffer) 27 56 83
853 27 push( @build, join( '; ', _compress_range(\@buffer) ) );
854 27 @buffer = ();
855 }
856 74 };
857  
858 74 for ( @{ $_->[1] } ) {
859 478 my $chapter = $_->[0];
860  
861 478 ▶ if ( $_->[1] ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($_->[1]) { } 72 406 478
862 72 ▶ if ( $type eq 'verses' ) {
Branch: 3 branches
BranchTrueFalseTotal
if ($type eq 'verses') { } 11 61 72
elsif ($type eq 'runs') { } 11 50 61
elsif ($type eq 'chapters') { } 11 39 50
863 11 push( @build, map { "$book $chapter:$_" } @{ $_->[1] } );
864 }
865 elsif ( $type eq 'runs' ) {
866 11 push( @build, map { "$book $chapter:$_" } _compress_range( $_->[1] ) );
867 }
868 elsif ( $type eq 'chapters' ) {
869 11 push( @build, "$book $chapter:" . join( ', ', _compress_range( $_->[1] ) ) );
870 }
871 else {
872 39 $flush_buffer->();
873 39 push( @build, $chapter . ':' . join( ', ', _compress_range( $_->[1] ) ) );
874 }
875 }
876 else {
877 406 ▶ unless ( $type eq 'books' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'books') { } 208 198 406
878 198 push( @build, "$book $chapter" );
879 }
880 else {
881 208 push( @buffer, $chapter );
882 }
883 }
884 }
885  
886 74 ▶ unless ( $type eq 'books' ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($type eq 'books') { } 44 30 74
887 30 @build;
888 }
889 else {
890 44 $flush_buffer->();
891 44 $book . ' ' . join( '; ', @build );
892 }
893 }
894 else {
895 96 $book;
896 }
897 } @$data
898 ];
899 }
900  
901 1 ▶sub as_verses ( $self, $data = undef ) {
Subroutine as_verses: called CC=3 SCAR=11.2
Pod documented
902 1 my $items = $self->_as_type( 'verses', $data );
903 1 ▶ return (wantarray) ? @$items : $items;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 1 1
904 }
905  
906 1 ▶sub as_runs ( $self, $data = undef ) {
Subroutine as_runs: called CC=3 SCAR=11.2
Pod documented
907 1 my $items = $self->_as_type( 'runs', $data );
908 1 ▶ return (wantarray) ? @$items : $items;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 1 1
909 }
910  
911 1 ▶sub as_chapters ( $self, $data = undef ) {
Subroutine as_chapters: called CC=3 SCAR=11.2
Pod documented
912 1 my $items = $self->_as_type( 'chapters', $data );
913 1 ▶ return (wantarray) ? @$items : $items;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 1 1
914 }
915  
916 52 ▶sub as_books ( $self, $data = undef ) {
Subroutine as_books: called CC=3 SCAR=11.0
Pod documented
917 52 my $items = $self->_as_type( 'books', $data );
918 52 ▶ return (wantarray) ? @$items : $items;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 45 7 52
919 }
920  
921 45 ▶sub refs ( $self, $data = undef ) {
Subroutine refs: called CC=2 SCAR=6.9
Pod documented
922 45 return join( '; ', $self->as_books($data) );
923 }
924  
925 2 ▶sub as_text ($self) {
Subroutine as_text: called CC=6 SCAR=18.2
Pod documented
926 my @text = map {
927 19 ▶ join( '', map { ( ref $_ ) ? $self->refs([$_]) : $_ } @$_ );
Branch: 1 branch
BranchTrueFalseTotal
ref $_ ? : 40 56 96
928 2 } @{ $self->_data };
929  
930 return
931 2 ▶ ( @text > 1 and wantarray ) ? @text :
Branch: 2 branches
BranchTrueFalseTotal
@text > 1 && wantarray ? : 0 2 2
@text > 1 && !wantarray ? : 1 1 2
Condition66%4/6
@text > 1 and wantarray
!ll&&!rl&&r
110
@text > 1 and not wantarray
!ll&&!rl&&r
101
MC/DC0%0/2
@text > 1 and wantarray
@text > 1 wantarray
MC/DC50%1/2
@text > 1 and not wantarray
@text > 1 not wantarray
Truth table66%2/3
A and B
A= @text > 1B= wantarray
ABresult
0X0
100
111
Truth table66%2/3
A and not(B)
A= @text > 1B= not wantarray
ABresult
0X0
100
111
932 ( @text > 1 and not wantarray ) ? \@text : join( ' ', @text );
933 }
934  
935 4 ▶sub set_bible_data ( $self, $bible = undef, $book_data = undef, $verse_data = undef ) {
Subroutine set_bible_data: called CC=16 SCAR=29.6
Pod documented
936 4 ▶ croak 'First argument to set_bible_data() must be a Bible name string'
Branch: 1 branch
BranchTrueFalseTotal
unless $bible and not ref $bible and length $bible > 0 1 3 4
Condition66%4/6
$bible and not ref $bible and length $bible > 0
!ll&&!rl&&r
103
$bible and not ref $bible
!ll&&!rl&&r
103
MC/DC33%1/3
$bible and not ref $bible and length $bible > 0
$bible not ref $bible length $bible > 0
Truth table50%2/4
A and not(B) and C
A= $bibleB= not ref $bibleC= length $bible > 0
ABCresult
0XX0
10X0
1100
1111
937 unless ( $bible and not ref $bible and length $bible > 0 );
938 3 ▶ croak 'Second argument to set_bible_data() must be an arrayref of arrayrefs'
Branch: 1 branch
BranchTrueFalseTotal
unless $book_data and ref $book_data eq "ARRAY" 1 2 3
Condition66%2/3
$book_data and ref $book_data eq "ARRAY"
!ll&&!rl&&r
102
MC/DC50%1/2
$book_data and ref $book_data eq "ARRAY"
$book_data ref $book_data eq "ARRAY"
Truth table66%2/3
A and B
A= $book_dataB= ref $book_data eq "ARRAY"
ABresult
0X0
100
111
939 unless ( $book_data and ref $book_data eq 'ARRAY' );
940  
941 2 for (@$book_data) {
942 41 ▶ croak 'Second argument to set_bible_data() does not appear valid' unless (
Branch: 1 branch
BranchTrueFalseTotal
unless ref $_ eq "ARRAY" and not ref $_->[0] and length $_->[0] > 0 and not ref $_->[1] and length $_->[1] > 0 1 40 41
Condition66%8/12
ref $_ eq "ARRAY" and not ref $_->[0] and length $_->[0] > 0 and not ref $_->[1] and length $_->[1] > 0
!ll&&!rl&&r
1040
ref $_ eq "ARRAY" and not ref $_->[0] and length $_->[0] > 0 and not ref $_->[1]
!ll&&!rl&&r
1040
ref $_ eq "ARRAY" and not ref $_->[0] and length $_->[0] > 0
!ll&&!rl&&r
1040
ref $_ eq "ARRAY" and not ref $_->[0]
!ll&&!rl&&r
0140
MC/DC20%1/5
ref $_ eq "ARRAY" and not ref $_->[0] and length $_->[0] > 0 and not ref $_->[1] and length $_->[1] > 0
ref $_ eq "ARRAY" not ref $_->[0] length $_->[0] > 0 not ref $_->[1] length $_->[1] > 0
Truth table33%2/6
A and not(B) and C and not(D) and E
A= ref $_ eq "ARRAY"B= not ref $_->[0]C= length $_->[0] > 0D= not ref $_->[1]E= length $_->[1] > 0
ABCDEresult
0XXXX0
10XXX0
110XX0
1110X0
111100
111111
943 ref $_ eq 'ARRAY' and
944 not ref $_->[0] and length $_->[0] > 0 and
945 not ref $_->[1] and length $_->[1] > 0
946 );
947 }
948  
949 1 ▶ unless ($verse_data) {
Branch: 1 branch
BranchTrueFalseTotal
if ($verse_data) { } 0 1 1
950 1 _build_bible_template( 'Orthodox' => $bible, $self->_bibles );
951 1 $self->_bibles->{$bible}[0] = $book_data;
952 }
953 else {
954 0 $self->_bibles->{$bible}[0] = $book_data;
955 0 $self->_bibles->{$bible}[1] = $verse_data;
956 }
957  
958 1 $self->bible($bible);
959 1 return $self;
960 }
961  
962 1 ▶sub get_bible_structure ( $self, $bible = undef ) {
Subroutine get_bible_structure: called CC=3 SCAR=11.1
Pod documented
963 1 ▶ $self->bible($bible) if ($bible);
Branch: 1 branch
BranchTrueFalseTotal
if $bible 1 0 1
964 1 return [ map { [ $_, $self->_bible_data->{lengths}{$_} ] } @{ $self->_bible_data->{books} } ];
965 }
966  
967 2 ▶sub identify_bible ( $self, @books ) {
Subroutine identify_bible: called CC=3 SCAR=11.0
Pod documented
968 2 ▶ croak('No books supplied; must supply at least 1 input') unless (@books);
Branch: 1 branch
BranchTrueFalseTotal
unless @books 1 1 2
969  
970 1 my $obj = $self->new( minimum_book_length => $self->minimum_book_length );
971 my $bibles = [
972 10 sort { $b->{count} <=> $a->{count} }
973 map {
974 6 $obj->bible($_);
975 6 my $books = scalar( $obj->clear->in(@books)->as_books );
976 {
977 6 name => $_,
978 books => $books,
979 count => scalar(@$books),
980 };
981 }
982 1 keys %{ $obj->_bibles }
983 ];
984  
985 6 $bibles = [ grep { $bibles->[0]{count} == $_->{count} } @$bibles ]
986 1 ▶ if ( $bibles->[0]{count} != $bibles->[-1]{count} );
Branch: 1 branch
BranchTrueFalseTotal
if $bibles->[0]{"count"} != $bibles->[-1]{"count"} 1 0 1
987  
988 1 return $bibles;
989 }
990  
991 3 1;
992  
993 __END__
↑ Summary