AutoTeX.pm

filter: Statementstmt 33.3% 31 / 93 Branchbran 0.0% 0 / 42 Conditioncond 0.0% 0 / 17 MC/DCmcdc 0.0% 0 / 10 Subroutinesub 69.2% 9 / 13 Podpod 100% 3 / 3 totaltotal 24.1% 43 / 178 CC 28 SCAR 46.0
CC
28
Cov
20%
__combine_dvips_flags
182.0
process
132.0
new
30.0
CRAP 99.7
« AutoTeX/StampPDF.pm ↑ Summary AutoTeX/Mail.pm »
1 package TeX::AutoTeX;
2  
3 #
4 # $Id: AutoTeX.pm,v 1.20.2.7 2011/01/27 18:56:29 thorstens Exp $
5 # $Revision: 1.20.2.7 $
6 # $Source: /cvsroot/arxivlib/arXivLib/lib/TeX/AutoTeX.pm,v $
7 #
8 # $Date: 2011/01/27 18:56:29 $
9 # $Author: thorstens $
10 #
11  
12 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
13 ### use warnings;
14 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 # our ($VERSION) = '$Revision: 1.20.2.7 $' =~ m{ \$Revision: \s+ (\S+) }x;
17 2 our $VERSION = 'v0.906.0';
18  
19 2 ▶use TeX::AutoTeX::Config qw(
Subroutine BEGIN: called CC=1 SCAR=0.0
20 $AUTOTEX_ENV_PATH
21 $DEFAULTPSRESOLUTION
22 $DEFAULT_BRANCH
23 $DEFAULT_TEX_BIN_PATH
24 2 );
25 2 ▶use TeX::AutoTeX::Fileset;
Subroutine BEGIN: called CC=1 SCAR=0.0
26 2 ▶use TeX::AutoTeX::File;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 2 ▶use TeX::AutoTeX::Log;
Subroutine BEGIN: called CC=1 SCAR=0.0
28 2 ▶use TeX::AutoTeX::Process;
Subroutine BEGIN: called CC=1 SCAR=0.0
29 2 ▶use TeX::AutoTeX::Mail;
Subroutine BEGIN: called CC=1 SCAR=0.0
30  
31 2 ▶use parent qw(Class::Accessor::Fast);
Subroutine BEGIN: called CC=1 SCAR=0.0
32 2 __PACKAGE__->follow_best_practice();
33 2 __PACKAGE__->mk_accessors(
34 qw(
35 workdir
36 branch
37 use_stamp
38 stampref
39 log
40 verbose
41 send_email
42 dvips_paper_type
43 dvips_resolution
44 dvips_printer
45 dvips_mapfile
46 output_format
47 is_pdftex
48 tex_env_path
49 )
50 );
51  
52 0 ▶sub new {
Subroutine new: not called CC=5 SCAR=34.0
Pod documented
53 0 my $class = shift;
54 0 my $self = {
55 workdir => undef,
56 branch => undef,
57 use_stamp => 1,
58 stampref => undef,
59 log => undef,
60 send_email => 0,
61 verbose => undef,
62 dvips_paper_type => undef,
63 dvips_resolution => $DEFAULTPSRESOLUTION,
64 dvips_printer => undef,
65 dvips_mapfile => undef,
66 @_,
67 };
68 0 ▶ if (!defined $self->{workdir}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"workdir"}) 0 0 0
69 0 croak 'no directory holding the unpacked source material defined';
70 }
71 0 ▶ if ($self->{workdir} ne 'will be derived from paper id'
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"workdir"} ne "will be derived from paper id" and (stat $self->{"workdir"})[2] != 16895 and (stat _)[2] != 16893) 0 0 0
Condition0%0/6
$self->{"workdir"} ne "will be derived from paper id" and (stat $self->{"workdir"})[2] != 16895 and (stat _)[2] != 16893
!ll&&!rl&&r
000
$self->{"workdir"} ne "will be derived from paper id" and (stat $self->{"workdir"})[2] != 16895
!ll&&!rl&&r
000
MC/DC0%0/3
$self->{"workdir"} ne "will be derived from paper id" and (stat $self->{"workdir"})[2] != 16895 and (stat _)[2] != 16893
$self->{"workdir"} ne "will be derived from paper id" (stat $self->{"workdir"})[2] != 16895 (stat _)[2] != 16893
Truth table0%0/4
A and B and C
A= $self->{"workdir"} ne "will be derived from paper id"B= (stat $self->{"workdir"})[2] != 16895C= (stat _)[2] != 16893
ABCresult
0XX0
10X0
1100
1111
72 && (stat $self->{workdir})[2] != oct(40777)
73 && (stat(_))[2] != oct(40775)) {
74 0 croak "workdir '$self->{workdir}' is not a directory or doesn't have mode 0777 or 0775";
75 }
76  
77 0 bless $self, $class;
78 }
79  
80 0 ▶sub process {
Subroutine process: not called CC=11 SCAR=48.8
Pod documented
81 0 my $self = shift;
82  
83 0 local ($?, $!, $@);
84  
85 0 ▶ if (!$self->{branch}) { # use the latest branch, unless specified otherwise
Branch: 1 branch
BranchTrueFalseTotal
unless ($self->{"branch"}) 0 0 0
86 0 $self->{branch} = $DEFAULT_BRANCH;
87 0 $self->{tex_env_path} = $DEFAULT_TEX_BIN_PATH;
88 0 local $ENV{TEXMFCNF} = q{}; # prevent inadvertent problems due to user settings
89 }
90 0 ▶ if (ref $self->{log} ne 'TeX::AutoTeX::Log') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{"log"} ne "TeX::AutoTeX::Log") 0 0 0
91 $self->{log} = TeX::AutoTeX::Log->new(
92 dir => $self->{workdir},
93 verbose => $self->{verbose},
94 0 ▶ dupefh => $self->{verbose} ? \*STDOUT : undef,
Branch: 1 branch
BranchTrueFalseTotal
$self->{'verbose'} ? : 0 0 0
95 );
96 }
97  
98 my $p = $self->{process} =
99 TeX::AutoTeX::Process->new(
100 log => $self->{log},
101 fileset => $self->{fileset},
102 temp_dir => $self->{workdir},
103 branch => $self->{branch},
104 stampref => $self->{stampref},
105 use_stamp => $self->{use_stamp},
106 decryption_key => $self->{decryption_key},
107 tex_env_path => $self->{tex_env_path}? $self->{tex_env_path}
108 0 ▶ : "/$self->{branch}/bin:/bin",
Branch: 1 branch
BranchTrueFalseTotal
$self->{'tex_env_path'} ? : 0 0 0
109 );
110  
111 0 ▶ if ($self->__combine_dvips_flags()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->__combine_dvips_flags) 0 0 0
112 0 $p->set_dvi_flags(@{$self->{dvi_flags}})
113 }
114  
115 0 ▶ if (ref $self->{stampref} ne 'ARRAY') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self->{"stampref"} ne "ARRAY") 0 0 0
116 0 $p->{use_stamp} = 0;
117 }
118  
119 0 local $ENV{PATH} = $AUTOTEX_ENV_PATH; # also untaints path
120  
121 0 ▶ if ($p->{error} = $p->go()) {
Branch: 1 branch
BranchTrueFalseTotal
if ($p->{"error"} = $p->go) 0 0 0
122 0 $self->{log}->verbose("AutoTeX returned error: $p->{error}");
123 # optionally send failure notification email to admin
124 0 ▶ if ($self->{send_email}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"send_email"}) 0 0 0
125 0 $self->email();
126 }
127 0 return;
128 }
129 0 ▶ if (@{$p->{made_pdf}}) {
Branch: 1 branch
BranchTrueFalseTotal
if (@{$p->{"made_pdf"};}) 0 0 0
130 $self->{log}->verbose('PDFTEX paper, check "'
131 . ($self->{paper} ? $self->{paper} : $self->{workdir})
132 0 ▶ . qq{".\n});
Branch: 1 branch
BranchTrueFalseTotal
$self->{'paper'} ? : 0 0 0
133 0 $self->set_is_pdftex(1);
134 }
135  
136 0 $self->{log}->verbose("All done.\n");
137 0 return 1;
138 }
139  
140 0 ▶sub __combine_dvips_flags {
Subroutine __combine_dvips_flags: not called CC=13 SCAR=52.0
141 0 my $self = shift;
142 0 $self->{dvi_flags} = [];
143 0 ▶ if ($self->{dvips_paper_type} && $self->{dvips_paper_type} =~ /^([a-z0-9]+)$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"dvips_paper_type"} and $self->{"dvips_paper_type"} =~ /^([a-z0-9]+)$/i) 0 0 0
Condition0%0/3
$self->{"dvips_paper_type"} and $self->{"dvips_paper_type"} =~ /^([a-z0-9]+)$/i
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"dvips_paper_type"} and $self->{"dvips_paper_type"} =~ /^([a-z0-9]+)$/i
$self->{"dvips_paper_type"} $self->{"dvips_paper_type"} =~ /^([a-z0-9]+)$/i
Truth table0%0/3
A and B
A= $self->{"dvips_paper_type"}B= $self->{"dvips_paper_type"} =~ /^([a-z0-9]+)$/i
ABresult
0X0
100
111
144 0 push @{$self->{dvi_flags}}, "-t $1";
145 }
146 0 ▶ if (defined $self->{dvips_printer}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"dvips_printer"}) 0 0 0
147 0 ▶ if ($self->{dvips_printer} =~ /(?:type1|pdf)/i) {
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'dvips_printer'} =~ /(?:type1|pdf)/i) { } 0 0 0
elsif ($self->{'dvips_printer'} eq 'pk') { } 0 0 0
148 0 push @{$self->{dvi_flags}}, '-P type1';
149 0 $self->{output_format} = 'fInm';
150 } elsif ($self->{dvips_printer} eq 'pk') {
151 # TS: new for texlive 12/2009
152 0 push @{$self->{dvi_flags}}, '-P pk';
153 }
154 }
155 0 ▶ if ($self->{dvips_resolution} && $self->{dvips_resolution} =~ /^([346]00)$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"dvips_resolution"} and $self->{"dvips_resolution"} =~ /^([346]00)$/) 0 0 0
Condition0%0/3
$self->{"dvips_resolution"} and $self->{"dvips_resolution"} =~ /^([346]00)$/
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"dvips_resolution"} and $self->{"dvips_resolution"} =~ /^([346]00)$/
$self->{"dvips_resolution"} $self->{"dvips_resolution"} =~ /^([346]00)$/
Truth table0%0/3
A and B
A= $self->{"dvips_resolution"}B= $self->{"dvips_resolution"} =~ /^([346]00)$/
ABresult
0X0
100
111
156 0 ▶ if ($1 != $DEFAULTPSRESOLUTION) {
Branch: 1 branch
BranchTrueFalseTotal
if ($1 != $TeX::AutoTeX::DEFAULTPSRESOLUTION) 0 0 0
157 0 push @{$self->{dvi_flags}}, "-D $1";
158 0 ▶ $self->{output_format} ||= "d$1"; # don't overwrite 'fInm'
Condition0%0/2
$self->{"output_format"} ||= "d$1"
l!l
00
MC/DC0%0/1
$self->{"output_format"} ||= "d$1"
$self->{"output_format"}
Truth table0%0/2
A
A= $self->{"output_format"}
Aresult
11
00
159 }
160 }
161 0 ▶ if ($self->{dvips_mapfile} && $self->{dvips_mapfile} =~ /^\+?([a-z]+\.map)$/i) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"dvips_mapfile"} and $self->{"dvips_mapfile"} =~ /^\+?([a-z]+\.map)$/i) 0 0 0
Condition0%0/3
$self->{"dvips_mapfile"} and $self->{"dvips_mapfile"} =~ /^\+?([a-z]+\.map)$/i
!ll&&!rl&&r
000
MC/DC0%0/2
$self->{"dvips_mapfile"} and $self->{"dvips_mapfile"} =~ /^\+?([a-z]+\.map)$/i
$self->{"dvips_mapfile"} $self->{"dvips_mapfile"} =~ /^\+?([a-z]+\.map)$/i
Truth table0%0/3
A and B
A= $self->{"dvips_mapfile"}B= $self->{"dvips_mapfile"} =~ /^\+?([a-z]+\.map)$/i
ABresult
0X0
100
111
162 0 push @{$self->{dvi_flags}}, "-u +$1";
163 }
164 0 ▶ return wantarray ? @{$self->{dvi_flags}} : scalar @{$self->{dvi_flags}};
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
165 }
166  
167 0 ▶sub email {
Subroutine email: not called CC=2 SCAR=17.9
Pod documented
168 0 my $self = shift;
169  
170 0 my $dvips_options = $self->{process}->dvi_flags_tostring();
171  
172 0 my $mailer = TeX::AutoTeX::Mail->new($self->{workdir});
173 0 ▶ if (my $msg = $mailer->send_failure("Failure for $self->{workdir}", <<"EOM")
Branch: 1 branch
BranchTrueFalseTotal
if (my $msg = $mailer->send_failure(qq[Failure for $self->{"workdir"}], qq[ $self->{"workdir"} failed autotex,\n dvips run with options '${dvips_options}'.\n\n $self->{"process"}{"error"}\n])) 0 0 0
174 $self->{workdir} failed autotex,
175 dvips run with options '$dvips_options'.
176  
177 $self->{process}->{error}
178 EOM
179 ) {
180 0 $self->{log}->verbose("send_failure error: $msg");
181 }
182 0 return;
183 }
184  
185 2 1;
186  
187 __END__
« AutoTeX/StampPDF.pm ↑ Summary AutoTeX/Mail.pm »