blib/lib/HEP/Names/LaTeX.pm

filter: Statementstmt 100% 29 / 29 Branchbran 94.4% 17 / 18 Conditioncond n/a MC/DCmcdc n/a Subroutinesub 100% 4 / 4 Podpod 100% 1 / 1 totaltotal 98.0% 51 / 52 CC 11 SCAR 21.8
CC
11
Cov
98%
particle_to_latex
11.0
BEGIN
1.0
BEGIN
1.0
CRAP 8.9
↑ Summary
1 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
2 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
3  
4 package HEP::Names::LaTeX;
5 1 $HEP::Names::LaTeX::VERSION = '0.01';
6 # ABSTRACT: formats plain names of high energy physics (HEP) particles to LaTeX
7  
8  
9 1 ▶use Exporter qw( import );
Subroutine BEGIN: called CC=1 SCAR=0.0
10  
11 1 our @EXPORT = qw( particle_to_latex );
12  
13  
14 1 my $names_to_escape = qr(psi|upsilon|gamma|tau|rho|pi|mu|eta|nu|omega);
15  
16 sub particle_to_latex
17 10 ▶{
Subroutine particle_to_latex: called CC=11 SCAR=24.0
Pod documented
18 10 ▶ return '' unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 10 10
19  
20 # in case of string literal in argument, we cannot modify @_!
21 10 my @names = @_;
22 10 foreach my $name ( @names ) {
23  
24 12 my ( $charge, $has_apo ) = ( '', '' );
25 # this probably should be done better :)
26 12 my $is_anti = $name =~ s/^anti-//;
27 # charge is at last position (plus *)
28 12 ▶ $charge = $1 if $name =~ s/(\**[0+-]+$)//;
Branch: 1 branch
BranchTrueFalseTotal
if $name =~ s/(\**[0+-]+$)// 9 3 12
29 12 ▶ $has_apo = $1 if $name =~ s/('+)//;
Branch: 1 branch
BranchTrueFalseTotal
if $name =~ s/('+)// 3 9 12
30 12 ▶ my $subscript = $1 if $name =~ s/_(.*)$//;
Branch: 1 branch
BranchTrueFalseTotal
if $name =~ s/_(.*)$// 4 8 12
31  
32 12 my $total_charge = $has_apo.$charge;
33 #$total_charge = undef unless length( $total_charge )
34  
35 # escape greek names
36 12 $name =~ s/($names_to_escape)/\\$1/gi;
37 12 ▶ $subscript =~ s/($names_to_escape)/\\$1/gi if $subscript;
Branch: 1 branch
BranchTrueFalseTotal
if $subscript 4 8 12
38  
39 # ad put it together
40 12 ▶ $name = "\\bar{$name}" if $is_anti;
Branch: 1 branch
BranchTrueFalseTotal
if $is_anti 4 8 12
41 12 ▶ $name = $name."_{$subscript}" if $subscript;
Branch: 1 branch
BranchTrueFalseTotal
if $subscript 4 8 12
42 12 ▶ $name = $name."^{$total_charge}" if length($total_charge);
Branch: 1 branch
BranchTrueFalseTotal
if length $total_charge 10 2 12
43 12 $name = "\$".$name."\$";
44 }
45  
46 10 ▶ return wantarray ? @names : $names[0];
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 1 9 10
47 }
48  
49  
50 1 1;
51  
52 __END__
↑ Summary