AutoTeX/StampPDF.pm

filter: Statementstmt 40.5% 15 / 37 Branchbran 0.0% 0 / 18 Conditioncond 0.0% 0 / 6 MC/DCmcdc 0.0% 0 / 4 Subroutinesub 80.0% 4 / 5 Podpod 100% 1 / 1 totaltotal 28.1% 20 / 71 CC 12 SCAR 47.6
CC
12
Cov
25%
stamp_pdf
156.0
BEGIN
1.0
BEGIN
1.0
CRAP 117.2
« AutoTeX/PostScript.pm ↑ Summary AutoTeX.pm »
1 package TeX::AutoTeX::StampPDF;
2  
3 #
4 # $Id: StampPDF.pm,v 1.9.2.7 2011/01/27 18:42:29 thorstens Exp $
5 # $Revision: 1.9.2.7 $
6 # $Source: /cvsroot/arxivlib/arXivLib/lib/TeX/AutoTeX/StampPDF.pm,v $
7 #
8 # $Date: 2011/01/27 18:42:29 $
9 # $Author: thorstens $
10 #
11  
12 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 ### use warnings;
14 1 ▶use Carp qw(cluck carp);
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 1 our ($VERSION) = '$Revision: 1.9.2.7 $' =~ m{ \$Revision: \s+ (\S+) }x;
17  
18 1 ▶use parent qw(Exporter);
Subroutine BEGIN: called CC=1 SCAR=0.0
19 1 our @EXPORT_OK = qw(stamp_pdf);
20 1 ▶use CAM::PDF;
Subroutine BEGIN: called CC=1 SCAR=0.0
21  
22 0 ▶sub stamp_pdf {
Subroutine stamp_pdf: not called CC=12 SCAR=50.5
Pod documented
23 0 my ($file, $stampref) = @_;
24  
25 0 ▶ if (!(-r $file && ref $stampref eq 'ARRAY')) {
Branch: 1 branch
BranchTrueFalseTotal
unless (-r $file and ref $stampref eq "ARRAY") 0 0 0
Condition0%0/3
-r $file and ref $stampref eq "ARRAY"
!ll&&!rl&&r
000
MC/DC0%0/2
-r $file and ref $stampref eq "ARRAY"
-r $file ref $stampref eq "ARRAY"
Truth table0%0/3
A and B
A= -r $fileB= ref $stampref eq "ARRAY"
ABresult
0X0
100
111
26 #FIXME: pod2usage;
27 0 throw TeX::AutoTeX::FatalException "must provide pdf file and stamp contents\n";
28 }
29  
30 # 6 * 72 - 1/2 * stringlength * 10
31 # (10 = approx average char width in 20pt Times-Roman)
32 0 my $yoffset = 432 - 5 * length $stampref->[0];
33  
34 # minimal arXiv stamp used as a page overlay in grayscale
35 0 my $pdfstamp = <<"EOSTAMP";
36 q
37 0.5 G 0.5 g
38 BT
39 /arXivStAmP 20 Tf 0 1 -1 0 32 $yoffset Tm
40 ($stampref->[0])Tj
41 ET
42 Q
43 EOSTAMP
44  
45 0 ▶ rename($file, "$file.bk") || throw TeX::AutoTeX::FatalException q{couldn't backup PDF file};
Branch: 1 branch
BranchTrueFalseTotal
rename $file, "$file.bk" or "TeX::AutoTeX::FatalException"->throw("couldn't backup PDF file") 0 0 0
46  
47 eval {
48 0 ▶ my $doc = CAM::PDF->new("$file.bk") || cluck "$CAM::PDF::errstr\n";
Condition0%0/3
'CAM::PDF'->new("$file.bk") || cluck("$CAM::PDF::errstr\n")
l!l&&r!l&&!r
000
MC/DC0%0/2
'CAM::PDF'->new("$file.bk") || cluck("$CAM::PDF::errstr\n")
'CAM::PDF'->new("$file.bk") cluck("$CAM::PDF::errstr\n")
Truth table0%0/3
A || B
A= 'CAM::PDF'->new("$file.bk")B= cluck("$CAM::PDF::errstr\n")
ABresult
1X1
011
000
49 0 ▶ if (!$doc->canModify()) {
Branch: 1 branch
BranchTrueFalseTotal
unless ($doc->canModify) 0 0 0
50 0 throw TeX::AutoTeX::FatalException "This PDF forbids modification\n";
51 }
52  
53 0 $doc->appendPageContent(1, $pdfstamp);
54 0 ▶ $doc->addFont(1, 'Times-Roman', 'arXivStAmP') || cluck "$CAM::PDF::errstr\n";
Branch: 1 branch
BranchTrueFalseTotal
$doc->addFont(1, "Times-Roman", "arXivStAmP") or cluck("$CAM::PDF::errstr\n") 0 0 0
55 0 $doc->preserveOrder();
56 0 ▶ $doc->cleanoutput($file) || cluck "$CAM::PDF::errstr\n";
Branch: 1 branch
BranchTrueFalseTotal
$doc->cleanoutput($file) or cluck("$CAM::PDF::errstr\n") 0 0 0
57 0 1;
58 0 ▶ } or do {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { my $doc = "CAM::PDF"->new("$file.bk") || cluck("$CAM::PDF::errstr\n"); unless ($doc->canModify) { "TeX::AutoTeX::FatalException"->throw("This PDF forbids modification\n"); } ; $doc->appendPageContent(1, $pdfstamp); $doc->addFont(1, "Times-Roman", "arXivStAmP") or cluck("$CAM::PDF::errstr\n"); $doc->preserveOrder; $doc->cleanoutput($file) or cluck("$CAM::PDF::errstr\n"); 1 } } or do { rename "$file.bk", $file or carp("woe is me, now that failed"); "TeX::AutoTeX::FatalException"->throw("stamp operation did not complete\n") } 0 0 0
59 0 ▶ rename("$file.bk", $file) || carp 'woe is me, now that failed';
Branch: 1 branch
BranchTrueFalseTotal
rename "$file.bk", $file or carp("woe is me, now that failed") 0 0 0
60 0 throw TeX::AutoTeX::FatalException "stamp operation did not complete\n";
61 };
62 0 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 0 0 0
63 0 ▶ rename("$file.bk", $file) || carp 'woe is me, now that failed';
Branch: 1 branch
BranchTrueFalseTotal
rename "$file.bk", $file or carp("woe is me, now that failed") 0 0 0
64 0 throw TeX::AutoTeX::FatalException "an error occurred during stamp operation, reverted to original file\n";
65 }
66 0 unlink "$file.bk";
67 0 return 0;
68 }
69  
70 1 1;
71  
72 __END__
« AutoTeX/PostScript.pm ↑ Summary AutoTeX.pm »