Page.pm

filter: Statementstmt 18.4% 12 / 65 Branchbran 0.0% 0 / 34 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 17.6% 3 / 17 Podpod 90.9% 10 / 11 totaltotal 19.6% 25 / 127 CC 19 SCAR 29.8
CC
19
Cov
12%
pagetitle
42.0
_setPageName
42.0
_validateName
20.0
CRAP 19.6
« Job.pm ↑ Summary Format.pm »
1 #================================= Page.pm ===================================
2 # Filename: Page.pm
3 # Description: Physical Page Class for Scanners.
4 # Original Author: Dale M. Amon
5 # Revised by: $Author: amon $
6 # Date: $Date: 2008-08-28 23:31:44 $
7 # Version: $Revision: 1.3 $
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 Scanner::Format;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 package Scanner::Page;
15 1 ▶use vars qw{@ISA};
Subroutine BEGIN: called CC=1 SCAR=0.0
16 1 @ISA = qw( UNIVERSAL );
17  
18 #=============================================================================
19 # CLASS METHODS
20 #=============================================================================
21 1 $Scanner::Page::DEFAULT_NAME_VERIFIER = undef;
22  
23 0 ▶sub defaultNameVerifierIs {
Subroutine defaultNameVerifierIs: not called CC=3 SCAR=24.8
Pod documented
24 0 my ($class, $obj) = @_;
25 0 ▶ if (!defined $obj) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $obj) 0 0 0
26 0 $Scanner::Page::DEFAULT_NAME_VERIFIER = undef;
27 0 return 1;
28 }
29 0 ▶ ref ($obj) || (return 0);
Branch: 1 branch
BranchTrueFalseTotal
ref $obj or return 0 0 0 0
30 0 $Scanner::Page::DEFAULT_NAME_VERIFIER = $obj;
31 0 return 1;
32 }
33  
34 #-----------------------------------------------------------------------------
35  
36 0 ▶sub new {
Subroutine new: not called CC=3 SCAR=24.8
Pod documented
37 0 my $class = shift;
38 0 my %params = @_;
39 0 my $self = bless {}, $class;
40
41 0 ▶ $self->_setFormat (\%params) || return undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->_setFormat(\%params) or return undef 0 0 0
42 0 ▶ $self->_setPageName (\%params) || return undef;
Branch: 1 branch
BranchTrueFalseTotal
$self->_setPageName(\%params) or return undef 0 0 0
43
44 0 return $self;
45 }
46  
47 #=============================================================================
48 # INSTANCE METHODS
49 #=============================================================================
50  
51 0 ▶sub pagetitle {
Subroutine pagetitle: not called CC=6 SCAR=37.4
Pod documented
52 0 my $s = shift;
53 0 my @list;
54
55 my ($date, $title, $pageid, $subtitle) =
56 0 @$s{'date','title','pageid','subtitle'};
57 0 ▶ ($pageid = "p" . $pageid) if ($pageid);
Branch: 1 branch
BranchTrueFalseTotal
if $pageid 0 0 0
58
59 0 ▶ foreach ( $date, $title, $pageid, $subtitle) {$_ && push @list, $_; }
Branch: 1 branch
BranchTrueFalseTotal
$_ and push @list, $_ 0 0 0
60 0 ▶ return undef if ($#list == -1);
Branch: 1 branch
BranchTrueFalseTotal
if $#list == -1 0 0 0
61
62 0 my $t = $list[0];
63 0 ▶ for (my $i=1; $i < $#list+1; $i++) {$t .= "-" . $list[$i]; }
Branch: 1 branch
BranchTrueFalseTotal
if ($i < $#list + 1) 0 0 0
64 0 return $t;
65 }
66  
67 #-----------------------------------------------------------------------------
68  
69 0 ▶sub info ($) {
Subroutine info: not called CC=1 SCAR=6.9
Pod documented
70 0 my $self = shift;
71 printf "[Page]\n" .
72 "Page Title: %s\n" .
73 "Date: %s\n" .
74 "Title: %s\n" .
75 "PageId: %s\n" .
76 "Subtitle: %s\n",
77 $self->pagetitle,
78 $self->{'date'},
79 $self->{'title'},
80 $self->{'pageid'},
81 0 $self->{'subtitle'};
82 0 print "\n";
83 0 $self->{'format'}->info ("Scan");
84 0 return $self;
85 }
86  
87 #-----------------------------------------------------------------------------
88  
89 0 ▶sub landscape { shift->{'format'}->landscape; }
Subroutine landscape: not called CC=1 SCAR=6.9
Pod documented
90 0 ▶sub portrait { shift->{'format'}->portrait; }
Subroutine portrait: not called CC=1 SCAR=6.9
Pod documented
91 0 ▶sub ScanDimensions {(shift->{'format'}->ScanDimensions);}
Subroutine ScanDimensions: not called CC=1 SCAR=6.9
Pod undocumented
92 0 ▶sub date { shift->{'date'}; }
Subroutine date: not called CC=1 SCAR=6.9
Pod documented
93 0 ▶sub title { shift->{'title'}; }
Subroutine title: not called CC=1 SCAR=6.9
Pod documented
94 0 ▶sub pageid { shift->{'pageid'}; }
Subroutine pageid: not called CC=1 SCAR=6.9
Pod documented
95 0 ▶sub subtitle { shift->{'subtitle'}; }
Subroutine subtitle: not called CC=1 SCAR=6.9
Pod documented
96  
97 #=============================================================================
98 # INTERNAL CLASS METHODS
99 #=============================================================================
100 # Verify that the list of elements can be used to create a page title.
101  
102 0 ▶sub _validateName {
Subroutine _validateName: not called CC=4 SCAR=30.0
103 0 my ($self,$date,$title,$pageid,$subtitle) = @_;
104
105 0 ▶ ((length($date) + length($title) + length($pageid) + length ($subtitle)) > 0)
Branch: 1 branch
BranchTrueFalseTotal
length($date) + length($title) + length($pageid) + length($subtitle) > 0 or return 0 0 0 0
106 || return 0;
107
108 0 ▶ if ($Scanner::Page::DEFAULT_NAME_VERIFIER) {
Branch: 1 branch
BranchTrueFalseTotal
if ($Scanner::Page::DEFAULT_NAME_VERIFIER) 0 0 0
109 $Scanner::Page::DEFAULT_NAME_VERIFIER->validateName
110 0 ▶ ( @$self{'date','title','pageid','subtitle'} ) || (return 0);
Branch: 1 branch
BranchTrueFalseTotal
$Scanner::Page::DEFAULT_NAME_VERIFIER->validateName(@$self{"date", "title", "pageid", "subtitle"}) or return 0 0 0 0
111 }
112 0 return 1;
113 }
114  
115 #=============================================================================
116 # INTERNAL OBJECT METHODS
117 #=============================================================================
118  
119 0 ▶sub _setPageName {
Subroutine _setPageName: not called CC=6 SCAR=37.4
120 0 my ($self, $params) = @_;
121  
122 0 @$self{'date','title', 'pageid','subtitle'} = ("", "", "", "" );
123 0 ▶ ($self->{'date'} = $params->{'date'}) if defined $params->{'date'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $params->{"date"} 0 0 0
124 0 ▶ ($self->{'title'} = $params->{'title'}) if defined $params->{'title'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $params->{"title"} 0 0 0
125 0 ▶ ($self->{'pageid'} = $params->{'pageid'}) if defined $params->{'pageid'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $params->{"pageid"} 0 0 0
126 0 ▶ ($self->{'subtitle'}= $params->{'subtitle'}) if defined $params->{'subtitle'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $params->{"subtitle"} 0 0 0
127
128 0 ▶ Scanner::Page->_validateName ( @$self{'date','title','pageid','subtitle'} )
Branch: 1 branch
BranchTrueFalseTotal
"Scanner::Page"->_validateName(@$self{"date", "title", "pageid", "subtitle"}) or return 0 0 0 0
129 || (return 0);
130 0 return 1;
131 }
132  
133 #-----------------------------------------------------------------------------
134  
135 0 ▶sub _setFormat {
Subroutine _setFormat: not called CC=2 SCAR=17.9
136 0 my ($self, $params) = @_;
137 0 ▶ defined $params->{'format'} or return 0;
Branch: 1 branch
BranchTrueFalseTotal
defined $params->{"format"} or return 0 0 0 0
138
139 0 $self->{'format'} = $params->{'format'};
140 0 return 1;
141 }
142
143 #=============================================================================
144 # POD DOCUMENTATION
145 #=============================================================================
146 # You may extract and format the documention section with the 'perldoc' cmd.
147  
148 =head1 NAME
149  
150 Scanner::Page - Representation of a Page to be passed to a Scanner.
151  
152 =head1 SYNOPSIS
153  
154 use Scanner::Page;
155  
156 $obj = Scanner::Page->new ( list of named arguments );
157 $bool = Scanner::Page->defaultNameVerifierIs ( $myverifierobj );
158  
159 $pagetitle = $obj->pagetitle;
160 $date = $obj->date;
161 $title = $obj->title;
162 $pageid = $obj->pageid;
163 $subtitle = $obj->subtitle;
164 ($width, $height) = $obj->ScanDimensions;
165 $flg = $obj->landscape;
166 $flg = $obj->portrait;
167 $obj = $obj->info;
168  
169 =head1 Inheritance
170  
171 UNIVERSAL
172  
173 =head1 Description
174  
175 Pages are transient objects used to pass information to Scanner::Device and
176 Document::Directory objects.
177  
178 =head1 Examples
179  
180 use File::Spec::Scanner::Page;
181  
182 my $flg = Scanner::Page->defaultNameVerifierIs ( $myvfyobj );
183  
184 my $pg = Scanner::Page->new ( 'format' => $fmt,
185 'date' => "20080818",
186 'title' => "DailyBoggle",
187 'pageid' => "001",
188 );
189  
190 if ($pg->landscape) {print "It is a landscape page.\n";}
191 if ($pg->portrait ) {print "It is a portrait page.\n";}
192  
193 my ($x,$y) = $pg->ScanDimensions;
194 my $pt = $obj->pagetitle;
195 my $date = $obj->date;
196 my $title = $obj->title;
197 my $pgnum = $obj->pageid;
198 my $stitle = $obj->subtitle;
199  
200 =head1 Class Variables
201  
202 DEFAULT_NAME_VERIFIER Class used for verifying a page name
203 consisting of the a set or subset of
204 date-title-pageid-subtitle. Default is undef.
205  
206 =head1 Instance Variables
207  
208 format A Scanner::Format object.
209 date The date part of the page name, eg 19941224.
210 title The document title portion of the name.
211 pageid The pageid, usually a simple page number: 104.
212 subtitle The page title portion of the name.
213  
214 =head1 Class Methods
215  
216 =over 4
217  
218 =item B<$bool = Scanner::Page-E<gt>defaultNameVerifierIs ( $obj )>
219  
220 Sets the default verifier object. Returns true if it succeeded. A false return
221 could indicate $obj is not a ref. undef is a valid value and will restore the
222 default behavior of the class, ie to do not much of anything about checking
223 the name related fields.
224  
225 A Scanner::Page has several fields for the input of strings used in
226 constructing a full page name. The actual format of these is not directly
227 enforced by this object other than a requirement that the concatenation of
228 them all generate a nonzero string length.
229  
230 In practice it is desirable to check that these fields have strings which will
231 create valid file names when put together in the form:
232  
233 date-title-pageid-subtitle
234  
235 and from which the scanner will eventually create:
236  
237 date-title-pageid-subtitle.jpeg
238  
239 If you wish each new object to check these fields rather than blindly use them
240 as it does by default, you may load a default object with this Class method.
241 Your object must have a method like this:
242  
243 $bool = $myobj->validateName ( $date, $title, $pageid, $subtitle )
244  
245 If you do nothing, only the simplest of checks, as noted earlier, are done.
246 This may be adequate for many applications which only wish to use the 'title'
247 field and nothing else.
248  
249 =item B<$obj = Scanner::Page-E<gt>new ( named argument list )>
250  
251 This is the Class method for creating new Scanner::Page objects. It may have
252 many different arguments. They are in short:
253  
254 format -> $fmtobj [REQUIRED]
255 date -> date string [OPT: default is ""]
256 title -> title string [OPT: default is ""]
257 pageid -> pageid string [OPT: default is ""]
258 subtitle -> subtitle string [OPT: default is ""]
259  
260 'format' => <Scanner::Format object>
261  
262 A format object that defines the orientation and size of the page.
263  
264 'date' => <date string>
265  
266 A date to be included as the first part of the page name, where a single date
267 is represented as:
268  
269 yyyymmdd
270 yyyymmddhhmmss
271  
272 and mm and dd may be 00 to represent 'the whole month' or the 'whole year' as
273 in a monthly magazine or a yearly report, or to represent uncertainty, 'it
274 was from sometime in that year'. there may optionally be two dates, so as to
275 represent a period of time associated with the page:
276  
277 date1-date2
278  
279 The default is the null string: "".
280  
281 'title' => <title string>
282  
283 The title associated with the document of which this page is a part or whole
284 if there is only one page. eg
285  
286 ModernQuantumTheory
287  
288 The default is the null string: "".
289  
290 'pageid' => <pageid string>
291  
292 If the document is part of a multi-page document, a representation of the page
293 number is needed. There may be two adjacent pages if the current page is an
294 opened booklet on the scanner. Pageid's may look like the following:
295  
296 000a
297 001
298 043.01
299 001-002
300  
301 The default is the null string: "".
302  
303 'subtitle' => <subtitle string>
304  
305 An individual title for the page, the name of an article within a magazine, a
306 comment about the contents of the page...
307  
308 TheCatDied-SmithAndWesson-itsNotDeadYet
309  
310 The default is the null string: "".
311  
312 It returns either a pointer to the newly created and initialized object or
313 undef if the object could not be created.
314  
315 =back 4
316  
317 =head1 Instance Methods
318  
319 =over 4
320  
321 =item B<$date = $obj-E<gt>date>
322  
323 Return the date string.
324  
325 =item B<($width, $height) = $obj-E>gt>ScanDimensions>
326  
327 Retrieve the page dimensions to be used for scanning. The height may include
328 extra space for calibration devices as earlier discussed in the
329 Scanner::Page->setDefaultCalibratorFlag section:
330  
331 (width, height+calibratorheight)
332  
333 The scanner might of course have something to say about the height or width we
334 have selected! That, however, is not the Page's problem. It is what it is and
335 it might be too large for the scanner you have.
336  
337 =item B<$obj = $obj-E<gt>info>
338  
339 Print info on the Scanner::Page to stdout.
340  
341 =item B<$flg = $obj-E<gt>landscape>
342  
343 Return true if it uses a landscape page format.
344  
345 =item B<$pageid = $obj-E<gt>pageid>
346  
347 Return the pageid string.
348  
349 =item $pagetitle = $obj->pagetitle
350  
351 Generate the full page title. There are four possible elements, any of which
352 might be null. The page title is built from whichever of date, title, pageid
353 and subtitle are non-null. The title is built up in the order:
354  
355 <date>-<title>-p<pageid>-<subtitle>
356  
357 Possible pagetitles are:
358  
359 20040819
360 20040819-QuantumTheory
361 20040819-p001
362 20040819-20100918-QuantumTheoryAdvances-p005-010-ForwardByMartians
363  
364 If somehow all four are null, undef is returned instead of a string.
365  
366 [Internal code question: how should I handle the 'p' that goes before a
367 pageid?]
368  
369 =item B<$flg = $obj-E<gt>portrait>
370  
371 Return true if it uses a portrait page format.
372  
373 =item B<$subtitle = $obj-E<gt>subtitle>
374  
375 Return the subtitle string.
376  
377 =item B<$title = $obj-E<gt>title>
378  
379 Return the title string.
380  
381 =back 4
382  
383 =head1 Private Class Methods
384  
385 None.
386  
387 =head1 Private Instance Methods
388  
389 None.
390  
391 =head1 Errors and Warnings
392  
393 None.
394  
395 =head1 KNOWN BUGS
396  
397 See TODO.
398  
399 =head1 SEE ALSO
400  
401 None.
402  
403 =head1 AUTHOR
404  
405 Dale Amon <amon@vnl.com>
406  
407 =cut
408
409 #=============================================================================
410 # CVS HISTORY
411 #=============================================================================
412 # $Log: Page.pm,v $
413 # Revision 1.3 2008-08-28 23:31:44 amon
414 # Major rewrite. Shuffled code between classes and add lots of features.
415 #
416 # Revision 1.2 2008-08-07 19:52:48 amon
417 # Upgrade source format to current standard.
418 #
419 # Revision 1.1.1.1 2006-06-15 22:06:59 amon
420 # Classes for scanner use abstractions.
421 #
422 # 20060615 Dale Amon <amon@islandone.org>
423 # Added check for an attempt to set a zero hieght or width.
424 # 20040818 Dale Amon <amon@islandone.org>
425 # Created.
426 1 1;
« Job.pm ↑ Summary Format.pm »