Document/Toc.pm

filter: Statementstmt 6.7% 14 / 209 Branchbran 0.0% 0 / 98 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 7.1% 4 / 56 Podpod 100% 28 / 28 totaltotal 11.7% 46 / 391 CC 55 SCAR 28.1
CC
55
Cov
5%
havePageTitleCategory
42.0
replacePageTitle
42.0
addPageTitles
30.0
CRAP 16.6
« Document/TocFile.pm ↑ Summary Document/NotesFile.pm »
1 #================================== Toc.pm ===================================
2 # Filename: Toc.pm
3 # Description: Manage a Table of contents file.
4 # Original Author: Dale Amon
5 # Revised by: $Author: amon $
6 # Date: $Date: 2008-08-28 23:26:17 $
7 # Version: $Revision: 1.5 $
8 # License: LGPL 2.1, Perl Artistic or BSD
9 #
10 #=============================================================================
11 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
12 1 ▶use Document::Members;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use Fault::DebugPrinter;
Subroutine BEGIN: called CC=1 SCAR=0.0
14  
15 package Document::Toc;
16 1 ▶use vars qw{@ISA};
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 @ISA = qw( Document::Members );
18  
19 #=============================================================================
20 # Object Methods
21 #=============================================================================
22 # Predicate operators
23 #-----------------------------------------------------------------------------
24  
25 0 ▶sub havePage {
Subroutine havePage: not called CC=2 SCAR=17.9
Pod documented
26 0 my ($self) = shift;
27 0 my ($pagenum) = @_;
28 0 ▶ defined $pagenum || (return 0);
Branch: 1 branch
BranchTrueFalseTotal
defined $pagenum or return 0 0 0 0
29 0 return ($self->_havepage (@_));
30 }
31  
32 #-----------------------------------------------------------------------------
33  
34 0 ▶sub havePageTitle {
Subroutine havePageTitle: not called CC=4 SCAR=30.0
Pod documented
35 0 my ($self) = shift;
36 0 my ($pagenum,$title) = @_;
37  
38 0 ▶ defined $pagenum || (return 0);
Branch: 1 branch
BranchTrueFalseTotal
defined $pagenum or return 0 0 0 0
39 0 ▶ defined $title || (return 0);
Branch: 1 branch
BranchTrueFalseTotal
defined $title or return 0 0 0 0
40  
41 0 ▶ ($self->_havepage (@_)) || (return 0);
Branch: 1 branch
BranchTrueFalseTotal
$self->_havepage(@_) or return 0 0 0 0
42 0 return ($self->_havetitle (@_));
43 }
44  
45 #-----------------------------------------------------------------------------
46  
47 0 ▶sub havePageTitleCategory {
Subroutine havePageTitleCategory: not called CC=6 SCAR=37.4
Pod documented
48 0 my ($self) = shift;
49 0 my ($pagenum,$title,$category) = @_;
50  
51 0 ▶ defined $pagenum || (return 0);
Branch: 1 branch
BranchTrueFalseTotal
defined $pagenum or return 0 0 0 0
52 0 ▶ defined $title || (return 0);
Branch: 1 branch
BranchTrueFalseTotal
defined $title or return 0 0 0 0
53 0 ▶ defined $category || (return 0);
Branch: 1 branch
BranchTrueFalseTotal
defined $category or return 0 0 0 0
54  
55 0 ▶ ($self->_havepage (@_)) || (return 0);
Branch: 1 branch
BranchTrueFalseTotal
$self->_havepage(@_) or return 0 0 0 0
56 0 ▶ ($self->_havetitle (@_)) || (return 0);
Branch: 1 branch
BranchTrueFalseTotal
$self->_havetitle(@_) or return 0 0 0 0
57 0 return ($self->_havecategory (@_));
58 }
59  
60 #-----------------------------------------------------------------------------
61 # Key listing operators
62 #-----------------------------------------------------------------------------
63  
64 0 ▶sub pages {return (shift->_listpages)}
Subroutine pages: not called CC=1 SCAR=6.9
Pod documented
65  
66 #-----------------------------------------------------------------------------
67  
68 0 ▶sub pageTitles {
Subroutine pageTitles: not called CC=3 SCAR=24.8
Pod documented
69 0 my $self = shift;
70 0 my ($pagenum) = @_;
71  
72 0 ▶ defined $pagenum || (return undef);
Branch: 1 branch
BranchTrueFalseTotal
defined $pagenum or return undef 0 0 0
73 0 ▶ ($self->_havepage (@_)) || (return undef);
Branch: 1 branch
BranchTrueFalseTotal
$self->_havepage(@_) or return undef 0 0 0
74 0 return ($self->_listtitles (@_));
75 }
76  
77 #-----------------------------------------------------------------------------
78  
79 0 ▶sub pageTitleCategories {
Subroutine pageTitleCategories: not called CC=4 SCAR=30.0
Pod documented
80 0 my $self = shift;
81 0 my ($pagenum,$title) = @_;
82  
83 0 ▶ defined $pagenum || (return undef);
Branch: 1 branch
BranchTrueFalseTotal
defined $pagenum or return undef 0 0 0
84 0 ▶ defined $title || (return undef);
Branch: 1 branch
BranchTrueFalseTotal
defined $title or return undef 0 0 0
85 0 ▶ ($self->_havetitle (@_)) || (return undef);
Branch: 1 branch
BranchTrueFalseTotal
$self->_havetitle(@_) or return undef 0 0 0
86 0 return ($self->_listcats (@_));
87 }
88  
89 #-----------------------------------------------------------------------------
90 # Add operators
91 #-----------------------------------------------------------------------------
92  
93 0 ▶sub addPages {
Subroutine addPages: not called CC=3 SCAR=24.8
Pod documented
94 0 my ($self) = shift;
95 0 ▶ foreach my $p (@_) {($self->_havepage ($p)) || ($self->_initpage ($p));}
Branch: 1 branch
BranchTrueFalseTotal
$self->_havepage($p) or $self->_initpage($p) 0 0 0
96 0 $self->_l8r;
97 0 return 1;
98 }
99  
100 #-----------------------------------------------------------------------------
101  
102 0 ▶sub addPageTitles{
Subroutine addPageTitles: not called CC=5 SCAR=34.0
Pod documented
103 0 my ($self) = shift;
104 0 my ($p) = shift;
105  
106 0 ▶ defined $p || (return 0);
Branch: 1 branch
BranchTrueFalseTotal
defined $p or return 0 0 0 0
107 0 ▶ ($self->_havepage ($p)) || ($self->_initpage ($p));
Branch: 1 branch
BranchTrueFalseTotal
$self->_havepage($p) or $self->_initpage($p) 0 0 0
108  
109 0 foreach my $t (@_) {
110 0 ▶ ($self->_havetitle ($p,$t)) || ($self->_inittitle ($p,$t));
Branch: 1 branch
BranchTrueFalseTotal
$self->_havetitle($p, $t) or $self->_inittitle($p, $t) 0 0 0
111 }
112 0 $self->_l8r;
113 0 return 1;
114 }
115  
116 #-----------------------------------------------------------------------------
117  
118 0 ▶sub addPageTitleCategories {
Subroutine addPageTitleCategories: not called CC=5 SCAR=34.0
Pod documented
119 0 my ($self) = shift;
120 0 my ($pagenum,$title, @categories) = @_;
121  
122 0 ▶ defined $pagenum || (return 0);
Branch: 1 branch
BranchTrueFalseTotal
defined $pagenum or return 0 0 0 0
123 0 ▶ defined $title || ($title="");
Branch: 1 branch
BranchTrueFalseTotal
defined $title or $title = "" 0 0 0
124  
125 0 Fault::DebugPrinter->dbg
126 (2,"Toc->addPageTitleCategories [$pagenum], [$title], [@categories]");
127
128 0 ▶ ($self->_havepage (@_)) || ($self->_initpage (@_));
Branch: 1 branch
BranchTrueFalseTotal
$self->_havepage(@_) or $self->_initpage(@_) 0 0 0
129 0 ▶ ($self->_havetitle (@_)) || ($self->_inittitle (@_));
Branch: 1 branch
BranchTrueFalseTotal
$self->_havetitle(@_) or $self->_inittitle(@_) 0 0 0
130 0 $self->_mergecatlist (@_);
131 0 $self->_l8r;
132 0 return 1;
133 }
134  
135 #-----------------------------------------------------------------------------
136 # Remove operators
137 #-----------------------------------------------------------------------------
138  
139 0 ▶sub removePages {
Subroutine removePages: not called CC=3 SCAR=24.8
Pod documented
140 0 my $self = shift;
141 0 ▶ foreach my $p (@_) {($self->_havepage ($p)) && ($self->_killpage ($p));}
Branch: 1 branch
BranchTrueFalseTotal
$self->_havepage($p) and $self->_killpage($p) 0 0 0
142 0 $self->_l8r;
143 0 return 1;
144 }
145  
146 #-----------------------------------------------------------------------------
147  
148 0 ▶sub removePageTitles {
Subroutine removePageTitles: not called CC=4 SCAR=30.0
Pod documented
149 0 my ($self,$p) = (shift,shift);
150  
151 0 ▶ defined $p || (return 0);
Branch: 1 branch
BranchTrueFalseTotal
defined $p or return 0 0 0 0
152  
153 0 foreach my $t (@_) {
154 0 ▶ ($self->_havetitle ($p,$t)) && ($self->_killtitle ($p,$t));
Branch: 1 branch
BranchTrueFalseTotal
$self->_havetitle($p, $t) and $self->_killtitle($p, $t) 0 0 0
155 }
156 0 $self->_l8r;
157 0 return 1;
158 }
159  
160 #-----------------------------------------------------------------------------
161  
162 0 ▶sub removePageTitleCategories {
Subroutine removePageTitleCategories: not called CC=5 SCAR=34.0
Pod documented
163 0 my ($self,$p,$t) = (shift,shift,shift);
164  
165 0 ▶ defined $p || (return 0);
Branch: 1 branch
BranchTrueFalseTotal
defined $p or return 0 0 0 0
166 0 ▶ defined $t || (return 0);
Branch: 1 branch
BranchTrueFalseTotal
defined $t or return 0 0 0 0
167  
168 # NOTE: It is probably possible to do this all in 1 line like _mergecatlist
169 #
170 0 foreach my $c (@_) {
171 0 ▶ ($self->_havecategory ($p,$t,$c)) && ($self->_killcategory ($p,$t,$c));
Branch: 1 branch
BranchTrueFalseTotal
$self->_havecategory($p, $t, $c) and $self->_killcategory($p, $t, $c) 0 0 0
172 }
173  
174 0 $self->_l8r;
175 0 return 1;
176 }
177  
178 #-----------------------------------------------------------------------------
179 # Replace operators
180 #-----------------------------------------------------------------------------
181  
182 0 ▶sub replacePageTitle {
Subroutine replacePageTitle: not called CC=6 SCAR=37.4
Pod documented
183 0 my ($self,$p,$o,$n) = @_;
184 0 ▶ defined $p || (return 0);
Branch: 1 branch
BranchTrueFalseTotal
defined $p or return 0 0 0 0
185 0 ▶ defined $o || (return 0);
Branch: 1 branch
BranchTrueFalseTotal
defined $o or return 0 0 0 0
186 0 ▶ defined $n || (return 0);
Branch: 1 branch
BranchTrueFalseTotal
defined $n or return 0 0 0 0
187 0 ▶ (!$self->_havetitle ($p,$n)) || (return 0);
Branch: 1 branch
BranchTrueFalseTotal
$self->_havetitle($p, $n) and return 0 0 0 0
188 0 ▶ ($self->_havetitle ($p,$o)) || (return 0);
Branch: 1 branch
BranchTrueFalseTotal
$self->_havetitle($p, $o) or return 0 0 0 0
189  
190 0 $self->_duptitle ($p,$o,$n);
191 0 $self->_killtitle ($p,$o);
192 0 $self->_l8r;
193 0 return 1;
194 }
195  
196 #-----------------------------------------------------------------------------
197 # Current selection or "bookmark" methods
198 #-----------------------------------------------------------------------------
199  
200 0 ▶sub setpage {my $s=shift; return (@{$s->{'mark'}}=($s->_selpage (@_)));}
Subroutine setpage: not called CC=1 SCAR=6.9
Pod documented
201 0 ▶sub settitle {my $s=shift; return (@{$s->{'mark'}}=($s->_seltitle(@_)));}
Subroutine settitle: not called CC=1 SCAR=6.9
Pod documented
202 0 ▶sub setcategories {my $s=shift; return (@{$s->{'mark'}}=($s->_selcats ));}
Subroutine setcategories: not called CC=1 SCAR=6.9
Pod documented
203 0 ▶sub setmark {my $s=shift; return (@{$s->{'mark'}}=($s->_selall (@_)));}
Subroutine setmark: not called CC=1 SCAR=6.9
Pod documented
204  
205 0 ▶sub setfirstpage {my $s=shift;
Subroutine setfirstpage: not called CC=1 SCAR=6.9
Pod documented
206 0 return (@{$s->{'mark'}}=($s->_selpage ($s->_1stpage )));}
207 0 ▶sub setfirsttitle {my $s=shift;
Subroutine setfirsttitle: not called CC=1 SCAR=6.9
Pod documented
208 0 return (@{$s->{'mark'}}=($s->_seltitle($s->_1sttitle)));}
209  
210 #-----------------------------------------------------------------------------
211  
212 0 ▶sub curpage {my $s=shift;
Subroutine curpage: not called CC=1 SCAR=6.9
Pod documented
213 0 my ($page, $title, @categories) = @{$s->{'mark'}};
214 0 return $page;}
215  
216 0 ▶sub curtitle {my $s=shift;
Subroutine curtitle: not called CC=1 SCAR=6.9
Pod documented
217 0 my ($page, $title, @categories) = @{$s->{'mark'}};
218 0 return $title;}
219  
220 0 ▶sub curpages {return shift->pages;}
Subroutine curpages: not called CC=1 SCAR=6.9
Pod documented
221  
222 0 ▶sub curtitles {my $s=shift;
Subroutine curtitles: not called CC=1 SCAR=6.9
Pod documented
223 0 return ($s->pageTitles (@{$s->{'mark'}}));}
224  
225 0 ▶sub curcategories {my $s=shift;
Subroutine curcategories: not called CC=1 SCAR=6.9
Pod documented
226 0 return ($s->pageTitleCategories (@{$s->{'mark'}}));}
227  
228 #-----------------------------------------------------------------------------
229 # Override most parent methods
230 #-----------------------------------------------------------------------------
231  
232 0 ▶sub isMember {return shift->havePage (@_);}
Subroutine isMember: not called CC=1 SCAR=6.9
Pod documented
233 0 ▶sub addMembers {return shift->addPages (@_);}
Subroutine addMembers: not called CC=1 SCAR=6.9
Pod documented
234 0 ▶sub members {return (shift->pages (@_));}
Subroutine members: not called CC=1 SCAR=6.9
Pod documented
235 0 ▶sub removeMembers {return shift->removePages (@_);}
Subroutine removeMembers: not called CC=1 SCAR=6.9
Pod documented
236  
237 #=============================================================================
238 # Internal Methods
239 #=============================================================================
240  
241 0 ▶sub _lazy {
Subroutine _lazy: not called CC=4 SCAR=30.0
242 0 my $self = shift;
243 0 ▶ $self->SUPER::_lazy || return 0;
Branch: 1 branch
BranchTrueFalseTotal
$self->SUPER::_lazy or return 0 0 0 0
244  
245 0 my ($p,$t,@c) = @{$self->{'first'}};
246 0 ▶ $t = (defined $p) ? $self->_1sttitle($p) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $p ? : 0 0 0
247 0 ▶ @c = (defined $t) ? $self->_listcats($p,$t) : undef;
Branch: 1 branch
BranchTrueFalseTotal
defined $t ? : 0 0 0
248 0 @{$self->{'first'}} = ($p, $t, @c);
249 0 return 1;
250 }
251  
252 #=============================================================================
253 # The following are a set of internal primitive operations on the toc data
254 # structure. They are used by external methods which also do arg checking.
255 #=============================================================================
256 # Args: self
257 # Returns: _listpages returns list of pages in toc
258 # _cntpages returns the number of keys in the hash
259 # _1stpage returns the first element of the sorted keys,
260 # undef if there are none.
261  
262 0 ▶sub _listpages {return (keys %{shift->{'toc'}});}
Subroutine _listpages: not called CC=1 SCAR=6.9
263 0 ▶sub _cntpages {return shift->_cntmembers;}
Subroutine _cntpages: not called CC=1 SCAR=6.9
264 0 ▶sub _1stpage {return shift->_1stmember;}
Subroutine _1stpage: not called CC=1 SCAR=6.9
265  
266 #-----------------------------------------------------------------------------
267 # Args: self
268 # pagenum
269 # Returns: _havepage returns true or false
270 # _listtitles returns list of titles on page
271 # _1sttitle returns 1st element of sorted title hash keys
272 # others return nothing.
273  
274 0 ▶sub _initpage { shift->{'toc'}->{+shift} = {};}
Subroutine _initpage: not called CC=1 SCAR=6.9
275 0 ▶sub _killpage { delete shift->{'toc'}->{+shift};}
Subroutine _killpage: not called CC=1 SCAR=6.9
276 0 ▶sub _havepage {return exists shift->{'toc'}->{+shift};}
Subroutine _havepage: not called CC=1 SCAR=6.9
277 0 ▶sub _listtitles {return (sort keys %{shift->{'toc'}->{+shift}});}
Subroutine _listtitles: not called CC=1 SCAR=6.9
278 0 ▶sub _1sttitle {my ($s,$p)=(shift,shift);
Subroutine _1sttitle: not called CC=2 SCAR=17.9
279 0 ▶ return ($s->_cnttitles($p) > 0) ?
Branch: 1 branch
BranchTrueFalseTotal
$s->_cnttitles($p) > 0 ? : 0 0 0
280 ($s->_listtitles($p))[0] : undef;}
281  
282 #-----------------------------------------------------------------------------
283 # Args: self
284 # pagenum
285 # title
286 # Returns: _havetitle returns true or false
287 # _listcats returns list of categories for title
288 # _cnttitles returns the number of title hash keys
289 # others return nothing.
290  
291 0 ▶sub _inittitle { shift->{'toc'}->{+shift}->{+shift} = {};}
Subroutine _inittitle: not called CC=1 SCAR=6.9
292 0 ▶sub _killtitle { delete shift->{'toc'}->{+shift}->{+shift};}
Subroutine _killtitle: not called CC=1 SCAR=6.9
293 0 ▶sub _havetitle {return exists shift->{'toc'}->{+shift}->{+shift};}
Subroutine _havetitle: not called CC=1 SCAR=6.9
294 0 ▶sub _cnttitles {return ($#{ [keys %{shift->{'toc'}->{+shift}}] } + 1);}
Subroutine _cnttitles: not called CC=1 SCAR=6.9
295 0 ▶sub _listcats {return (sort keys %{shift->{'toc'}->{+shift}->{+shift}});}
Subroutine _listcats: not called CC=1 SCAR=6.9
296  
297 #-----------------------------------------------------------------------------
298 # _mergecatlist: Take the title's hash address; set all elements (if any)
299 # named in categories to undef. This will merge the new list
300 # with the existing list.
301 #
302 # Args: self
303 # pagenum
304 # title
305 # category, except _addcategory for which it is @categories
306 # Returns: _havecategory returns true or false
307 # _cntcats returns the number of category hash keys
308 # others return nothing.
309  
310 0 ▶sub _initcategory { shift->{'toc'}->{+shift}->{+shift}->{+shift}={};}
Subroutine _initcategory: not called CC=1 SCAR=6.9
311 0 ▶sub _killcategory { delete shift->{'toc'}->{+shift}->{+shift}->{+shift};}
Subroutine _killcategory: not called CC=1 SCAR=6.9
312 0 ▶sub _havecategory {return exists shift->{'toc'}->{+shift}->{+shift}->{+shift};}
Subroutine _havecategory: not called CC=1 SCAR=6.9
313 0 ▶sub _mergecatlist {my $a = shift->{'toc'}->{+shift}->{+shift};
Subroutine _mergecatlist: not called CC=1 SCAR=6.9
314 0 @$a{@_} = ();}
315  
316 0 ▶sub _cntcats {return ($#{ [keys %{shift->{'toc'}->{+shift}->{+shift}}] } + 1);}
Subroutine _cntcats: not called CC=1 SCAR=6.9
317  
318 #-----------------------------------------------------------------------------
319 # _duptitle: Set the contents of new title to the same hash as old title.
320 # (This is used before deleting the old title.)
321 #
322 # Args: self
323 # pagenum
324 # old title
325 # new title
326 # Returns: return nothing.
327  
328 0 ▶sub _duptitle {my ($s,$p,$o,$n) = @_;
Subroutine _duptitle: not called CC=1 SCAR=6.9
329 0 $s->{'toc'}->{$p}->{$n} = $s->{'toc'}->{$p}->{$o};}
330  
331 #-----------------------------------------------------------------------------
332 # Current selection or "bookmark" methods
333 #-----------------------------------------------------------------------------
334 # Build a selection based on the specified page.
335 #
336 # Args: self
337 # page or undef
338 # Returns: (undef, undef, emptyarray) or
339 # (page, undef, emptyarray) or
340 # (page, 1sttitle, emptyarray) or
341 # (page, 1sttitle, emptyarray) or
342 # (page, 1sttitle, category list)
343  
344 0 ▶sub _selpage {
Subroutine _selpage: not called CC=4 SCAR=30.0
345 0 my ($self,$page) = @_;
346 0 ▶ if (!defined $page) {return (undef,undef);}
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $page) 0 0 0
347 0 ▶ if (!$self->_havepage($page)) {return (undef,undef);}
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_havepage($page)) 0 0 0
348 0 ▶ if ($self->_cnttitles($page) < 1) {return ($page,undef);}
Branch: 1 branch
BranchTrueFalseTotal
if ($self->_cnttitles($page) < 1) 0 0 0
349  
350 0 my $title = ($self->_listtitles($page))[0];
351 0 my @categories = ($self->_listcats ($page,$title));
352  
353 0 return ($page,$title,@categories);
354 }
355  
356 #-----------------------------------------------------------------------------
357 # After selecting a page, build a selection based on the specified title.
358 #
359 # Args: self
360 # title or undef
361 # Returns: (undef, undef, emptyarray) or
362 # (page, undef, emptyarray) or
363 # (page, title, emptyarray) or
364 # (page, title, category list)
365  
366 0 ▶sub _seltitle {
Subroutine _seltitle: not called CC=4 SCAR=30.0
367 0 my ($self,$title) = @_;
368 0 my ($p,$t) = (@{$self->{'mark'}});
369  
370 0 ▶ if (!defined $p) {return (undef,undef)};
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $p) 0 0 0
371 0 ▶ if (!defined $title) {return ($p, undef);}
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $title) 0 0 0
372 0 ▶ if (!$self->_havetitle($p,$title)) {return ($p, undef);}
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_havetitle($p, $title)) 0 0 0
373  
374 0 my @categories = ($self->_listcats ($p,$title));
375  
376 0 return ($p, $title, @categories);
377 }
378  
379 #-----------------------------------------------------------------------------
380 # After selecting a page and title, add the categories, if any.
381 #
382 # NOTE: Rather redundant actually... Keep it around for now.
383 #
384 # Args: self
385 # title or undef
386 # Returns: (undef, undef, emptyarray) or
387 # (page, undef, emptyarray) or
388 # (page, title, emptyarray) or
389 # (page, title, category list)
390  
391 0 ▶sub _selcats {
Subroutine _selcats: not called CC=3 SCAR=24.8
392 0 my ($self) = @_;
393 0 my ($p,$t,@c) = (@{$self->{'mark'}});
394  
395 0 ▶ if (!defined $p) {return (undef,undef)};
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $p) 0 0 0
396 0 ▶ if (!defined $t) {return ($p, undef)};
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $t) 0 0 0
397 0 return ($p,$t,$self->_listcats ($p,$t));
398 }
399  
400 #-----------------------------------------------------------------------------
401 # After selecting a page, build a selection based on the specified title.
402 #
403 # Args: self
404 # page or undef
405 # title or undef
406 # Returns: (undef, undef, emptyarray) or
407 # (page, undef, emptyarray) or
408 # (page, title, emptyarray) or
409 # (page, title, category list)
410  
411 0 ▶sub _selall {
Subroutine _selall: not called CC=5 SCAR=34.0
412 0 my ($self,$p,$t) = @_;
413  
414 0 ▶ if (!defined $p) {return (undef,undef)};
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $p) 0 0 0
415 0 ▶ if (!$self->_havepage($p,$t)) {return (undef,undef);}
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_havepage($p, $t)) 0 0 0
416 0 ▶ if (!defined $t) {return ($p, undef);}
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $t) 0 0 0
417 0 ▶ if (!$self->_havetitle($p,$t)) {return ($p, undef);}
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->_havetitle($p, $t)) 0 0 0
418 0 return ($p,$t,$self->_listcats ($p,$t));
419 }
420
421 #=============================================================================
422 # Pod Documentation
423 #=============================================================================
424 # You may extract and format the documention section with the 'perldoc' cmd.
425  
426 =head1 NAME
427  
428 Document::Toc - Manage a Table of contents file.
429  
430 =head1 SYNOPSIS
431  
432 use Document::Toc;
433  
434 @pagelist = $obj->pages;
435 @titles = $obj->pageTitles ($pageid);
436 @categories = $obj->pageTitleCategories ($pageid, $title);
437  
438 $flg = $obj->havePage ($pageid);
439 $flg = $obj->havePageTitle ($pageid, $title);
440 $flg = $obj->havePageTitleCategory ($pageid, $title, $category);
441  
442 $flg = $obj->addPages (@pageids);
443 $flg = $obj->addPageTitles ($pageid, @titles);
444 $flg = $obj->addPageTitleCategories ($pageid, $title, @categories);
445  
446 $flg = $obj->removePages (@pageid);
447 $flg = $obj->removePageTitles ($pageid, @titles);
448 $flg = $obj->removePageTitleCategories ($pageid,$title,@categories);
449  
450 $flg = $obj->replacePageTitle ($pageid, $oldtitle, $newtitle);
451 @curselection = $obj->setpage ($page);
452 @curselection = $obj->settitle ($title);
453 @curselection = $obj->setcategories;
454 @curselection = $obj->setmark ($page, $title);
455 @curselection = $obj->setfirstpage;
456 @curselection = $obj->setfirsttitle;
457  
458 $page = $obj->curpage;
459 $title = $obj->curtitle;
460 @pages = $obj->curpages;
461 @titles = $obj->curtitles;
462 @categories = $obj->curcategories;
463  
464 @members = $obj->members;
465 $flg = $obj->isMember ($member);
466 $flg = $obj->addMembers (@members);
467 $flg = $obj->removeMembers (@members);
468  
469 =head1 Inheritance
470  
471 UNIVERSAL
472 Document::Members
473 Document::Toc
474  
475 =head1 Description
476  
477 This Class manages a table of contents object. A table of contents is
478 keyed by pageids; each pageid may have zero or more titles; each title
479 may belong to zero or more categories. It encodes the semantics of a
480 .toc file.
481  
482 001 cover
483 002 contents
484 003 --
485 005 ArticleTitleOne Space, Aeronautics
486 005 ArticleTitleTwo Biology, Genetics
487 006 backcover
488  
489 into an easily modifiable and searchable form.
490  
491 =head1 Examples
492  
493 use Document::Toc;
494 my $toc = Document::Toc->new;
495  
496 my $f = $toc->addPages ("001","002","003","005","006");
497 $f = $toc->addPageTitles ("002","TitleOne","TitleTwo");
498 $f = $toc->addPageTitleCategories ("002","TitleTwo","Biology","Genetics");
499 $f = $toc->addPageTitles ("003","TitleOne","TitleTwo");
500 $f = $toc->addPageTitleCategories ("003","TitleTwo","Biology","Genetics");
501 $f = $toc->addPageTitles ("005","TitleOne","TitleTwo");
502 $f = $toc->addPageTitleCategories ("005","TitleTwo","Biology","Genetics");
503  
504 my @pages = $toc->pages;
505 my @titles = $toc->pageTitles ("005");
506 my @categories = $toc->pageTitleCategories ("005", "TitleTwo");
507  
508 $f = $toc->havePage ("001");
509 $f = $toc->havePageTitle ("005","TitleTwo");
510 $f = $toc->havePageTitleCategory ("005","TitleTwo","Biology");
511  
512 $f = $toc->removePages ("002","006");
513 $f = $toc->removePageTitles ("003","TitleOne");
514 $f = $toc->removePageTitleCategories ("005","TitleTwo","Genetics");
515  
516 $f = $toc->replacePageTitle ("005","TitleTwo","NewTitle");
517 my @cursel = $toc->setpage ("005");
518 @cursel = $toc->settitle ("TitleTwo");
519 @cursel = $toc->setcategories;
520 @cursel = $toc->setmark ("003","TitleTwo");
521 @cursel = $toc->setfirstpage;
522 @cursel = $toc->setfirsttitle;
523  
524 my $page = $toc->curpage;
525 my $title = $toc->curtitle;
526 @pages = $toc->curpages;
527 @titles = $toc->curtitles;
528 @categories = $toc->curcategories;
529  
530 @pages = $toc->members;
531 $f = $toc->isMember ("001");
532 $f = $toc->addMembers ("004");
533 $f = $toc->removeMembers ("003");
534  
535 =head1 Class Variables
536  
537 None.
538  
539 =head1 Instance Variables
540  
541 None.
542  
543 =head1 Class Methods
544  
545 None.
546  
547 =head1 Instance Methods
548  
549 =over 4
550  
551 =item B<$flg = $obj-E<gt>addMembers (@members)>
552  
553 Overrides parent and calls addPages.
554  
555 =item B<$flg = $obj-E<gt>addPages (@pageids)>
556  
557 Add new pageids to the toc with a blank title and no categories. True if
558 it succeeds. Existing pages are unaffected.
559  
560 =item B<$flg = $obj-E<gt>addPageTitleCategories ($pageid, $title, @categories)>
561  
562 Merge new categories into the list of categories associated with title on
563 the specified page. True if it succeeds. Existing categories are unaffected.
564  
565 =item B<$flg = $obj-E<gt>addPageTitles ($pageid, @titles)>
566  
567 Add new titles to an existing pageid. True if it succeeds. Existing titles
568 are unaffected. Note that a blank title really is "" and not represented
569 by "--" as in a TocFile!
570  
571 =item B<@categories = $obj-E<gt>curcategories>
572  
573 Return a list of all categories in the current page and table selection
574 or an empty array.
575  
576 =item B<$page = $obj-E<gt>curpage>
577  
578 Return the current page name or undef if there is none.
579  
580 =item B<@pages = $obj-E<gt>curpages>
581  
582 Return a list of all pages in this Toc or undef if empty.
583  
584 =item B<$title = $obj-E<gt>curtitle>
585  
586 Return the current title or undef if there is none.
587  
588 =item B<@titles = $obj-E<gt>curtitles>
589  
590 Return a list of all titles on the current page or undef if there are none.
591  
592 =item B<$flg = $obj-E<gt>havePage ($pageid)>
593  
594 True if $pageid exists.
595  
596 =item B<$flg = $obj-E<gt>havePageTitle ($pageid, $title)>
597  
598 True if $title exists on $pageid.
599  
600 =item B<$flg = $obj-E<gt>havePageTitleCategory ($pageid, $title, $category)>
601  
602 True if $category is in use for $title on $pageid.
603  
604 =item B<$flg = $obj-E<gt>isMember ($member)>
605  
606 Overrides parent and calls havePage.
607  
608 =item B<@members = $obj-E<gt>members>
609  
610 Overrides parent and calls pages.
611  
612 =item B<@pagelist = $obj-E<gt>pages>
613  
614 Return a list of the pageids in the toc. List may be empty.
615  
616 =item B<@categories = $obj-E<gt>pageTitleCategories ($pageid, $title)>
617  
618 Return a list of all the categories associated with a specific page title.
619 List can be empty if there is no assignment of the title to a category or
620 categories yet.
621  
622 =item B<@titles = $obj-E<gt>pageTitles ($pageid)>
623  
624 Return a list of the page titles associated with a specific pageid found
625 in the .toc. List can be empty as there will always be one untitled entry
626 for each page in the Archivist::Publication's directory.
627  
628 =item B<$flg = $obj-E<gt>replacePageTitle ($pageid, $oldtitle, $newtitle)>
629  
630 Change the a title name without disturbing its' associated categories.
631 Success means a new title was created, given the category hash of the old
632 title, and the old title was deleted.
633  
634 =item B<I might want some bulk operators to do complete replacement of a
635 page title category list record.>
636  
637 =item B<$flg = $obj-E<gt>removeMembers (@members)>
638  
639 Overrides parent and calls removePages.
640  
641 =item B<$flg = $obj-E<gt>removePages (@pageid)>
642  
643 Remove pageids from the hash. Will remove all titles and their
644 associated categories that are part of the specified pages. Ignores pages
645 that don't exist. Returns true if the operation succeeds.
646  
647 =item B<$flg = $obj-E<gt>removePageTitles ($pageid, @title)>
648  
649 Remove titles and their associated categories from a pageid. Ignores
650 titles that don't exist. Returns true on success.
651  
652 =item B<$flg = $obj-E<gt>removePageTitleCategories ($pageid, $title, @category)>
653  
654 Remove categories from the specified title on the specified pageids.
655 Ignores categories which don't exist. Returns true on success.
656  
657 =item B<@curselection = $obj-E<gt>setcategories>
658  
659 Set the selection mark to start with the categories associated with the
660 current title. Return the modified current selection.
661  
662 =item B<@curselection = $obj-E<gt>setfirstpage>
663  
664 Set the selection mark to the firstpage. Return the modified current
665 selection.
666  
667 =item B<@curselection = $obj-E<gt>setfirsttitle>
668  
669 Set the selection mark to the first title on the current page. Return the
670 modified current selection.
671  
672 =item B<@curselection = $obj-E<gt>setmark ($page, $title)>
673  
674 Set the selection mark to start with the specified page and title. Return
675 the modified current selection.
676  
677 =item B<@curselection = $obj-E<gt>setpage ($page)>
678  
679 Set the selection mark to start with the specified page. Return the modified
680 current selection.
681  
682 =item B<@curselection = $obj-E<gt>settitle ($title)>
683  
684 Set the selection mark to start with the specified title on the current
685 page. Return the modified current selection.
686  
687 =back 4
688  
689 =head1 Private Class Methods
690  
691 None.
692  
693 =head1 Private Instance Methods
694  
695 =over 4
696  
697 =item B<$dideval = $obj-E<gt>_lazy>
698  
699 SUBCLASS MAY CHAIN. Chains to parent class method. If the lazy evaluation
700 bit is set, do evaluations and then clear it. Returns true if subclass
701 should carry out it's own lazy evaluation.
702  
703 This is an internal primitive operation on the members data. It assumes
704 you know what you are doing because if you screw up the lazy evaluation
705 you could create some really subtle bugs.
706  
707 =back 4
708  
709 =head1 KNOWN BUGS
710  
711 See TODO.
712  
713 =head1 SEE ALSO
714  
715 Document::Members, Fault::DebugPrinter
716  
717 =head1 AUTHOR
718  
719 Dale Amon <amon@vnl.com>
720  
721 =cut
722
723 #=============================================================================
724 # CVS HISTORY
725 #=============================================================================
726 # $Log: Toc.pm,v $
727 # Revision 1.5 2008-08-28 23:26:17 amon
728 # perldoc section regularization.
729 #
730 # Revision 1.4 2008-08-13 21:04:32 amon
731 # Third phase of reformatting to current standard.
732 #
733 # Revision 1.3 2008-08-13 20:56:53 amon
734 # Second phase of reformatting to current standard.
735 #
736 # Revision 1.2 2008-08-13 14:50:02 amon
737 # First phase of reformatting to current standard.
738 #
739 # Revision 1.1.1.1 2004-09-12 12:39:26 amon
740 # Manages a Document directory
741 #
742 # 20040813 Dale Amon <amon@islandone.org>
743 # Moved to Document:: from Archivist::
744 # to make it easier to enforce layers.
745 #
746 # 20030110 Dale Amon <amon@vnl.com>
747 # Added selection mark support
748 #
749 # 20021219 Dale Amon <amon@vnl.com>
750 # Created.
751 #
752 1 1;
« Document/TocFile.pm ↑ Summary Document/NotesFile.pm »