Document/Directory.pm

filter: Statementstmt 41.9% 26 / 62 Branchbran 0.0% 0 / 12 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 57.1% 8 / 14 Podpod 66.6% 4 / 6 totaltotal 40.4% 38 / 94 CC 7 SCAR 26.4
CC
7
Cov
35%
open
42.0
add
6.0
pagename
2.0
CRAP 14.0
« Document/NotesFile.pm ↑ Summary Document/LogFile.pm »
1 #============================== Directory.pm =================================
2 # Filename: Directory.pm
3 # Description: Manage an archival Document directory.
4 # Original Author: Dale M. Amon
5 # Revised by: $Author: amon $
6 # Date: $Date: 2008-08-28 23:26:17 $
7 # Version: $Revision: 1.2 $
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 File::Spec;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 1 ▶use File::Spec::PublicationPage;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 1 ▶use Fault::ErrorHandler;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 ▶use Document::LogFile;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 1 ▶use Document::TocFile;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 1 ▶use Document::Toc;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 package Document::Directory;
21 1 ▶use vars qw{@ISA};
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 @ISA = qw( UNIVERSAL );
23  
24 #=============================================================================
25 # CLASS METHODS
26 #=============================================================================
27  
28 0 ▶sub open ($$$$) {
Subroutine open: not called CC=6 SCAR=37.4
Pod documented
29 0 my ($class,$path,$date,$title) = @_;
30 0 my $self = bless {}, $class;
31 0 my $abspath = File::Spec->rel2abs ($path);
32 0 my $fs = File::Spec::PublicationPage->new ("$abspath/$date-$title");
33  
34 0 ▶ if (system ("mkdir", "-p", $fs->pathname) != 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (system("mkdir", "-p", $fs->pathname) != 0) 0 0 0
35 0 Fault::ErrorHandler->warn
36 ("Could not mkdir -p " . $fs->pathname . "\n");
37 }
38 0 my $tocpath = $fs->pathname . "/.toc";
39 0 my $logpath = $fs->pathname . "/.log";
40 0 my $log = Document::LogFile->new ($fs->pathname);
41 0 ▶ (-e $logpath) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
-e $logpath or return undef 0 0 0
42
43 # Open or create .toc file as necessary; create a toc object in memory.
44 0 my $toc = Document::Toc->new ();
45 0 my $tocfile = Document::TocFile->open ( $fs->rootpath,
46 $fs->dates,
47 $fs->undated_filename );
48
49 # If we created the .toc, log the fact and flush to instantiate it.
50 0 ▶ if (! -e $tocpath) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-e $tocpath) 0 0 0
51 0 ▶ $tocfile->flush or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$tocfile->flush or return undef 0 0 0
52 0 ▶ $log->log ("Created table of contents") or return undef;
Branch: 1 branch
BranchTrueFalseTotal
$log->log("Created table of contents") or return undef 0 0 0
53 }
54  
55 0 @$self{'filespec','log','toc','tocfile'} = ($fs,$log,$toc,$tocfile);
56  
57 0 return $self;
58 }
59  
60 #=============================================================================
61 # INSTANCE METHODS
62 #=============================================================================
63  
64 0 ▶sub add ($$$) {
Subroutine add: not called CC=2 SCAR=17.9
Pod documented
65 0 my ($self,$pageid,$titles) = @_;
66 0 my ($log,$tocfile,$toc) = @$self{'log','tocfile','toc'};
67  
68 0 ▶ (-e $self->pagepath($pageid)) or return undef;
Branch: 1 branch
BranchTrueFalseTotal
-e $self->pagepath($pageid) or return undef 0 0 0
69  
70 0 $log->log ("$pageid Scanned");
71  
72 0 $toc->addPageTitles ($pageid, ($titles) );
73
74 # Merge new data so we can go back and add or rescan pages in an existing
75 # document.
76 0 $tocfile->mergeFrom ($toc);
77 0 $tocfile->flush;
78  
79 0 return $self;
80 }
81  
82 #-----------------------------------------------------------------------------
83  
84 0 ▶sub pagename ($$) {
Subroutine pagename: not called CC=1 SCAR=6.9
Pod documented
85 0 my ($self,$pageid) = @_;
86 0 my $fs = $self->{'filespec'};
87 0 return $fs->dates . "-" . $fs->undated_filename . "-p" . $pageid;
88 }
89  
90 #-----------------------------------------------------------------------------
91  
92 0 ▶sub pagepath ($$) {
Subroutine pagepath: not called CC=1 SCAR=6.9
Pod documented
93 0 my ($self,$pageid) = @_;
94 0 my $fs = $self->{'filespec'};
95 0 return $fs->pathname . "/" . $self->pagename($pageid) . ".jpeg";
96 }
97  
98 #-----------------------------------------------------------------------------
99  
100 0 ▶sub filespec ($) {shift->{'filespec'}};
Subroutine filespec: not called CC=1 SCAR=6.9
Pod undocumented
101  
102 #-----------------------------------------------------------------------------
103  
104 0 ▶sub info ($) {
Subroutine info: not called CC=1 SCAR=6.9
Pod undocumented
105 0 my $self = shift;
106 0 my $fs = $self->{'filespec'};
107  
108 0 printf "[Document]\n" .
109 "Document Location: %s\n" .
110 "Document Name: %s\n" .
111 "Date: %s\n" .
112 "Title: %s\n",
113 $fs->rootpath,
114 $fs->filename,
115 $fs->dates,
116 $fs->undated_filename;
117 0 return $self;
118 }
119
120 #=============================================================================
121 # POD DOCUMENTATION
122 #=============================================================================
123 # You may extract and format the documention section with the 'perldoc' cmd.
124  
125 =head1 NAME
126  
127 Document::Directory - Manage an archival Document directory.
128  
129 =head1 SYNOPSIS
130  
131 use Document::Directory;
132 $obj = Document::Directory->open($path,$date,$title);
133 $obj = $obj->add ($pageid,$tiles);
134 $str = $obj->pagename ($pageid);
135 $str = $obj->pagepath ($pageid);
136 $fs = $obj->filespec;
137 $obj = $obj->info;
138  
139 =head1 Inheritance
140  
141 UNIVERSAL
142  
143 =head1 Description
144  
145 Manage a Document directory. A document directory contains images of document
146 pages along with a table of contents file (.toc) and a log of what has been
147 done to the document and pages in it. A Document is not a transient object
148 that will be edited or updated. It is an artifact that once created should
149 not be modified.
150  
151 There are of course some cases in which such changes might be needed. If a
152 page scan is badly done there might be a good reason to replace it. In such
153 cases the old page scan will be saved along with the new one.
154  
155 While content should not be changed, the .toc file and the file naming can
156 be modified, but the fact of such changes will be logged.
157  
158 =head1 Examples
159  
160 None.
161  
162 =head1 Class Variables
163  
164 None.
165  
166 =head1 Instance Variables
167  
168 filespec A filespec object containing the document name and location
169 logfile A document log file object.
170 tocfile A document table of contents file object
171 toc In memory copy of the table of contents.
172  
173 =head1 Class Methods
174  
175 =over 4
176  
177 =item B<$obj = Document::Directory-E<gt>open ($path,$date,$title)>
178  
179 Create and initialize instances of Document::Directory for a document that
180 is located at $path and has a name of "$date-$title".
181  
182 =head1 Instance Methods
183  
184 =over 4
185  
186 =item B<$obj = $obj-E<gt>add ($pageid,$titles)>
187  
188 If a the file associated with $pageid exists, add the page id and titles to the .toc
189 file and log the date and time at which this was done.
190  
191 Returns undef if any of these actions failed.
192  
193 =item B<$str = $obj-E<gt>pagename ($pageid)>
194  
195 Return the complete page name for $pageid. The name does not
196 include a file extension.
197  
198 =item B<$str = $obj-E<gt>pagepath ($pageid)>
199  
200 Return the absolute path name which should be used to access $pageid. The
201 file extension is assumed to be .jpeg.
202  
203 =item B<$fs = $obj-E<gt>filespec)>
204  
205 Return the filespec object which contains the document name and location.
206  
207 =item B<$fs = $obj-E<gt>filespec)>
208  
209 Print information about the document:
210  
211 [Document]
212 Document Location: /Archive/Publications/NuclearHobbiest/
213 Document Name: 20080827-NuclearHobbiest
214 Date: 20080827
215 Title: NuclearHobbiest
216  
217 =back 4
218  
219 =head1 Private Class Method
220  
221 None.
222  
223 =head1 Private Instance Methods
224  
225 None.
226  
227 =head1 KNOWN BUGS
228  
229 See TODO.
230  
231 =head1 Errors and Warnings
232  
233 None.
234  
235 =head1 SEE ALSO
236  
237 Document::Toc, Document::TocFile, Document::LogFile
238  
239 =head1 AUTHOR
240  
241 Dale Amon <amon@vnl.com>
242  
243 =cut
244
245 #=============================================================================
246 # CVS HISTORY
247 #=============================================================================
248 # $Log: Directory.pm,v $
249 # Revision 1.2 2008-08-28 23:26:17 amon
250 # perldoc section regularization.
251 #
252 # Revision 1.1 2008-08-28 15:43:20 amon
253 # Added Directory class to handle document directory
254 #
255 # Revision 1.2 2008-08-07 19:52:48 amon
256 # Upgrade source format to current standard.
257 #
258 # Revision 1.1.1.1 2008-08-06 21:36:11 amon
259 # Classes for scanner use abstractions.
260 #
261 # 20070511 Dale Amon <amon@islandone.org>
262 # Created.
263 1 1;
« Document/NotesFile.pm ↑ Summary Document/LogFile.pm »