lib/LaTeXML/Common/Locator.pm

filter: Statementstmt 23.1% 19 / 82 Branchbran 0.0% 0 / 46 Conditioncond 0.0% 0 / 26 MC/DCmcdc 0.0% 0 / 16 Subroutinesub 35.2% 6 / 17 Podpod 81.8% 9 / 11 totaltotal 17.1% 34 / 198 CC 34 SCAR 39.7
CC
34
Cov
12%
stringify
110.0
toAttribute
72.0
newRange
56.0
CRAP 52.8
« lib/LaTeXML/Post/XSLT.pm ↑ Summary lib/LaTeXML/Post/OpenMath.pm »
1 # /=====================================================================\ #
2 # | LaTeXML::Common::Locator | #
3 # | Locators | #
4 # |=====================================================================| #
5 # | Part of LaTeXML: | #
6 # | Public domain software, produced as part of work done by the | #
7 # | United States Government & not subject to copyright in the US. | #
8 # |---------------------------------------------------------------------| #
9 # | Bruce Miller <bruce.miller@nist.gov> #_# | #
10 # | http://dlmf.nist.gov/LaTeXML/ (o o) | #
11 # \=========================================================ooo==U==ooo=/ #
12 package LaTeXML::Common::Locator;
13 5 ▶use LaTeXML::Global;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 5 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 5 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 5 ▶use base qw(LaTeXML::Common::Object);
Subroutine BEGIN: called CC=1 SCAR=0.0
17  
18 5 ▶use LaTeXML::Util::Pathname;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 5 ▶use LaTeXML::Util::WWW;
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 0 ▶sub new {
Subroutine new: not called CC=1 SCAR=6.9
Pod documented
22 0 my ($class, $source, $fromLine, $fromCol, $toLine, $toCol) = @_;
23 0 my $locator = bless { source => $source,
24 fromLine => $fromLine, fromCol => $fromCol,
25 toLine => $toLine, toCol => $toCol
26 }, $class;
27 0 return $locator; }
28  
29 # creates a new locator range from a given start and end
30 0 ▶sub newRange {
Subroutine newRange: not called CC=7 SCAR=40.3
Pod documented
31 0 my ($class, $from, $to) = @_;
32 # make sure that either parameters are defined
33 0 ▶ return $to unless defined($from);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $from 0 0 0
34 0 ▶ return $from unless defined($to);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $to 0 0 0
35 # bail if we have differnt sources
36 0 ▶ return unless ($$from{source} || '') eq ($$to{source} || '');
Branch: 1 branch
BranchTrueFalseTotal
unless ($from->{"source"} || "") eq ($to->{"source"} || "") 0 0 0
Condition0%0/4
$from->{'source'} || ''
l!l
00
$to->{'source'} || ''
l!l
00
MC/DC0%0/1
$from->{'source'} || ''
$from->{'source'}
MC/DC0%0/1
$to->{'source'} || ''
$to->{'source'}
Truth table0%0/2
A
A= $from->{'source'}
Aresult
11
00
Truth table0%0/2
A
A= $to->{'source'}
Aresult
11
00
37 # the end coordinates depend on
38 0 my ($toLine, $toCol);
39 0 ▶ if ($to->isRange) {
Branch: 1 branch
BranchTrueFalseTotal
if ($to->isRange) { } 0 0 0
40 0 $toLine = $$to{toLine};
41 0 $toCol = $$to{toCol}; }
42 else {
43 0 $toLine = $$to{fromLine};
44 0 $toCol = $$to{fromCol}; }
45 0 return new($class, $$from{source}, $$from{fromLine}, $$from{fromCol}, $toLine, $toCol); }
46  
47 0 ▶sub isRange {
Subroutine isRange: not called CC=2 SCAR=17.9
Pod documented
48 0 my ($self) = @_;
49 0 ▶ return defined($$self{toLine}) || defined($$self{toCol}); }
Condition0%0/3
defined $self->{'toLine'} || defined $self->{'toCol'}
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $self->{'toLine'} || defined $self->{'toCol'}
defined $self->{'toLine'} defined $self->{'toCol'}
Truth table0%0/3
A || B
A= defined $self->{'toLine'}B= defined $self->{'toCol'}
ABresult
1X1
011
000
50  
51 0 ▶sub getShortSource {
Subroutine getShortSource: not called CC=5 SCAR=34.0
Pod documented
52 0 my ($self, $stringSource) = @_;
53 0 my $source = $$self{source};
54 0 ▶ return ($stringSource || 'String') unless ((defined $source) && $source);
Branch: 1 branch
BranchTrueFalseTotal
unless defined $source and $source 0 0 0
Condition0%0/5
defined $source and $source
!ll&&!rl&&r
000
$stringSource || 'String'
l!l
00
MC/DC0%0/2
defined $source and $source
defined $source $source
MC/DC0%0/1
$stringSource || 'String'
$stringSource
Truth table0%0/3
A and B
A= defined $sourceB= $source
ABresult
0X0
100
111
Truth table0%0/2
A
A= $stringSource
Aresult
11
00
55 0 ▶ if (index($source, ':') > 1) { # assuming legit protocols are more than 1 char (NOT windows C:/)
Branch: 1 branch
BranchTrueFalseTotal
if (index($source, ':') > 1) { } 0 0 0
56 0 my ($path, $base, $ext) = url_split($source);
57 0 return "$base.$ext"; }
58 else {
59 0 my ($path, $base, $ext) = pathname_split($source);
60 0 return "$base.$ext"; } }
61  
62 0 ▶sub toString {
Subroutine toString: not called CC=7 SCAR=40.3
Pod documented
63 0 my ($self) = @_;
64 0 my $loc = $self->getShortSource;
65 0 ▶ $loc .= "; line $$self{fromLine}" if defined($$self{fromLine});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"fromLine"} 0 0 0
66 0 ▶ $loc .= " col $$self{fromCol}" if defined($$self{fromLine}) && defined($$self{fromCol});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"fromLine"} and defined $self->{"fromCol"} 0 0 0
Condition0%0/3
defined $self->{"fromLine"} and defined $self->{"fromCol"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"fromLine"} and defined $self->{"fromCol"}
defined $self->{"fromLine"} defined $self->{"fromCol"}
Truth table0%0/3
A and B
A= defined $self->{"fromLine"}B= defined $self->{"fromCol"}
ABresult
0X0
100
111
67 0 ▶ $loc .= " - line $$self{toLine}" if defined($$self{toLine});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"toLine"} 0 0 0
68 0 ▶ $loc .= " col $$self{toCol}" if defined($$self{toLine}) && defined($$self{toCol});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"toLine"} and defined $self->{"toCol"} 0 0 0
Condition0%0/3
defined $self->{"toLine"} and defined $self->{"toCol"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"toLine"} and defined $self->{"toCol"}
defined $self->{"toLine"} defined $self->{"toCol"}
Truth table0%0/3
A and B
A= defined $self->{"toLine"}B= defined $self->{"toCol"}
ABresult
0X0
100
111
69 0 return $loc; }
70  
71 0 ▶sub stringify {
Subroutine stringify: not called CC=10 SCAR=47.0
Pod documented
72 0 my ($self) = @_;
73 0 ▶ my $loc = defined $$self{source} ? ($$self{source} || 'Literal String') : 'Anonymous String';
Branch: 1 branch
BranchTrueFalseTotal
defined $self->{'source'} ? : 0 0 0
Condition0%0/2
$self->{"source"} or "Literal String"
l!l
00
MC/DC0%0/1
$self->{"source"} or "Literal String"
$self->{"source"}
Truth table0%0/2
A
A= $self->{"source"}
Aresult
11
00
74 0 ▶ my $rangeFrom = $self->isRange ? ' from' : '';
Branch: 1 branch
BranchTrueFalseTotal
$self->isRange ? : 0 0 0
75 0 ▶ $loc .= ";$rangeFrom line $$self{fromLine}" if defined($$self{fromLine});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"fromLine"} 0 0 0
76 0 ▶ $loc .= " col $$self{fromCol}" if defined($$self{fromLine}) && defined($$self{fromCol});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"fromLine"} and defined $self->{"fromCol"} 0 0 0
Condition0%0/3
defined $self->{"fromLine"} and defined $self->{"fromCol"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"fromLine"} and defined $self->{"fromCol"}
defined $self->{"fromLine"} defined $self->{"fromCol"}
Truth table0%0/3
A and B
A= defined $self->{"fromLine"}B= defined $self->{"fromCol"}
ABresult
0X0
100
111
77 0 ▶ $loc .= " to line $$self{toLine}" if defined($$self{toLine});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"toLine"} 0 0 0
78 0 ▶ $loc .= " col $$self{toCol}" if defined($$self{toLine}) && defined($$self{toCol});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"toLine"} and defined $self->{"toCol"} 0 0 0
Condition0%0/3
defined $self->{"toLine"} and defined $self->{"toCol"}
!ll&&!rl&&r
000
MC/DC0%0/2
defined $self->{"toLine"} and defined $self->{"toCol"}
defined $self->{"toLine"} defined $self->{"toCol"}
Truth table0%0/3
A and B
A= defined $self->{"toLine"}B= defined $self->{"toCol"}
ABresult
0X0
100
111
79 0 return $loc; }
80  
81 0 ▶sub toAttribute {
Subroutine toAttribute: not called CC=8 SCAR=42.8
Pod documented
82 0 my ($self) = @_;
83 0 my $loc = $self->getShortSource('anonymous_string') . '#text';
84 0 ▶ if ($self->isRange) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->isRange) { } 0 0 0
85 0 $loc .= 'range(from=';
86 0 ▶ $loc .= "$$self{fromLine}" if defined($$self{fromLine});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"fromLine"} 0 0 0
87 0 ▶ $loc .= ";$$self{fromCol}" if defined($$self{fromCol});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"fromCol"} 0 0 0
88 0 $loc .= ',to=';
89 0 ▶ $loc .= "$$self{toLine}" if defined($$self{toLine});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"toLine"} 0 0 0
90 0 ▶ $loc .= ";$$self{toCol}" if defined($$self{toCol});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"toCol"} 0 0 0
91 0 $loc .= ')';
92 0 return $loc; }
93 else {
94 0 $loc .= 'point(';
95 0 ▶ $loc .= "$$self{fromLine}" if defined($$self{fromLine});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"fromLine"} 0 0 0
96 0 ▶ $loc .= ";$$self{fromCol}" if defined($$self{fromCol});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"fromCol"} 0 0 0
97 0 $loc .= ')';
98 0 return $loc; } }
99  
100 0 ▶sub getLocator {
Subroutine getLocator: not called CC=1 SCAR=6.9
Pod undocumented
101 # getting the locator of a locator should return itself
102 0 my ($self) = @_;
103 0 return $self; }
104  
105 0 ▶sub getSource {
Subroutine getSource: not called CC=1 SCAR=6.9
Pod undocumented
106 0 my ($self) = @_;
107 0 return $self; }
108  
109 0 ▶sub getFromLocator {
Subroutine getFromLocator: not called CC=1 SCAR=6.9
Pod documented
110 0 my ($self) = @_;
111 0 return LaTeXML::Common::Locator->new($$self{source}, $$self{fromLine}, $$self{fromCol}); }
112  
113 0 ▶sub getToLocator {
Subroutine getToLocator: not called CC=1 SCAR=6.9
Pod documented
114 0 my ($self) = @_;
115 0 return LaTeXML::Common::Locator->new($$self{source}, $$self{toLine}, $$self{toCol}); }
116  
117 #**********************************************************************
118 5 1;
119  
120 __END__
« lib/LaTeXML/Post/XSLT.pm ↑ Summary lib/LaTeXML/Post/OpenMath.pm »