blib/lib/Text/Starfish.pm

filter: Statementstmt 89.2% 859 / 962 Branchbran 56.2% 278 / 494 Conditioncond 63.8% 46 / 72 MC/DCmcdc 41.6% 20 / 48 Subroutinesub 100% 264 / 264 Podpod 51.6% 31 / 60 totaltotal 78.8% 1498 / 1900 CC 287 SCAR 26.8
CC
287
Cov
77%
read_records
306.0
read_starfish_conf
42.0
process_files
25.2
CRAP 14.6
↑ Summary testfiles/23-methods/test.pl »
1 # Starfish - Perl-based System for Preprocessing and Text-Embedded Programming
2 #
3 # (c) 2001-2021 Vlado Keselj https://web.cs.dal.ca/~vlado vlado@dnlp.ca
4 # and contributing authors
5 #
6 # See the documentation following the code. You can also use the
7 # command "perldoc Starfish.pm".
8  
9 package Text::Starfish;
10 5 ▶use vars qw($NAME $ABSTRACT $VERSION); use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 $NAME = 'Text::Starfish';
12 4 $ABSTRACT = 'Perl-based System for Preprocessing and Text-Embedded Programming';
13 4 $VERSION = '1.39';
14  
15 5 ▶use POSIX;
Subroutine BEGIN: called CC=1 SCAR=0.0
16 5 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 5 ▶use Cwd qw(cwd);
Subroutine BEGIN: called CC=1 SCAR=0.0
18 5 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
19 5 ▶use vars qw($VERSION @ISA @EXPORT @EXPORT_OK %EXPORT_TAGS); # Exporter vars
Subroutine BEGIN: called CC=1 SCAR=0.0
20  
21 4 @ISA = qw(Exporter);
22 4 %EXPORT_TAGS = ( 'all' => [qw(
23 add_hook appendfile echo file_modification_date
24 file_modification_time getfile getmakefilelist get_verbatim_file
25 getinclude htmlquote include
26 last_update putfile read_records read_starfish_conf rm_hook set_out_delimiters
27 sfish_add_tag sfish_ignore_outer starfish_cmd make_gen_dirs_to_generate
28 make_add_dirs_to_generate_if_needed
29 ) ] );
30 4 @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } );
31 4 @EXPORT = @{ $EXPORT_TAGS{'all'} };
32  
33 # Used in starfishing Makefiles
34 5 ▶use vars qw(@DirGenerateIfNeeded);
Subroutine BEGIN: called CC=1 SCAR=0.0
35  
36 # non-exported package globals
37 5 ▶use vars qw($GlobalREPLACE);
Subroutine BEGIN: called CC=1 SCAR=0.0
38  
39 sub appendfile($@);
40 sub getfile($ );
41 sub getmakefilelist($$);
42 sub htmlquote($ );
43 sub putfile($@);
44 sub read_records($ );
45 sub starfish_cmd(@);
46  
47 47 ▶sub new($@) {
Subroutine new: called CC=8 SCAR=22.1
Pod documented
48 47 my $proto = shift;
49 47 ▶ my $class = ref($proto) || $proto;
Condition33%1/3
ref $proto || $proto
l!l&&r!l&&!r
0460
MC/DC0%0/2
ref $proto || $proto
ref $proto $proto
Truth table33%1/3
A || B
A= ref $protoB= $proto
ABresult
1X1
011
000
50 47 my $self = {};
51 47 bless($self, $class);
52  
53 47 $self->{Loops} = 1;
54 47 my $copyhooks = '';
55 47 foreach (@_) {
56 3 ▶ if (/^-infile=(.*)$/) { $self->{INFILE} = $1 }
Branch: 2 branches
BranchTrueFalseTotal
if (/^-infile=(.*)$/) { } 2 0 2
elsif (/^-copyhooks$/) { } 0 0 0
57 1 elsif (/^-copyhooks$/) { $copyhooks = 1 }
58 1 else { _croak("unknown new option: $_") }
59 }
60  
61 47 ▶ if ($copyhooks) {
Branch: 1 branch
BranchTrueFalseTotal
if ($copyhooks) 0 46 46
62 1 ▶ _croak("new: cannot copyhooks if Star is not there") unless
Branch: 1 branch
BranchTrueFalseTotal
unless ref $main::Star eq "Text::Starfish" 0 0 0
63 ref($::Star) eq 'Text::Starfish';
64 1 $self->{Style} = $::Star->{Style};
65 1 $self->{CodePreparation} = $::Star->{CodePreparation};
66 1 $self->{LineComment} = $::Star->{LineComment};
67 1 $self->{OutDelimiters} = $::Star->{OutDelimiters};
68 1 $self->{IgnoreOuter} = $::Star->{IgnoreOuter};
69 1 $self->{hook} = [ @{ $::Star->{hook} } ];
70 }
71  
72 47 ▶ $self->set_style() unless $copyhooks;
Branch: 1 branch
BranchTrueFalseTotal
unless $copyhooks 46 0 46
73  
74 47 return $self;
75 }
76  
77 45 ▶sub starfish_cmd(@) {
Subroutine starfish_cmd: called CC=9 SCAR=22.0
Pod documented
78 45 my $sf = Text::Starfish->new();
79 45 my @tmp = ();
80 45 foreach (@_) {
81 122 ▶ if (/^-e=?/) { $sf->{INITIAL_CODE} = $' }
Branch: 5 branches
BranchTrueFalseTotal
if (/^-e=?/) { } 32 89 121
elsif (/^-mode=/) { } 2 87 89
elsif (/^-o=/) { } 26 61 87
elsif (/^-replace$/) { } 16 45 61
elsif (/^-v$/) { } 0 45 45
82 3 elsif (/^-mode=/) { $sf->{NEW_FILE_MODE} = $' }
83 27 elsif (/^-o=/) { $sf->{OUTFILE} = $' }
84 17 elsif (/^-replace$/) { $sf->{REPLACE} = $GlobalREPLACE = 1; }
85 1 elsif (/^-v$/) { print "$NAME, version $VERSION, $ABSTRACT\n"; exit 0; }
86 46 else { push @tmp, $_ }
87 }
88  
89 45 ▶ if (defined $sf->{NEW_FILE_MODE} and $sf->{NEW_FILE_MODE} =~ /^0/)
Branch: 1 branch
BranchTrueFalseTotal
if (defined $sf->{"NEW_FILE_MODE"} and $sf->{"NEW_FILE_MODE"} =~ /^0/) 2 42 44
Condition66%2/3
defined $sf->{"NEW_FILE_MODE"} and $sf->{"NEW_FILE_MODE"} =~ /^0/
!ll&&!rl&&r
4202
MC/DC50%1/2
defined $sf->{"NEW_FILE_MODE"} and $sf->{"NEW_FILE_MODE"} =~ /^0/
defined $sf->{"NEW_FILE_MODE"} $sf->{"NEW_FILE_MODE"} =~ /^0/
Truth table66%2/3
A and B
A= defined $sf->{"NEW_FILE_MODE"}B= $sf->{"NEW_FILE_MODE"} =~ /^0/
ABresult
0X0
100
111
90 3 { $sf->{NEW_FILE_MODE} = oct($sf->{NEW_FILE_MODE}) }
91  
92 45 $sf->process_files(@tmp);
93 43 return $sf;
94 }
95  
96 2 ▶sub include($@) { $::O .= getinclude(@_); return 1; }
Subroutine include: called CC=1 SCAR=0.0
Pod documented
97  
98 3 ▶sub getinclude($@) {
Subroutine getinclude: called CC=2 SCAR=6.9
Pod documented
99 3 my $sf = loadinclude(@_);
100 3 ▶ return '' unless defined $sf;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $sf 1 1 2
101 2 $sf->_digest();
102 2 return $sf->{Out}; }
103  
104 3 ▶sub loadinclude($@) {
Subroutine loadinclude: called CC=10 SCAR=24.0
Pod documented
105 3 my $infile = '';
106 3 my @args = ();
107 3 my $replace = 1;
108 3 my $require = '';
109 3 foreach (@_) {
110 3 ▶ if (/^-replace$/) { $replace = 1 }
Branch: 4 branches
BranchTrueFalseTotal
if (/^-replace$/) { } 0 2 2
elsif (/^-noreplace$/) { } 0 2 2
elsif (/^-require$/) { } 0 2 2
elsif (not /^-/ and $infile eq '') { } 2 0 2
111 1 elsif (/^-noreplace$/) { $replace = '' }
112 1 elsif (/^-require$/) { $require = 1 }
113 3 ▶ elsif (!/^-/ && $infile eq '') { $infile = $_ }
Condition33%1/3
not /^-/ and $infile eq ""
!ll&&!rl&&r
002
MC/DC0%0/2
not /^-/ and $infile eq ""
not /^-/ $infile eq ""
Truth table33%1/3
not(A) and B
A= not /^-/B= $infile eq ""
ABresult
0X0
100
111
114 1 else { push @args, $_ }
115 }
116  
117 3 my $sf = Text::Starfish->new("-infile=$infile", @args);
118 3 $sf->{REPLACE} = $replace;
119  
120 3 ▶ if ($sf->{INFILE} eq '' or ! -r $sf->{INFILE} ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($sf->{"INFILE"} eq "" or not -r $sf->{"INFILE"}) 1 1 2
Condition66%2/3
$sf->{"INFILE"} eq "" or not -r $sf->{"INFILE"}
l!l&&r!l&&!r
011
MC/DC50%1/2
$sf->{"INFILE"} eq "" or not -r $sf->{"INFILE"}
$sf->{"INFILE"} eq "" not -r $sf->{"INFILE"}
Truth table66%2/3
A or not(B)
A= $sf->{"INFILE"} eq ""B= not -r $sf->{"INFILE"}
ABresult
1X1
011
000
121 2 ▶ if ($require) { _croak("cannot getinclude file: ($sf->{INFILE})") }
Branch: 1 branch
BranchTrueFalseTotal
if ($require) 0 1 1
122 2 return undef;
123 }
124  
125 2 $sf->{data} = getfile $sf->{INFILE};
126 2 return $sf; }
127  
128 45 ▶sub process_files {
Subroutine process_files: called CC=24 SCAR=32.3
Pod documented
129 45 my $self = shift;
130 45 my @args = @_;
131  
132 45 ▶ if (defined $self->{REPLACE} and !defined $self->{OUTFILE})
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"REPLACE"} and not defined $self->{"OUTFILE"}) 0 44 44
Condition66%2/3
defined $self->{"REPLACE"} and not defined $self->{"OUTFILE"}
!ll&&!rl&&r
28160
MC/DC0%0/2
defined $self->{"REPLACE"} and not defined $self->{"OUTFILE"}
defined $self->{"REPLACE"} not defined $self->{"OUTFILE"}
Truth table66%2/3
A and not(B)
A= defined $self->{"REPLACE"}B= not defined $self->{"OUTFILE"}
ABresult
0X0
100
111
133 1 { _croak("Starfish:output file required for replace") }
134  
135 45 my $FileCount=0;
136 45 $self->eval1($self->{INITIAL_CODE}, 'initial');
137  
138 45 ▶ while (@args) {
Branch: 1 branch
BranchTrueFalseTotal
if (@args) 45 42 87
139 46 $self->{INFILE} = shift @args;
140 46 ++$FileCount;
141 46 $self->set_style();
142 46 $self->{data} = getfile $self->{INFILE};
143  
144 # *123* we need to forbid defining an outfile externally as well as
145 # internally:
146 46 ▶ my $outfileExternal = exists($self->{OUTFILE}) ? $self->{OUTFILE} : '';
Branch: 1 branch
BranchTrueFalseTotal
exists $self->{'OUTFILE'} ? : 26 19 45
147  
148 46 my $ExistingText = '';
149 46 ▶ if (! defined $self->{OUTFILE}) {
Branch: 3 branches
BranchTrueFalseTotal
if (not defined $self->{'OUTFILE'}) { } 19 26 45
elsif ($FileCount > 1) { } 0 26 26
elsif (not -f $self->{'OUTFILE'}) { } 23 3 26
150 20 $ExistingText = $self->{data};
151 20 $self->{LastUpdateTime} = (stat $self->{INFILE})[9];
152 }
153 elsif ($FileCount > 1) {
154 1 $ExistingText = '';
155 1 $self->{LastUpdateTime} = time;
156 }
157 elsif (! -f $self->{OUTFILE}) {
158 24 $ExistingText = '';
159 24 $self->{LastUpdateTime} = time;
160 }
161 else {
162 4 $ExistingText = getfile $self->{OUTFILE};
163 4 $self->{LastUpdateTime} = (stat $self->{OUTFILE})[9];
164 }
165  
166 46 $self->_digest();
167  
168 # see *123* above
169 44 ▶ if ($outfileExternal ne '' and $outfileExternal ne $self->{OUTFILE})
Branch: 1 branch
BranchTrueFalseTotal
if ($outfileExternal ne "" and $outfileExternal ne $self->{"OUTFILE"}) 0 43 43
Condition66%2/3
$outfileExternal ne "" and $outfileExternal ne $self->{"OUTFILE"}
!ll&&!rl&&r
19240
MC/DC0%0/2
$outfileExternal ne "" and $outfileExternal ne $self->{"OUTFILE"}
$outfileExternal ne "" $outfileExternal ne $self->{"OUTFILE"}
Truth table66%2/3
A and B
A= $outfileExternal ne ""B= $outfileExternal ne $self->{"OUTFILE"}
ABresult
0X0
100
111
170 1 { _croak("OUTFILE defined externally ($outfileExternal) and ".
171 "internally ($self->{OUTFILE})") }
172  
173 44 my $InFile = $self->{INFILE};
174 44 ▶ if ($FileCount==1 && defined $self->{OUTFILE}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($FileCount == 1 and defined $self->{"OUTFILE"}) 24 19 43
Condition100%3/3
$FileCount == 1 and defined $self->{"OUTFILE"}
!ll&&!rl&&r
11824
MC/DC100%2/2
$FileCount == 1 and defined $self->{"OUTFILE"}
$FileCount == 1 defined $self->{"OUTFILE"}
Truth table100%3/3
A and B
A= $FileCount == 1B= defined $self->{"OUTFILE"}
ABresult
0X0
100
111
175 # touch the outfile if it does not exist
176 25 ▶ if ( ! -f $self->{OUTFILE} ) {
Branch: 2 branches
BranchTrueFalseTotal
if (not -f $self->{'OUTFILE'}) { } 22 2 24
elsif (defined $self->{'NEW_FILE_MODE'}) { } 0 2 2
177 23 putfile $self->{OUTFILE};
178 23 my $infile_mode = (stat $InFile)[2];
179 23 ▶ if (defined $self->{NEW_FILE_MODE}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'NEW_FILE_MODE'}) { } 2 20 22
180 3 chmod $self->{NEW_FILE_MODE}, $self->{OUTFILE}}
181 21 else { chmod $infile_mode, $self->{OUTFILE} }
182 }
183 elsif (defined $self->{NEW_FILE_MODE}) {
184 1 chmod $self->{NEW_FILE_MODE}, $self->{OUTFILE} }
185 }
186  
187 # write the text if changed
188 44 ▶ if ($ExistingText ne $self->{Out}) {
Branch: 2 branches
BranchTrueFalseTotal
if ($ExistingText ne $self->{'Out'}) { } 38 5 43
elsif (defined $self->{'NEW_FILE_MODE'}) { } 0 5 5
189 39 ▶ if (defined $self->{OUTFILE}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'OUTFILE'}) { } 22 16 38
190 # If the OutFile is defined, we may have to play with
191 # permissions in order to write. Be careful! Allow
192 # unallowed write only on outfile and if -mode is
193 # specified
194 23 my $mode = ((stat $self->{OUTFILE})[2]);
195 23 ▶ if (($mode & 0200) == 0 and defined $self->{NEW_FILE_MODE}) {
Branch: 1 branch
BranchTrueFalseTotal
if (($mode & 128) == 0 and defined $self->{'NEW_FILE_MODE'}) { } 1 21 22
Condition66%2/3
($mode & 128) == 0 and defined $self->{"NEW_FILE_MODE"}
!ll&&!rl&&r
2101
MC/DC50%1/2
($mode & 128) == 0 and defined $self->{"NEW_FILE_MODE"}
($mode & 128) == 0 defined $self->{"NEW_FILE_MODE"}
Truth table66%2/3
A and B
A= ($mode & 128) == 0B= defined $self->{"NEW_FILE_MODE"}
ABresult
0X0
100
111
196 2 chmod $mode|0200, $self->{OUTFILE};
197 2 ▶ if ($FileCount==1) { putfile $self->{OUTFILE}, $self->{Out} }
Branch: 1 branch
BranchTrueFalseTotal
if ($FileCount == 1) { } 1 0 1
198 1 else { appendfile $self->{OUTFILE}, $self->{Out} }
199 2 chmod $mode, $self->{OUTFILE};
200 } else {
201 22 ▶ if ($FileCount==1) { putfile $self->{OUTFILE}, $self->{Out} }
Branch: 1 branch
BranchTrueFalseTotal
if ($FileCount == 1) { } 21 0 21
202 1 else { appendfile $self->{OUTFILE}, $self->{Out} }
203 }
204 }
205 else {
206 17 putfile $InFile, $self->{Out};
207 17 ▶ chmod $self->{NEW_FILE_MODE}, $InFile if defined $self->{NEW_FILE_MODE};
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"NEW_FILE_MODE"} 0 16 16
208 }
209 }
210 elsif (defined $self->{NEW_FILE_MODE}) {
211 1 ▶ if (defined $self->{OUTFILE}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'OUTFILE'}) { } 0 0 0
212 1 chmod $self->{NEW_FILE_MODE}, $self->{OUTFILE} }
213 1 else { chmod $self->{NEW_FILE_MODE}, $InFile }
214 }
215 } # end of while (@args)
216  
217 } # end of method process_files
218  
219 47 ▶sub _digest {
Subroutine _digest: called CC=12 SCAR=24.9
220 47 my $self = shift;
221 47 $self->{CurrentLoop} = 1;
222 47 my $savedcontent = $self->{data};
223
224 START: # The main scanning loop
225 54 $self->{Out} = '';
226 54 $self->_scan();
227 54 ▶ while ($self->{ttype} != -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"ttype"} != -1) 765 51 816
228 766 ▶ if ($self->{ttype} > -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'ttype'} > -1) { } 720 45 765
229 721 $self->{Out} .= $self->_evf_dispatch;
230 } # else $ttype < -1 (outer text)
231 46 else { $self->_process_outer( $self->{currenttoken} ) }
232 764 $self->_scan(); }
233
234 52 ▶ if ($self->{CurrentLoop} < $self->{Loops}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"CurrentLoop"} < $self->{"Loops"}) 7 44 51
235 8 ++$self->{CurrentLoop};
236 8 ▶ if ($self->{REPLACE}) { # in replace mode interate with
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"REPLACE"}) 1 6 7
237 2 $self->{data} = $savedcontent; # original input
238 2 goto START; }
239 7 $self->{data} = $self->{Out};
240 7 ▶ if ($savedcontent ne $self->{Out})
Branch: 1 branch
BranchTrueFalseTotal
if ($savedcontent ne $self->{"Out"}) 6 0 6
241 7 { $self->{LastUpdateTime} = time }
242 7 putfile 'sfish.debug', $self->{data};
243 7 goto START; }
244  
245 # Final routines, if defined
246 45 ▶ if (defined($self->{Final})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"Final"}) 2 42 44
247 3 my @a = @{ $self->{Final} };
248 3 local $::Star = $self;
249 3 for my $f (@a) {
250 3 $self->{Out} = &{$f}($self->{Out}); }}
251
252 # Related to the macro concept (e.g. code folding)
253 45 ▶ if (defined $self->{macrosdefined}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"macrosdefined"}) 6 38 44
254 7 my ($m, $s);
255 7 for $m (sort keys %{$self->{Macros}}) {
256 11 $s = $self->{Macros}->{$m};
257 11 ▶ if ($s =~ /\n/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($s =~ /\n/) 10 0 10
258 11 my $p1 = "$`$&"; $s = $';
259 11 ▶ if ($s) { $s = $p1.wrap($s) }
Branch: 1 branch
BranchTrueFalseTotal
if ($s) { } 10 0 10
260 1 else { $s = $p1 }
261 }
262 11 $self->{Out}.= $self->{MprefAuxDefine}.$s.$self->{MsufAuxDefine};
263 }
264 }
265 } # end of sub _digest
266  
267 # process outer text; by default, it should be appended to $self->{Out}
268 766 ▶sub _process_outer {
Subroutine _process_outer: called CC=3 SCAR=11.0
269 766 my $self = shift; my $outer = shift;
270 766 ▶ if ($self->{REPLACE} && $self->{IgnoreOuter}) { }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'REPLACE'} and $self->{'IgnoreOuter'}) { } 20 745 765
Condition100%3/3
$self->{"REPLACE"} and $self->{"IgnoreOuter"}
!ll&&!rl&&r
15658920
MC/DC100%2/2
$self->{"REPLACE"} and $self->{"IgnoreOuter"}
$self->{"REPLACE"} $self->{"IgnoreOuter"}
Truth table100%3/3
A and B
A= $self->{"REPLACE"}B= $self->{"IgnoreOuter"}
ABresult
0X0
100
111
271 746 else { $self->{Out} .= $outer }
272 # Comment: something should be done if IgnoreOuter is true and
273 # not in REPLACE mode; maybe comment-out outer text? (todo?)
274 }
275  
276 # _index($str,$substr) or _index($str, qr/../)
277 # returns index and length of found match, index==-1 for not found
278 # third argument is an optional offset
279 3304 ▶sub _index {
Subroutine _index: called CC=6 SCAR=17.9
280 3304 my $str = shift; my $subs = shift; my $off = shift;
281 3304 ▶ if (ref($subs) eq 'Regexp') {
Branch: 2 branches
BranchTrueFalseTotal
if (ref $subs eq 'Regexp') { } 145 3158 3303
elsif ($off < 1) { } 2920 238 3158
282 146 ▶ if ($off < 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($off < 1) { } 134 11 145
283 135 ▶ if ($str =~ $subs) { return (length($`),length($&)) }
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /$subs/) { } 11 123 134
284 124 else { return (-1,0) }
285 } else {
286 12 pos($str) = $off;
287 12 ▶ if ($str =~ /$subs/g) { return (length($`),length($&)) }
Branch: 1 branch
BranchTrueFalseTotal
if ($str =~ /$subs/g) { } 11 0 11
288 1 else { return (-1,0) }
289 }
290 }
291 2921 elsif ($off < 1) { return (index($str, $subs), length($subs)) }
292 239 else { return (index($str, $subs, $off), length($subs)) }
293 }
294  
295 # Scanning for the best hook match
296 766 ▶sub _scan_for_hook_match {
Subroutine _scan_for_hook_match: called CC=22 SCAR=31.0
297 766 my $self = shift;
298 766 $self->{prefix} = $self->{suffix} = '';
299 766 $self->{args} = [];
300
301 766 my $i1 = length($self->{data}) + 1; # distance to starting anchor
302 766 my $i2 = $i1; # distance to ending anchor
303 766 my $pl=0; my $sl=0; # prefix and suffix lengths
304 766 $self->{ttype} = -2; # token type == hook id
305 766 foreach my $ttype (0 .. $#{ $self->{hook} }) {
306 5207 my $hook = $self->{hook}->[$ttype];
307 5207 my ($j, $pl2, $j2, $sl2); # current token under consideration,
308 # $j dist to candidate starting achor
309 # $j2 dist to candidate ending anchor
310 # pl2 and sl2 - lengths of prefix and suffix
311 5207 my $ht = $hook->{ht};
312 5207 ▶ if ($ht eq '') { # guessing hook type if not defined
Branch: 1 branch
BranchTrueFalseTotal
if ($ht eq "") 135 5071 5206
313 136 ▶ if (exists($hook->{begin})) { $ht = $hook->{ht} = 'be' }
Branch: 1 branch
BranchTrueFalseTotal
if (exists $hook->{'begin'}) { } 135 0 135
314 1 else { $ht = $hook->{ht} = 'regex' } }
315  
316 5207 ▶ if ($ht eq 'string') {
Branch: 4 branches
BranchTrueFalseTotal
if ($ht eq 'string') { } 2 5204 5206
elsif ($ht eq 'be') { } 3035 2169 5204
elsif ($ht eq 'regex') { } 2157 12 2169
elsif ($ht eq 'ht:re2') { } 12 0 12
317 3 ($j,$pl2) = _index($self->{data}, $hook->{s});
318 3 ▶ next unless $j != -1 && $j <= $i1;
Branch: 1 branch
BranchTrueFalseTotal
unless $j != -1 and $j <= $i1 1 1 2
Condition66%2/3
$j != -1 and $j <= $i1
!ll&&!rl&&r
101
MC/DC50%1/2
$j != -1 and $j <= $i1
$j != -1 $j <= $i1
Truth table66%2/3
A and B
A= $j != -1B= $j <= $i1
ABresult
0X0
100
111
319 2 ▶ next if $j==$i1 and $i2<=$j+$pl2;
Branch: 1 branch
BranchTrueFalseTotal
if $j == $i1 and $i2 <= $j + $pl2 0 1 1
Condition33%1/3
$j == $i1 and $i2 <= $j + $pl2
!ll&&!rl&&r
100
MC/DC0%0/2
$j == $i1 and $i2 <= $j + $pl2
$j == $i1 $i2 <= $j + $pl2
Truth table33%1/3
A and B
A= $j == $i1B= $i2 <= $j + $pl2
ABresult
0X0
100
111
320 2 $i1 = $j; $pl = $pl2; $self->{ttype} = $ttype; $self->{args} = [];
321 2 $i2 = $i1+$pl; $sl = 0;
322 } elsif ($ht eq 'be') {
323 3036 ($j,$pl2) = _index($self->{data}, $hook->{'begin'});
324 3036 ▶ next unless $j != -1 && $j <= $i1;
Branch: 1 branch
BranchTrueFalseTotal
unless $j != -1 and $j <= $i1 2775 260 3035
Condition100%3/3
$j != -1 and $j <= $i1
!ll&&!rl&&r
268689260
MC/DC100%2/2
$j != -1 and $j <= $i1
$j != -1 $j <= $i1
Truth table100%3/3
A and B
A= $j != -1B= $j <= $i1
ABresult
0X0
100
111
325 261 ▶ if ($hook->{'end'} ne '') {
Branch: 1 branch
BranchTrueFalseTotal
if ($hook->{'end'} ne '') { } 260 0 260
326 261 ($j2, $sl2) = _index($self->{data}, $hook->{'end'}, $j);
327 261 ▶ next if -1 == $j2;
Branch: 1 branch
BranchTrueFalseTotal
if -1 == $j2 10 250 260
328 1 } else { $j2 = length($self->{data}) + 1; $sl2 = 0; }
329 251 ▶ next if ($j==$i1 and $i2<=$j2);
Branch: 1 branch
BranchTrueFalseTotal
if $j == $i1 and $i2 <= $j2 8 242 250
Condition100%3/3
$j == $i1 and $i2 <= $j2
!ll&&!rl&&r
24118
MC/DC100%2/2
$j == $i1 and $i2 <= $j2
$j == $i1 $i2 <= $j2
Truth table100%3/3
A and B
A= $j == $i1B= $i2 <= $j2
ABresult
0X0
100
111
330 243 $i1 = $j; $pl = $pl2; $i2 = $j2; $sl = $sl2;
331 243 $self->{ttype} = $ttype; $self->{args} = [];
332 } elsif ($ht eq 'regex') {
333 2158 my @args = ($self->{data} =~ /$hook->{regex}/m);
334 2158 ▶ next unless @args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 1187 970 2157
335 971 my $j = length($`);
336 971 ▶ next unless $j < $i1;
Branch: 1 branch
BranchTrueFalseTotal
unless $j < $i1 428 542 970
337 543 $i1 = $j; $i2 = $i1+length($&); $sl=$pl=0;
338 543 unshift @args, $&; # could be removed
339 543 $self->{ttype} = $ttype;
340 543 $self->{args} = \@args;
341 } elsif ($ht eq 'ht:re2') {
342 13 my @args = ($self->{data} =~ /$hook->{regex}/m);
343 13 ▶ next unless @args;
Branch: 1 branch
BranchTrueFalseTotal
unless @args 4 8 12
344 9 my $j = length($`);
345 9 ▶ next unless $j < $i1;
Branch: 1 branch
BranchTrueFalseTotal
unless $j < $i1 0 8 8
346 9 $i1 = $j; $i2 = $i1+length($&); $sl=$pl=0;
347 9 unshift @args, $&; # full match is prepended to @args !?to remove?
348 9 $self->{ttype} = $ttype;
349 9 $self->{args} = \@args;
350 1 } else { _croak("Unknown hook type: ($ht)"); }
351 }
352 766 $self->{match_ij} = [$i1,$i2,$pl,$sl];
353 }
354  
355 # $self->{ttype}: -1 EOF
356 # -2 outer text (but also handled directly)
357 817 ▶sub _scan {
Subroutine _scan: called CC=5 SCAR=16.1
358 817 my $self = shift;
359 817 $self->{prefix} = $self->{suffix} = ''; $self->{args} = [];
360 817 ▶ if ($self->{data} eq '') { # no more data, EOF
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'data'} eq '') { } 51 765 816
361 52 $self->{ttype} = -1; # ttype==-1 is EOF
362 52 $self->{currenttoken} = '';
363 }
364 else {
365 766 $self->_scan_for_hook_match();
366 766 my ($i1,$i2,$pl,$sl) = @{ $self->{match_ij} };
367 766 ▶ if ($self->{ttype}==-2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{'ttype'} == -2) { } 45 720 765
368 46 $self->{currenttoken}=$self->{data}; $self->{data}='' }
369 else { # live code
370 # just copy type -2
371 # instead of returning as earlier, to
372 # support negative look-back for prefix
373 # $self->{Out} .= substr($self->{data}, 0, $i1);
374 721 $self->_process_outer( substr($self->{data}, 0, $i1) );
375 721 $self->{prefix} = substr($self->{data}, $i1, $pl);
376 721 $self->{currenttoken} = substr($self->{data}, $i1+$pl, $i2-$i1-$pl);
377 721 $self->{suffix} = substr($self->{data}, $i2, $sl);
378 721 $self->{data} = substr($self->{data}, $i2+$sl);
379 # Remove old output if it is there:
380 721 ▶ if (defined($self->{OutDelimiters})) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"OutDelimiters"}) 720 0 720
381 721 my ($b1,$b2,$e1,$e2) = @{ $self->{OutDelimiters} };
382 721 ▶ if ($self->{data} =~ /^\Q$b1\E(\d*)\Q$b2\E.*?\Q$e1\E\1\Q$e2\E/s) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"data"} =~ /^\Q$b1\E(\d*)\Q$b2\E.*?\Q$e1\E\1\Q$e2\E/s) 26 694 720
383 27 $self->{data} = $'; }
384 }
385 }
386 }
387 817 return $self->{ttype};
388 }
389  
390 # _evf_dispatch should decide how to properly call the evaluator (evf), or just
391 # apply replacement. It should eventually be used for string-based evaluators.
392 721 ▶sub _evf_dispatch {
Subroutine _evf_dispatch: called CC=7 SCAR=19.5
393 721 my $self = shift;
394 721 my $hook = $self->{hook}->[$self->{ttype}]; my $ht = $hook->{ht};
395 721 local $::Star = $self;
396 721 local $::O = '';
397 721 ▶ if ($ht eq 'string') { $::O .= $hook->{evf_const};
Branch: 4 branches
BranchTrueFalseTotal
if ($ht eq 'string') { } 1 719 720
elsif ($hook->{'ht'} eq 'regex') { } 525 194 719
elsif ($hook->{'ht'} eq 'ht:re2') { } 8 186 194
elsif (@{$self->{'args'};}) { } 0 186 186
398 } elsif ($hook->{ht} eq 'regex') {
399 526 $::O .= &{ $hook->{replace} } ( $self, @{ $self->{args} } ); #!!!
400 } elsif ($hook->{ht} eq 'ht:re2') { #!!! python/make style eval
401 # evaluation function uses its own output
402 # wrap and attachement.
403 9 return &{$hook->{replace}}( $self, @{ $self->{args} } );
404 187 } elsif ( @{$self->{args}} ) { # guessing regex hook type
405 1 return &{$hook->{replace}}( $self, @{ $self->{args} } );
406 } else {
407 187 return &{$hook->{f}}
408 187 ( $self, $self->{prefix}, $self->{currenttoken}, $self->{suffix});
409 }
410  
411 527 ▶ return $::O if $self->{REPLACE};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"REPLACE"} 524 2 526
412 3 ▶ return $self->{currenttoken} if $::O eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $main::O eq "" 0 2 2
413 return $self->{currenttoken}.
414 3 $self->_output_wrap( $::O );
415 }
416  
417 # eval wrapper for string code
418 272 ▶sub eval1 {
Subroutine eval1: called CC=4 SCAR=13.9
Pod undocumented
419 272 my $self = shift;
420 272 ▶ my $code = shift; $code = '' unless defined $code;
Branch: 1 branch
BranchTrueFalseTotal
unless defined $code 13 258 271
421 272 my $comment = shift;
422 4 ▶ eval("package main; no strict; $code");
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
Subroutine BEGIN: called CC=1 SCAR=0.0
423 272 ▶ if ($@) {
Branch: 1 branch
BranchTrueFalseTotal
if ($@) 1 270 271
424 2 my ($code1, $linecnt);
425 2 foreach (split(/\n/, $code))
426 3 { ++$linecnt; $code1 .= sprintf("%03d %s\n", $linecnt, $_); }
427 2 _croak("$comment code error:$@\ncode:\n$code1");
428 }
429 }
430  
431 # The main subroutine for evaluating a snippet of string
432 133 ▶sub _evaluate {
Subroutine _evaluate: called CC=5 SCAR=16.1
433 133 my $self = shift;
434  
435 133 my $pref = shift;
436 133 my $code = shift; my $c = $code;
437 133 my $suf = shift;
438 133 ▶ if (defined($self->{CodePreparation}) && $self->{CodePreparation}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"CodePreparation"} and $self->{"CodePreparation"}) 91 41 132
Condition66%2/3
defined $self->{"CodePreparation"} and $self->{"CodePreparation"}
!ll&&!rl&&r
04185
MC/DC50%1/2
defined $self->{"CodePreparation"} and $self->{"CodePreparation"}
defined $self->{"CodePreparation"} $self->{"CodePreparation"}
Truth table66%2/3
A and B
A= defined $self->{"CodePreparation"}B= $self->{"CodePreparation"}
ABresult
0X0
100
111
439 92 local $_=$code;
440 92 $self->eval1($self->{CodePreparation},'preprocessing');
441 92 $code = $_; }
442  
443 # Evaluate code, first final preparation and then eval1
444 133 local $::Star = $self;
445 127 local $::O = '';
446 133 $self->eval1($code, 'snippet');
447
448 128 ▶ if ($self->{REPLACE}) { return $::O }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"REPLACE"}) 59 72 131
449 82 ▶ if ($::O ne '') { $suf.= $self->_output_wrap($::O); }
Branch: 1 branch
BranchTrueFalseTotal
if ($main::O ne "") 31 37 68
450 82 return "$pref$c$suf"; }
451  
452 # Wrap output with output delimiters
453 41 ▶sub _output_wrap {
Subroutine _output_wrap: called CC=5 SCAR=16.1
454 50 my $self = shift; my $out = shift; my @d = ("#","+\n","#","-");
455 50 ▶ @d = @{ $self->{OutDelimiters} } if defined( $self->{OutDelimiters} );
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"OutDelimiters"} 34 0 34
456 37 my ($b,$e) = ($d[0].$d[1], $d[2].$d[3]); my $i;
457 37 ▶ if (index($out, $e) != -1) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($out, $e) != -1) 6 28 34
458 9 ▶ while(1) { $i++; $e=$d[2].$i.$d[3]; last if index($out, $e)==-1;
Branch: 1 branch
BranchTrueFalseTotal
if index($out, $e) == -1 6 6 12
459 7 ▶ _croak("Problem finding ending delimiter!\n(O=$out)") if $i > 1000000;}
Branch: 1 branch
BranchTrueFalseTotal
if $i > 1000000 0 6 6
460 9 $b = $d[0].$i.$d[1]; }
461 37 return $b.$out.$e; }
462  
463 # Python-specific evaluator (used also for makefile style)
464 # used with hook type ht:re2
465 11 ▶sub evaluate_py1 { #!!!py
Subroutine evaluate_py1: called CC=8 SCAR=21.3
Pod undocumented
466 9 my $self = shift;
467 9 my $allmatch = shift; #!!!py maybe to remove it!?
468 9 my $indent = shift;
469 9 my $prefix = shift;
470 9 my $code = shift; my $c = $code;
471 9 my $oldout = shift; #!?to remove it
472  
473 9 ▶ if (defined($self->{CodePreparation}) && $self->{CodePreparation}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"CodePreparation"} and $self->{"CodePreparation"}) 8 0 8
Condition33%1/3
defined $self->{"CodePreparation"} and $self->{"CodePreparation"}
!ll&&!rl&&r
008
MC/DC0%0/2
defined $self->{"CodePreparation"} and $self->{"CodePreparation"}
defined $self->{"CodePreparation"} $self->{"CodePreparation"}
Truth table33%1/3
A and B
A= defined $self->{"CodePreparation"}B= $self->{"CodePreparation"}
ABresult
0X0
100
111
474 9 local $_=$code;
475 9 $self->eval1($self->{CodePreparation},'preprocessing');
476 9 $code = $_;
477 }
478  
479 # Evaluate code, first final preparation and then eval1
480 9 local $::O = '';
481 9 local $::Star = $self;
482 9 $self->eval1($code, 'snippet');
483  
484 9 ▶ if ($self->{REPLACE}) { return $indent.$::O }
Branch: 2 branches
BranchTrueFalseTotal
if ($self->{'REPLACE'}) { } 0 8 8
elsif ($main::O eq '') { } 1 7 8
485 2 elsif ($::O eq '') { return "$indent#$prefix$c!>" }
486 else {
487 8 $::O =~ s/^/$indent/gmx;
488 8 my $r;
489 8 my ($b,$e); my @d = @{ $self->{OutDelimiters} };
490 8 $b = $d[0].$d[1]; my $i; $e = $d[2].$d[3];
491 8 ▶ if (index($::O, $e) != -1) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($main::O, $e) != -1) 0 7 7
492 1 ▶ while(1) { $i++; $e=$d[2].$i.$d[3]; last if index($::O, $e)==-1;
Branch: 1 branch
BranchTrueFalseTotal
if index($main::O, $e) == -1 0 0 0
493 1 ▶ _croak("Problem finding ending delimiter!\n(O=$::O)")
Branch: 1 branch
BranchTrueFalseTotal
if $i > 1000000 0 0 0
494 if $i > 1000000; }
495 1 $b = $d[0].$i.$d[1];
496 }
497 8 $r= "$indent#$prefix$c!>$b".$::O;
498 8 $r =~ s/\n?$/\n/; $r.="$indent$e"; # no extra \n
499 }
500 }
501  
502 # predefined evaluator: echo
503 17 ▶sub eval_echo {
Subroutine eval_echo: called CC=3 SCAR=11.1
Pod undocumented
504 2 my $self = shift;
505 2 my $pref = shift;
506 2 my $cont = shift;
507 2 my $suff = shift;
508 2 $::O = $cont;
509  
510 # to update OutDelimiters
511 2 ▶ return $::O if $self->{REPLACE};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"REPLACE"} 0 1 1
512 2 ▶ return $pref.$cont.$suff if $::O eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $main::O eq "" 0 1 1
513 2 $suff.=$self->_output_wrap($::O);
514 2 return $pref.$cont.$suff;
515 }
516  
517 # predefined evaluator: ignore
518 18 ▶sub eval_ignore {
Subroutine eval_ignore: called CC=2 SCAR=6.9
Pod undocumented
519 3 my $self = shift;
520 3 ▶ return '' if $self->{REPLACE};
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"REPLACE"} 1 1 2
521  
522 2 my $pref = shift;
523 2 my $code = shift;
524 2 my $suf = shift;
525 2 return $pref.$code.$suf;
526 }
527  
528 # predefined ignore evaluator for regex hooks
529 166 ▶sub repl_comment {
Subroutine repl_comment: called CC=2 SCAR=7.0
Pod undocumented
530 164 my $self = shift;
531 164 ▶ if ($self->{REPLACE}) { return '' }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"REPLACE"}) 163 0 163
532 1 return $self->{currenttoken};
533 }
534  
535 2 ▶sub define {
Subroutine define: called CC=5 SCAR=16.6
Pod undocumented
536 2 my $self = shift;
537  
538 2 my $pref = shift;
539 2 my $data = shift;
540 2 my $suf = shift;
541  
542 2 ▶ if ($self->{CurrentLoop} > 1) { return "$pref$data$suf"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"CurrentLoop"} > 1) 0 1 1
543  
544 2 ▶ $data =~ /^.+/ or _croak("expected macro spec");
Branch: 1 branch
BranchTrueFalseTotal
$data =~ /^.+/ or _croak("expected macro spec") 1 0 1
545 2 ▶ _croak("no macro spec") unless $&;
Branch: 1 branch
BranchTrueFalseTotal
unless $& 0 1 1
546 2 ▶ _croak("double macro def (forbidden):$&") if ($self->{ForbidMacro}->{$&});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"ForbidMacro"}{$&} 0 1 1
547 2 $self->{Macros}->{$&} = $data;
548 2 return '';
549 }
550  
551 3 ▶sub MCdefine {
Subroutine MCdefine: called CC=5 SCAR=16.6
Pod undocumented
552 3 my $self = shift;
553 3 my $pref = shift;
554 3 my $data = shift;
555 3 my $suf = shift;
556  
557 3 ▶ if ($self->{CurrentLoop} > 1) { die "define in loop > 1 !?" }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"CurrentLoop"} > 1) 0 2 2
558  
559 3 ▶ $data =~ /^.+/ or die "expected macro spec";
Branch: 1 branch
BranchTrueFalseTotal
$data =~ /^.+/ or die "expected macro spec" 2 0 2
560 3 ▶ die "no macro spec" unless $&;
Branch: 1 branch
BranchTrueFalseTotal
unless $& 0 2 2
561 3 ▶ die "double macro def (forbidden):$&" if ($self->{ForbidMacro}->{$&});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"ForbidMacro"}{$&} 0 2 2
562 3 $self->{Macros}->{$&} = $data;
563 3 return '';
564 }
565  
566 3 ▶sub MCdefe {
Subroutine MCdefe: called CC=6 SCAR=18.6
Pod undocumented
567 3 my $self = shift;
568 3 ▶ die "(".ref($self).")" unless ref($self) eq 'Text::Starfish';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self eq "Text::Starfish" 0 2 2
569  
570 3 my $pref = shift;
571 3 my $data = shift;
572 3 my $suf = shift;
573  
574 3 ▶ if ($self->{CurrentLoop} > 1) { die "defe in a loop >1!?" }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"CurrentLoop"} > 1) 0 2 2
575  
576 3 ▶ $data =~ /^.+/ or die "expected macro spec";
Branch: 1 branch
BranchTrueFalseTotal
$data =~ /^.+/ or die "expected macro spec" 2 0 2
577 3 ▶ die "no macro spec" unless $&;
Branch: 1 branch
BranchTrueFalseTotal
unless $& 0 2 2
578 3 ▶ die "def macro forbidden:$&\n" if (defined $self->{ForbidMacro}->{$&});
Branch: 1 branch
BranchTrueFalseTotal
if defined $self->{"ForbidMacro"}{$&} 0 2 2
579 3 $self->{Macros}->{$&} = $data;
580 3 return $self->{MacroKey}->{'expand'}.$&.$self->{MacroKey}->{'/expand'};
581 }
582  
583 4 ▶sub MCnewdefe {
Subroutine MCnewdefe: called CC=7 SCAR=20.6
Pod undocumented
584 4 ▶ my $self = shift; die "(".ref($self).")" unless ref($self) eq 'Text::Starfish';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self eq "Text::Starfish" 0 3 3
585  
586 4 my $pref = shift;
587 4 my $data = shift;
588 4 my $suf = shift;
589  
590 4 ▶ if ($self->{CurrentLoop} > 1) { die "newdefe in second loop!?" }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"CurrentLoop"} > 1) 0 3 3
591  
592 4 ▶ $data =~ /^.+/ or die "expected macro spec";
Branch: 1 branch
BranchTrueFalseTotal
$data =~ /^.+/ or die "expected macro spec" 3 0 3
593 4 ▶ die "no macro spec" unless $&;
Branch: 1 branch
BranchTrueFalseTotal
unless $& 0 3 3
594 4 ▶ if (defined $self->{Macros}->{$&} || $self->{ForbidMacro}->{$&}) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"Macros"}{$&} or $self->{"ForbidMacro"}{$&}) 0 3 3
Condition33%1/3
defined $self->{"Macros"}{$&} or $self->{"ForbidMacro"}{$&}
l!l&&r!l&&!r
003
MC/DC0%0/2
defined $self->{"Macros"}{$&} or $self->{"ForbidMacro"}{$&}
defined $self->{"Macros"}{$&} $self->{"ForbidMacro"}{$&}
Truth table33%1/3
A or B
A= defined $self->{"Macros"}{$&}B= $self->{"ForbidMacro"}{$&}
ABresult
1X1
011
000
595 1 die "double def:$&" }
596 4 $self->{Macros}->{$&} = $data;
597 4 $self->{ForbidMacro}->{$&} = 1;
598 4 return $self->{MprefExpand}.$&.$self->{MsufExpand};
599 }
600  
601 9 ▶sub expand {
Subroutine expand: called CC=6 SCAR=18.3
Pod undocumented
602 9 my $self = shift;
603 9 ▶ die "(".ref($self).")" unless ref($self) eq 'Text::Starfish';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self eq "Text::Starfish" 0 8 8
604  
605 9 my $pref = shift;
606 9 my $data = shift;
607 9 my $suf = shift;
608  
609 9 ▶ if ($self->{CurrentLoop} < 2 || $self->{HideMacros})
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"CurrentLoop"} < 2 or $self->{"HideMacros"}) 4 4 8
Condition66%2/3
$self->{"CurrentLoop"} < 2 or $self->{"HideMacros"}
l!l&&r!l&&!r
404
MC/DC50%1/2
$self->{"CurrentLoop"} < 2 or $self->{"HideMacros"}
$self->{"CurrentLoop"} < 2 $self->{"HideMacros"}
Truth table66%2/3
A or B
A= $self->{"CurrentLoop"} < 2B= $self->{"HideMacros"}
ABresult
1X1
011
000
610 5 { return $self->{MacroKey}->{'expand'}.$data.$self->{MacroKey}->{'/expand'} }
611
612 5 ▶ $data =~ /^.+/ or die "expected macro spec";
Branch: 1 branch
BranchTrueFalseTotal
$data =~ /^.+/ or die "expected macro spec" 4 0 4
613 5 ▶ die "no macro spec" unless $&;
Branch: 1 branch
BranchTrueFalseTotal
unless $& 0 4 4
614 return $self->{MacroKey}->{'expanded'}.$self->{Macros}->{$&}.
615 5 $self->{MacroKey}->{'/expanded'};
616 }
617  
618 15 ▶sub MCexpand {
Subroutine MCexpand: called CC=7 SCAR=20.1
Pod undocumented
619 15 my $self = shift;
620 15 ▶ die "(".ref($self).")" unless ref($self) eq 'Text::Starfish';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self eq "Text::Starfish" 0 14 14
621  
622 15 my $pref = shift;
623 15 my $data = shift;
624 15 my $suf = shift;
625  
626 15 ▶ if ($self->{CurrentLoop} < 2 || $self->{HideMacros}) {
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"CurrentLoop"} < 2 or $self->{"HideMacros"}) 2 12 14
Condition66%2/3
$self->{"CurrentLoop"} < 2 or $self->{"HideMacros"}
l!l&&r!l&&!r
2012
MC/DC50%1/2
$self->{"CurrentLoop"} < 2 or $self->{"HideMacros"}
$self->{"CurrentLoop"} < 2 $self->{"HideMacros"}
Truth table66%2/3
A or B
A= $self->{"CurrentLoop"} < 2B= $self->{"HideMacros"}
ABresult
1X1
011
000
627 3 return "$pref$data$suf"; }
628
629 13 ▶ $data =~ /^.+/ or die "expected macro spec";
Branch: 1 branch
BranchTrueFalseTotal
$data =~ /^.+/ or die "expected macro spec" 12 0 12
630 13 ▶ die "no macro spec" unless $&;
Branch: 1 branch
BranchTrueFalseTotal
unless $& 0 12 12
631 13 ▶ die "macro not defined" unless defined $self->{Macros}->{$&};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"Macros"}{$&} 0 12 12
632 13 return $self->{MprefExpanded}.$self->{Macros}->{$&}.$self->{MsufExpanded};
633 }
634  
635 1 ▶sub fexpand {
Subroutine fexpand: called CC=6 SCAR=22.9
Pod undocumented
636 1 my $self = shift;
637 1 ▶ die "(".ref($self).")" unless ref($self) eq 'Text::Starfish';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self eq "Text::Starfish" 0 0 0
638  
639 1 my $pref = shift;
640 1 my $data = shift;
641 1 my $suf = shift;
642  
643 1 ▶ if ($self->{CurrentLoop} < 2) { return "$pref$data$suf"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"CurrentLoop"} < 2) 0 0 0
644
645 1 ▶ $data =~ /^.+/ or die "expected macro spec";
Branch: 1 branch
BranchTrueFalseTotal
$data =~ /^.+/ or die "expected macro spec" 0 0 0
646 1 ▶ die "no macro spec" unless $&;
Branch: 1 branch
BranchTrueFalseTotal
unless $& 0 0 0
647 1 ▶ die "macro not defined:$&" unless defined $self->{Macros}->{$&};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"Macros"}{$&} 0 0 0
648 1 return $self->{MpreffExpanded} . $self->{Macros}->{$&}.$self->{MsuffExpanded};
649 }
650  
651 1 ▶sub MCfexpand {
Subroutine MCfexpand: called CC=6 SCAR=22.9
Pod undocumented
652 1 my $self = shift;
653 1 ▶ die "(".ref($self).")" unless ref($self) eq 'Text::Starfish';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self eq "Text::Starfish" 0 0 0
654  
655 1 my $pref = shift;
656 1 my $data = shift;
657 1 my $suf = shift;
658  
659 1 ▶ if ($self->{CurrentLoop} < 2) { return "$pref$data$suf"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"CurrentLoop"} < 2) 0 0 0
660
661 1 ▶ $data =~ /^.+/ or die "expected macro spec";
Branch: 1 branch
BranchTrueFalseTotal
$data =~ /^.+/ or die "expected macro spec" 0 0 0
662 1 ▶ die "no macro spec" unless $&;
Branch: 1 branch
BranchTrueFalseTotal
unless $& 0 0 0
663 1 ▶ die "macro not defined:$&" unless defined $self->{Macros}->{$&};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"Macros"}{$&} 0 0 0
664 return $self->{MacroKey}->{'fexpanded'}.$self->{Macros}->{$&}.
665 1 $self->{MacroKey}->{'/fexpanded'};
666 }
667  
668 4 ▶sub expanded {
Subroutine expanded: called CC=4 SCAR=14.2
Pod undocumented
669 4 my $self = shift;
670 4 ▶ die "(".ref($self).")" unless ref($self) eq 'Text::Starfish';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self eq "Text::Starfish" 0 3 3
671  
672 4 my $pref = shift;
673 4 my $data = shift;
674 4 my $suf = shift;
675
676 4 ▶ $data =~ /^.+/ or die "expected macro name";
Branch: 1 branch
BranchTrueFalseTotal
$data =~ /^.+/ or die "expected macro name" 3 0 3
677 4 ▶ die "no macro spec" unless $&;
Branch: 1 branch
BranchTrueFalseTotal
unless $& 0 3 3
678 4 return $self->{MprefExpand}.$&.$self->{MsufExpand};
679 }
680  
681 5 ▶sub MCexpanded {
Subroutine MCexpanded: called CC=4 SCAR=14.2
Pod undocumented
682 5 my $self = shift;
683 5 ▶ die "(".ref($self).")" unless ref($self) eq 'Text::Starfish';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self eq "Text::Starfish" 0 4 4
684  
685 5 my $pref = shift;
686 5 my $data = shift;
687 5 my $suf = shift;
688
689 5 ▶ $data =~ /^.+/ or die "expected macro name";
Branch: 1 branch
BranchTrueFalseTotal
$data =~ /^.+/ or die "expected macro name" 4 0 4
690 5 ▶ die "no macro spec" unless $&;
Branch: 1 branch
BranchTrueFalseTotal
unless $& 0 4 4
691 5 return $self->{MacroKey}->{'expand'}.$&.$self->{MacroKey}->{'/expand'};
692 }
693  
694 1 ▶sub fexpanded {
Subroutine fexpanded: called CC=4 SCAR=16.6
Pod undocumented
695 1 my $self = shift;
696 1 ▶ die "(".ref($self).")" unless ref($self) eq 'Text::Starfish';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self eq "Text::Starfish" 0 0 0
697  
698 1 my $pref = shift;
699 1 my $data = shift;
700 1 my $suf = shift;
701
702 1 ▶ $data =~ /^.+/ or die "expected macro name";
Branch: 1 branch
BranchTrueFalseTotal
$data =~ /^.+/ or die "expected macro name" 0 0 0
703 1 ▶ die "no macro spec" unless $&;
Branch: 1 branch
BranchTrueFalseTotal
unless $& 0 0 0
704 1 return $self->{MpreffExpand}.$&.$self->{MsuffExpand};
705 }
706  
707 1 ▶sub MCfexpanded {
Subroutine MCfexpanded: called CC=6 SCAR=22.9
Pod undocumented
708 1 my $self = shift;
709 1 ▶ die "(".ref($self).")" unless ref($self) eq 'Text::Starfish';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self eq "Text::Starfish" 0 0 0
710  
711 1 my $pref = shift;
712 1 my $data = shift;
713 1 my $suf = shift;
714
715 1 ▶ if ($self->{CurrentLoop} < 2) { return "$pref$data$suf"; }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"CurrentLoop"} < 2) 0 0 0
716 1 ▶ $data =~ /^.+/ or die "expected macro name";
Branch: 1 branch
BranchTrueFalseTotal
$data =~ /^.+/ or die "expected macro name" 0 0 0
717 1 ▶ die "no macro spec" unless $&;
Branch: 1 branch
BranchTrueFalseTotal
unless $& 0 0 0
718 1 ▶ die "Macro not defined:$&" unless defined $self->{Macros}->{$&};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"Macros"}{$&} 0 0 0
719 return $self->{MacroKey}->{'fexpanded'}.$self->{Macros}->{$&}.
720 1 $self->{MacroKey}->{'/fexpanded'};
721 }
722  
723 1 ▶sub MCauxdefine {
Subroutine MCauxdefine: called CC=6 SCAR=21.9
Pod undocumented
724 1 my $self = shift;
725 1 ▶ die "(".ref($self).")" unless ref($self) eq 'Text::Starfish';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self eq "Text::Starfish" 0 0 0
726  
727 1 my $pref = shift;
728 1 my $data = shift;
729 1 my $suf = shift;
730
731 1 ▶ $data =~ /^.+/ or die "expected macro name";
Branch: 1 branch
BranchTrueFalseTotal
$data =~ /^.+/ or die "expected macro name" 0 0 0
732 1 ▶ die "no macro spec" unless $&;
Branch: 1 branch
BranchTrueFalseTotal
unless $& 0 0 0
733 1 my $mn = $&;
734 1 $data = unwrap($data);
735 1 ▶ die "double macro def (forbidden):$mn\n" if ($self->{ForbidMacro}->{$mn});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"ForbidMacro"}{$mn} 0 0 0
736 1 ▶ if (! defined($self->{Macros}->{$mn}) ) { $self->{Macros}->{$mn}=$data }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"Macros"}{$mn}) 0 0 0
737 1 return '';
738 }
739  
740 5 ▶sub auxDefine {
Subroutine auxDefine: called CC=6 SCAR=18.2
Pod undocumented
741 5 my $self = shift;
742 5 ▶ die "(".ref($self).")" unless ref($self) eq 'Text::Starfish';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $self eq "Text::Starfish" 0 4 4
743  
744 5 my $pref = shift;
745 5 my $data = shift;
746 5 my $suf = shift;
747
748 5 ▶ $data =~ /^.+/ or die "expected macro name";
Branch: 1 branch
BranchTrueFalseTotal
$data =~ /^.+/ or die "expected macro name" 4 0 4
749 5 ▶ die "no macro spec" unless $&; my $mn = $&;
Branch: 1 branch
BranchTrueFalseTotal
unless $& 0 4 4
750 5 $data = unwrap($data);
751 5 ▶ die "double macro def (forbidden):$mn\n" if ($self->{ForbidMacro}->{$mn});
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"ForbidMacro"}{$mn} 1 3 4
752 4 ▶ if (! defined($self->{Macros}->{$mn}) ) { $self->{Macros}->{$mn}=$data }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"Macros"}{$mn}) 3 0 3
753 4 return '';
754 }
755  
756 11 ▶sub wrap {
Subroutine wrap: called CC=1 SCAR=0.0
Pod undocumented
757 11 my $d = shift;
758 11 $d =~ s/^/\/\/ /mg;
759 11 return $d;
760 }
761  
762 5 ▶sub unwrap {
Subroutine unwrap: called CC=1 SCAR=0.0
Pod undocumented
763 5 my $d = shift;
764 5 $d =~ s/^\/\/ //mg;
765 5 return $d;
766 }
767  
768 1 ▶sub setGlobStyle {
Subroutine setGlobStyle: called CC=1 SCAR=0.0
Pod undocumented
769 1 my $self = shift;
770 1 my $s = shift;
771 1 $self->{STYLE} = $s;
772 1 $self->set_style($s);
773 }
774  
775 78 ▶sub clearStyle {
Subroutine clearStyle: called CC=2 SCAR=6.9
Pod undocumented
776 78 my $self = shift;
777 78 foreach my $k (qw(Style CodePreparation LineComment OutDelimiters
778 IgnoreOuter)) {
779 386 delete $self->{$k} }
780 78 $self->{hook} = [];
781 }
782  
783 4 ▶sub setStyle { return &set_style }
Subroutine setStyle: called CC=1 SCAR=0.0
Pod documented
784  
785 # List of fields typically set in set_style:
786 # $self->{Style} = string, style
787 # $self->{CodePreparation} = scalar
788 # $self->{LineComment} = string, line comment
789 # $self->{OutDelimiters} = [] eg: "//" "+\n" "//" "-\n"
790 # $self->{IgnoreOuter} = 1 or ''
791 # $self->{hook} = [], list of hooks
792 186 ▶sub set_style {
Subroutine set_style: called CC=24 SCAR=31.9
Pod documented
793 186 my $self = shift;
794 186 ▶ if (ref($self) ne 'Text::Starfish') { unshift @_, $self; $self = $::Star; }
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self ne "Text::Starfish") 0 185 185
795  
796 186 ▶ if ($#_ == -1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ == -1) 91 94 185
797 92 ▶ if (defined $self->{STYLE} && $self->{STYLE} ne '')
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{'STYLE'} and $self->{'STYLE'} ne '') { } 0 91 91
Condition33%1/3
defined $self->{"STYLE"} and $self->{"STYLE"} ne ""
!ll&&!rl&&r
9100
MC/DC0%0/2
defined $self->{"STYLE"} and $self->{"STYLE"} ne ""
defined $self->{"STYLE"} $self->{"STYLE"} ne ""
Truth table33%1/3
A and B
A= defined $self->{"STYLE"}B= $self->{"STYLE"} ne ""
ABresult
0X0
100
111
798 1 { $self->set_style($self->{STYLE}) }
799 else {
800 92 my $f = $self->{INFILE};
801  
802 92 ▶ if ($f =~ /\.(html\.sfish|sf)$/i) { $self->set_style('html.sfish') }
Branch: 1 branch
BranchTrueFalseTotal
if ($f =~ /\.(html\.sfish|sf)$/i) { } 1 90 91
803 else {
804 91 $f =~ s/\.s(tar)?fish$//;
805 91 ▶ if ($f =~ /\.html?/i) { $self->set_style('html') }
Branch: 6 branches
BranchTrueFalseTotal
if ($f =~ /\.html?/i) { } 7 83 90
elsif ($f =~ /\.(?:la)?tex$/i) { } 5 78 83
elsif ($f =~ /\.java$/i) { } 13 65 78
elsif ($f =~ /^[Mm]akefile/) { } 3 62 65
elsif ($f =~ /\.ps$/i) { } 0 62 62
elsif ($f =~ /\.py$/i) { } 1 61 62
806 6 elsif ($f =~ /\.(?:la)?tex$/i) { $self->set_style('tex') }
807 14 elsif ($f =~ /\.java$/i) { $self->set_style('java') }
808 4 elsif ($f =~ /^[Mm]akefile/) { $self->set_style('makefile') }
809 1 elsif ($f =~ /\.ps$/i) { $self->set_style('ps') }
810 2 elsif ($f =~ /\.py$/i) { $self->set_style('python') }
811 62 else { $self->set_style('perl') }
812 }
813 }
814 92 return;
815 }
816  
817 95 my $s = shift;
818 95 ▶ if ($s eq 'latex' or $s eq 'TeX') { $s = 'tex' }
Branch: 1 branch
BranchTrueFalseTotal
if ($s eq "latex" or $s eq "TeX") 3 91 94
Condition66%2/3
$s eq "latex" or $s eq "TeX"
l!l&&r!l&&!r
0391
MC/DC50%1/2
$s eq "latex" or $s eq "TeX"
$s eq "latex" $s eq "TeX"
Truth table66%2/3
A or B
A= $s eq "latex"B= $s eq "TeX"
ABresult
1X1
011
000
819 95 ▶ if (defined $self->{Style} and $s eq $self->{Style}) { return }
Branch: 1 branch
BranchTrueFalseTotal
if (defined $self->{"Style"} and $s eq $self->{"Style"}) 17 77 94
Condition100%3/3
defined $self->{"Style"} and $s eq $self->{"Style"}
!ll&&!rl&&r
463117
MC/DC100%2/2
defined $self->{"Style"} and $s eq $self->{"Style"}
defined $self->{"Style"} $s eq $self->{"Style"}
Truth table100%3/3
A and B
A= defined $self->{"Style"}B= $s eq $self->{"Style"}
ABresult
0X0
100
111
820
821 # default
822 78 $self->clearStyle();
823 78 $self->{'LineComment'} = '#';
824 78 $self->{'IgnoreOuter'} = '';
825 78 $self->{OutDelimiters} = [ "#", "+\n", "#", "-" ];
826 78 $self->{CodePreparation} = 's/\\n(?:#|%|\/\/+)/\\n/g';
827 78 $self->{hook} = [];
828 78 $self->add_hook('be','#<?','!>');
829 78 $self->add_hook('be','<?' ,'!>');
830 78 $self->add_hook('be','<?starfish','?>');
831  
832 #!!!py
833 # Used for Python and Makefile with &evaluate_py1
834 # matched with hook type ht:re2
835 78 my $re_py1 = qr/([\ \t]*)\#(\ *<\?)([\000-\377]*?)!>/x;
836 # extension below was a bug for <?...!>...<?...!>#+...#-
837 # ([\ \t]*\#+\n[\000-\377]*?\n[\ \t]*\#-\n)?/x;
838  
839 78 ▶ if ($s eq 'perl') { }
Branch: 8 branches
BranchTrueFalseTotal
if ($s eq 'perl') { } 45 32 77
elsif ($s eq 'makefile') { } 3 29 32
elsif ($s eq 'python') { } 1 28 29
elsif ($s eq 'java') { } 13 15 28
elsif ($s eq 'tex') { } 7 8 15
elsif ($s eq 'html.sfish') { } 1 7 8
elsif ($s eq 'html') { } 7 0 7
elsif ($s eq 'ps') { } 0 0 0
840 elsif ($s eq 'makefile') {
841 4 $self->{CodePreparation} = 's/\\n\\s*#/\\n/g';
842 4 $self->{hook} = [ ];
843 4 $self->add_hook('ht:re2', $re_py1, \&evaluate_py1); #!!!
844 }
845 elsif ($s eq 'python') {
846 2 $self->{hook} = [ ];
847 2 $self->{CodePreparation} = 's/\\n\\s*#/\\n/g';
848 2 $self->add_hook('ht:re2', $re_py1, \&evaluate_py1); #!!!
849 }
850 elsif ($s eq 'java') {
851 14 $self->{LineComment} = '//';
852 14 $self->{OutDelimiters} = [ "//", "+\n", "//", "-" ];
853 14 $self->{hook} = [{begin => '//<?', end => '!>', f => \&_evaluate },
854 {begin => '<?', end => '!>', f => \&_evaluate }];
855 14 $self->{CodePreparation} = 's/^\s*\/\/+//mg';
856 }
857 elsif ($s eq 'tex') {
858 8 $self->{LineComment} = '%';
859 # change OutDelimiters ?
860 # $self->{OutDelimiters} = [ "%", "+\n", "%", "-\n" ];
861 8 $self->{OutDelimiters} = [ "%", "+\n", "\n%", "-\n" ];
862 8 $self->{hook}=[{ht=>'be', begin=>'%<?', end=>"!>\n", f=>\&_evaluate },
863 # change to this one?
864 #{ht=>'be', begin=>'%<?', end=>"!>", f=>\&_evaluate },
865 {ht=>'be', begin=>'<?', end=>"!>\n", f=>\&_evaluate },
866 {ht=>'be', begin=>'<?', end=>"!>", f=>\&_evaluate }];
867  
868 8 $self->{CodePreparation} = 's/^[ \t]*%//mg';
869 }
870 elsif ($s eq 'html.sfish') {
871 2 undef $self->{LineComment};
872 2 $self->{OutDelimiters} = [ "<!-- +", " -->", "<!-- -", " -->" ];
873 2 $self->{CodePreparation} = '';
874 2 $self->{hook}=[];
875 2 $self->add_hook('be', '<!--<?', '!>-->');
876 2 $self->add_hook('be', qr/<\?starfish\b/, '?>');
877 2 $self->add_hook('be', qr/<\?sf\b/, '!>');
878 2 $self->add_hook('regex', qr/^#.*\n/m, 'comment');
879 }
880 elsif ($s eq 'html') {
881 8 undef $self->{LineComment}; # Changes
882 8 $self->{OutDelimiters} = [ "<!-- +", " -->", "<!-- -", " -->" ];
883 $self->{hook}=[
884 8 {ht=>'be', begin => '<!--<?', end => '!>-->', f => \&_evaluate },
885 {ht=>'be', begin=>'<?starfish ', end=>'?>', f=>\&_evaluate } ];
886 8 $self->{CodePreparation} = '';
887 }
888 elsif ($s eq 'ps') {
889 1 $self->{LineComment} = '%';
890 1 $self->{OutDelimiters} = [ "% ", "+\n", "% ", "-" ];
891 $self->{hook}=[
892 1 {ht=>'be', begin => '<?', end => '!>', f => \&_evaluate }];
893 1 $self->{CodePreparation} = 's/\\n%/\\n/g';
894 }
895 1 else { _croak("set_style:unknown style:$s") }
896 78 $self->{Style} = $s;
897 }
898  
899 # to be deprecated? Used only to make it available in name space
900 7 ▶sub sfish_add_tag($$) { $::Star->add_tag(@_) }
Subroutine sfish_add_tag: called CC=1 SCAR=0.0
Pod documented
901 3 ▶sub sfish_ignore_outer { $::Star->ignore_outer(@_) }
Subroutine sfish_ignore_outer: called CC=1 SCAR=0.0
Pod documented
902  
903 # adds tags such as %slide:.* and %<slide> by adding appropriate hooks
904 # eg: add_tag('slide', 'ignore')
905 # eg: add_tag('sl,l', 'echo')
906 7 ▶sub add_tag {
Subroutine add_tag: called CC=6 SCAR=18.1
Pod documented
907 7 my $self = shift;
908 7 ▶ if (ref($self) ne 'Text::Starfish')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self ne "Text::Starfish") 0 6 6
909 1 { unshift @_, $self; $self = $::Star; }
910 7 my $tag = shift; my $fun = shift;
911 7 my $lc = $self->{LineComment};
912 #die "tag=($tag) fun=($fun) ref(fun)=".ref($fun);
913 7 ▶ if (ref($fun) eq '') {
Branch: 1 branch
BranchTrueFalseTotal
if (ref $fun eq "") 6 0 6
914 7 ▶ if ( $fun eq 'ignore') { $fun = sub{''} }
Subroutine __ANON__: called CC=1 SCAR=0.0
Branch: 2 branches
BranchTrueFalseTotal
if ($fun eq 'ignore') { } 1 5 6
elsif ($fun eq 'echo') { } 5 0 5
915 6 ▶ elsif ( $fun eq 'echo') { $fun = sub{$_[2]} }
Subroutine __ANON__: called CC=1 SCAR=0.0
916 }
917 7 ▶ my $lc1 = ($lc eq '') ? $lc : "$lc?"; #!!!
Branch: 1 branch
BranchTrueFalseTotal
$lc eq '' ? : 0 6 6
918 7 $self->add_hook('regex', qr/$lc1<$tag>\n?((?:.|\n)*?)$lc1<\/$tag>\n?/, $fun);
919 7 $self->add_hook('regex', qr/$lc$tag:(.*\n)/, $fun);
920 }
921  
922 3 ▶sub ignore_outer {
Subroutine ignore_outer: called CC=3 SCAR=11.2
Pod documented
923 3 my $self = shift;
924 3 ▶ if (ref($self) ne 'Text::Starfish')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self ne "Text::Starfish") 0 2 2
925 1 { unshift @_, $self; $self = $::Star; }
926 3 my $newignoreouter = 1;
927 3 ▶ $newignoreouter = $_[1] if $#_ > 0;
Branch: 1 branch
BranchTrueFalseTotal
if $#_ > 0 0 2 2
928 3 $self->{IgnoreOuter} = $newignoreouter;
929 }
930  
931 5 ▶sub set_out_delimiters {
Subroutine set_out_delimiters: called CC=3 SCAR=11.2
Pod undocumented
932 5 my $self = shift;
933 5 ▶ if (ref($self) ne 'Text::Starfish')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self ne "Text::Starfish") 4 0 4
934 5 { unshift @_, $self; $self = $::Star; }
935 5 ▶ _croak("OutDelimiters must be array of 4 elements:(@_)") if scalar(@_)!=4;
Branch: 1 branch
BranchTrueFalseTotal
if scalar @_ != 4 0 4 4
936 5 $self->{OutDelimiters} = [ $_[0], $_[1], $_[2], $_[3] ]; }
937  
938 # eg: add_hook('string','somestring','replacement')
939 # add_hook('be', '<?new', '!'.'>');
940 286 ▶sub add_hook { #!!! adding hooks
Subroutine add_hook: called CC=16 SCAR=27.8
Pod documented
941 286 my $self = shift;
942 286 ▶ if (ref($self) ne 'Text::Starfish')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self ne "Text::Starfish") 14 271 285
943 15 { unshift @_, $self; $self = $::Star; }
944  
945 286 my $ht = shift;
946 286 my $hooks = $self->{hook}; my $hook = { ht=>$ht };
947 286 ▶ if ($ht eq 'string') {
Branch: 4 branches
BranchTrueFalseTotal
if ($ht eq 'string') { } 1 284 285
elsif ($ht eq 'be') { } 254 30 284
elsif ($ht eq 'regex') { } 26 4 30
elsif ($ht eq 'ht:re2') { } 4 0 4
948 2 my $s=shift; my $replace = shift;
949 2 $hook->{s} = $s; $hook->{evf_const} = $replace;
950 2 push @{$hooks}, $hook;
951 } elsif ($ht eq 'be') {
952 255 my $b = shift; my $e = shift; my $f='default';
953 255 ▶ if ($#_>-1) { $f = shift }
Branch: 1 branch
BranchTrueFalseTotal
if ($#_ > -1) 16 238 254
954 255 $hook->{begin} = $b; $hook->{end} = $e;
955 255 ▶ if ($f eq 'default') { $hook->{f} = \&_evaluate;
Branch: 4 branches
BranchTrueFalseTotal
if ($f eq 'default') { } 239 15 254
elsif ($f eq 'ignore') { } 2 13 15
elsif ($f eq 'echo') { } 1 12 13
elsif (ref $f eq 'CODE') { } 1 11 12
956 240 push @{$hooks}, $hook; return;
957 3 } elsif ($f eq 'ignore') { $hook->{f} = \&eval_ignore;
958 3 push @{$hooks}, $hook; return;
959 2 } elsif ($f eq 'echo') { $hook->{f} = \&eval_echo;
960 2 push @{$hooks}, $hook; return;
961 } elsif (ref($f) eq 'CODE') {
962 4 ▶ $hook->{f} = sub { local $_; my $self=shift;
Subroutine __ANON__: called CC=2 SCAR=6.9
963 4 my $p=shift; $_=shift; my $s=shift;
964 4 &$f($p,$_,$s);
965 4 ▶ if ($self->{REPLACE}) { return $_ }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"REPLACE"}) 3 0 3
966 1 return "$p$_$s";
967 2 };
968 2 push @{$hooks}, $hook; return;
969 } else {
970 12 $hook->{ht} = '';
971 12 eval("\$hook->{f} = sub {\n".
972 "local \$_;\n".
973 "my \$self = shift;\n".
974 "my \$p = shift; \$_ = shift; my \$s = shift;\n".
975 "$f;\n".
976 'if ($self->{REPLACE}) { return $_ }'."\n".
977 "return \"\$p\$_\$s\"; };");
978 12 ▶ _croak("add_hook error:$@") if $@;
Branch: 1 branch
BranchTrueFalseTotal
if $@ 0 11 11
979 12 push @{$hooks}, $hook; return;
980 }
981 } elsif ($ht eq 'regex') {
982 27 my $regex=shift; my $replace = shift;
983 27 $hook->{regex} = $regex;
984 27 ▶ if (ref($replace) eq '' && $replace eq 'comment')
Branch: 2 branches
BranchTrueFalseTotal
if (ref $replace eq '' and $replace eq 'comment') { } 3 23 26
elsif (ref $replace eq 'CODE') { } 23 0 23
Condition66%2/3
ref $replace eq "" and $replace eq "comment"
!ll&&!rl&&r
2303
MC/DC50%1/2
ref $replace eq "" and $replace eq "comment"
ref $replace eq "" $replace eq "comment"
Truth table66%2/3
A and B
A= ref $replace eq ""B= $replace eq "comment"
ABresult
0X0
100
111
985 4 { $hook->{replace} = \&repl_comment }
986 elsif (ref($replace) eq 'CODE')
987 24 { $hook->{replace} = $replace }
988 1 else { _croak("add_hook, undefined regex format input ".
989 "(TODO?): ref regex(".ref($regex).
990 "), ref replace(".ref($replace).")" ) }
991 27 push @{$hooks}, $hook;
992 } elsif ($ht eq 'ht:re2') {
993 5 my $regex=shift; my $replace=shift;
994 5 ▶ die unless ref($replace) eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $replace eq "CODE" 0 4 4
995 5 $hook->{regex} = $regex; $hook->{replace} = $replace;
996 5 push @{$hooks}, $hook;
997 1 } else { _croak("add_hook error, unknown hook type `$ht'") }
998 }
999  
1000 # addHook is deprecated. Use add_hook, which contains the hook type
1001 # as the second argument, after $self.
1002 18 ▶sub addHook {
Subroutine addHook: called CC=4 SCAR=14.1
Pod documented
1003 18 my $self = shift;
1004 18 ▶ if ($#_ == 2) {
Branch: 2 branches
BranchTrueFalseTotal
if ($#_ == 2) { } 12 5 17
elsif ($#_ == 1 and ref $_[0] eq 'Regexp') { } 5 0 5
1005 13 $self->add_hook('be', @_); return;
1006 ▶ } elsif ($#_ == 1 and ref($_[0]) eq 'Regexp') {
Condition33%1/3
$#_ == 1 and ref $_[0] eq "Regexp"
!ll&&!rl&&r
005
MC/DC0%0/2
$#_ == 1 and ref $_[0] eq "Regexp"
$#_ == 1 ref $_[0] eq "Regexp"
Truth table33%1/3
A and B
A= $#_ == 1B= ref $_[0] eq "Regexp"
ABresult
0X0
100
111
1007 6 my $regex=shift; my $replace = shift;
1008 6 $self->add_hook('regex', $regex, $replace); return;
1009 1 } else { _croak("addHook parameter error") }}
1010  
1011 6 ▶sub rm_hook {
Subroutine rm_hook: called CC=6 SCAR=17.9
Pod documented
1012 6 my $self = shift;
1013 6 ▶ if (ref($self) ne 'Text::Starfish')
Branch: 1 branch
BranchTrueFalseTotal
if (ref $self ne "Text::Starfish") 4 1 5
1014 5 { unshift @_, $self; $self = $::Star; }
1015  
1016 6 my $ht = shift; # hook type: be (begin-end)
1017 6 ▶ if ($ht eq 'be') {
Branch: 1 branch
BranchTrueFalseTotal
if ($ht eq 'be') { } 5 0 5
1018 6 my $b=shift; my $e=shift;
1019 6 my @Hooks = @{ $self->{hook} }; my @Hooks1;
1020 6 foreach my $h (@Hooks) {
1021 20 ▶ if ($h->{begin} eq $b and $h->{end} eq $e) {}
Branch: 1 branch
BranchTrueFalseTotal
if ($h->{'begin'} eq $b and $h->{'end'} eq $e) { } 5 14 19
Condition66%2/3
$h->{"begin"} eq $b and $h->{"end"} eq $e
!ll&&!rl&&r
1405
MC/DC50%1/2
$h->{"begin"} eq $b and $h->{"end"} eq $e
$h->{"begin"} eq $b $h->{"end"} eq $e
Truth table66%2/3
A and B
A= $h->{"begin"} eq $bB= $h->{"end"} eq $e
ABresult
0X0
100
111
1022 15 else { push @Hooks1, $h }
1023 }
1024 6 $self->{hook} = \@Hooks1;
1025 } else {
1026 1 _croak("rm_hook not implemented for type ht=($ht)") }
1027 }
1028  
1029 # rmHook to be deprecated. Needs to be replaced with rm_hook
1030 2 ▶sub rmHook {
Subroutine rmHook: called CC=1 SCAR=0.0
Pod documented
1031 2 my $self = shift; my $p = shift; my $s = shift;
1032 2 $self->rm_hook('be', $p, $s); return; }
1033  
1034 1 ▶sub rmAllHooks { my $self = shift; $self->{hook} = []; }
Subroutine rmAllHooks: called CC=1 SCAR=0.0
Pod documented
1035  
1036 1 ▶sub resetHooks { my $self = shift; $self->rmAllHooks(); $self->set_style(); }
Subroutine resetHooks: called CC=1 SCAR=0.0
Pod undocumented
1037  
1038 3 ▶sub add_final {
Subroutine add_final: called CC=3 SCAR=11.2
Pod documented
1039 3 my $self = shift;
1040 3 ▶ my $f = shift; die "$f not a function" unless ref($f) eq 'CODE';
Branch: 1 branch
BranchTrueFalseTotal
unless ref $f eq "CODE" 0 2 2
1041 3 ▶ if (!defined($self->{Final})) { $self->{Final} = [] }
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $self->{"Final"}) 2 0 2
1042 3 push @{ $self->{Final} }, $f;
1043 }
1044  
1045 14 ▶sub defineMacros {
Subroutine defineMacros: called CC=3 SCAR=11.0
Pod undocumented
1046 14 my $self = shift;
1047  
1048 14 ▶ return if $self->{CurrentLoop} > 1;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"CurrentLoop"} > 1 6 7 13
1049 8 ▶ $self->{Loops} = 2 if $self->{Loops} < 2;
Branch: 1 branch
BranchTrueFalseTotal
if $self->{"Loops"} < 2 7 0 7
1050 7 $self->{MprefDefine} = '//define ';
1051 7 $self->{MsufDefine} = "//enddefine\n";
1052 7 $self->{MprefExpand} = '//expand ';
1053 7 $self->{MsufExpand} = "\n";
1054 7 $self->{MacroKey}->{'expand'} = '//m!expand ';
1055 7 $self->{MacroKey}->{'/expand'} = "\n";
1056 7 $self->{MacroKey}->{'expanded'} = '//m!expanded ';
1057 7 $self->{MacroKey}->{'/expanded'} = "//m!end\n";
1058 7 $self->{MpreffExpand} = '//fexpand ';
1059 7 $self->{MsuffExpand} = "\n";
1060 7 $self->{MacroKey}->{'fexpand'} = '//m!fexpand ';
1061 7 $self->{MacroKey}->{'/fexpand'} = "\n";
1062 7 $self->{MprefExpanded} = '//expanded ';
1063 7 $self->{MsufExpanded} = "//endexpanded\n";
1064 7 $self->{MpreffExpanded} = '//fexpanded ';
1065 7 $self->{MsuffExpanded} = "//endexpanded\n";
1066 7 $self->{MacroKey}->{'fexpanded'} = '//m!fexpanded ';
1067 7 $self->{MacroKey}->{'/fexpanded'} = "//m!end\n";
1068 7 $self->{MprefAuxDefine}='//auxdefine ';
1069 7 $self->{MsufAuxDefine}="//endauxdefine\n";
1070 7 $self->{MacroKey}->{'auxdefine'}='//m!auxdefine ';
1071 7 $self->{MacroKey}->{'/auxdefine'}="//m!endauxdefine\n";
1072 7 $self->{MacroKey}->{'define'} = '//m!define ';
1073 7 $self->{MacroKey}->{'/define'} = "//m!end\n";
1074 7 $self->{MacroKey}->{'defe'} = '//m!defe ';
1075 7 $self->{MacroKey}->{'/defe'} = "//m!end\n";
1076 7 $self->{MacroKey}->{'newdefe'} = '//m!newdefe ';
1077 7 $self->{MacroKey}->{'/newdefe'} = "//m!end\n";
1078 7 push @{$self->{hook}}, #!!!
1079 {begin=>$self->{MprefDefine}, end=>$self->{MsufDefine}, f=>\&define},
1080 {begin=>$self->{MprefExpand}, end=>$self->{MsufExpand}, f=>\&expand},
1081 {begin=>$self->{MpreffExpand}, end=>$self->{MsuffExpand}, f=>\&fexpand},
1082 {begin=>$self->{MprefExpanded}, end=>$self->{MsufExpanded}, f=>\&expanded},
1083 {begin=>$self->{MpreffExpanded},
1084 end=>$self->{MsuffExpanded},f=>\&fexpanded},
1085 {begin=>$self->{MprefAuxDefine},
1086 end=>$self->{MsufAuxDefine},f=>\&auxDefine},
1087 {begin=>$self->{MacroKey}->{'auxdefine'},
1088 end=>$self->{MacroKey}->{'/auxdefine'},f=>\&MCauxdefine},
1089 {begin=>$self->{MacroKey}->{'define'},
1090 end=>$self->{MacroKey}->{'/define'}, f=>\&MCdefine},
1091 {begin=>$self->{MacroKey}->{'expand'},
1092 end=>$self->{MacroKey}->{'/expand'}, f=>\&MCexpand},
1093 {begin=>$self->{MacroKey}->{'fexpand'},
1094 end=>$self->{MacroKey}->{'/fexpand'}, f=>\&MCfexpand},
1095 {begin=>$self->{MacroKey}->{'expanded'},
1096 end=>$self->{MacroKey}->{'/expanded'},f=>\&MCexpanded},
1097 {begin=>$self->{MacroKey}->{'fexpanded'},
1098 end=>$self->{MacroKey}->{'/fexpanded'},f=>\&MCfexpanded},
1099 {begin=>$self->{MacroKey}->{'defe'},
1100 end=>$self->{MacroKey}->{'/defe'}, f=>\&MCdefe},
1101 {begin=>$self->{MacroKey}->{'newdefe'},
1102 7 end=>$self->{MacroKey}->{'/newdefe'}, f=>\&MCnewdefe};
1103 7 $self->{macrosdefined} = 1;
1104 }
1105  
1106 2 ▶sub getmakefilelist ($$) {
Subroutine getmakefilelist: called CC=2 SCAR=6.9
Pod documented
1107 1 my $f = getfile($_[0]); shift;
1108 1 my $l = shift;
1109 1 ▶ $f =~ /\b$l=(.*(?:(?<=\\)\n.*)*)/ or
Branch: 1 branch
BranchTrueFalseTotal
$f =~ /\b$l=(.*(?:(?<=\\)\n.*)*)/ or die "starfish:getmakefilelist:no list:$l" 1 0 1
1110 die "starfish:getmakefilelist:no list:$l";
1111 1 $f=$1; $f=~s/\\\n/ /g;
1112 1 $f =~ s/^\s+//; $f =~ s/\s+$//;
1113 1 return split(/\s+/, $f);
1114 }
1115  
1116 61 ▶sub echo(@) { $::O .= join('', @_) }
Subroutine echo: called CC=1 SCAR=0.0
Pod documented
1117  
1118 # used in LaTeX mode to include verbatim textual files
1119 1 ▶sub get_verbatim_file {
Subroutine get_verbatim_file: called CC=1 SCAR=6.9
Pod documented
1120 0 my $f = shift;
1121 0 return "\\begin{verbatim}\n".
1122 untabify(scalar(getfile($f))).
1123 "\\end{verbatim}\n";
1124 }
1125  
1126 1 ▶sub untabify {
Subroutine untabify: called CC=3 SCAR=24.8
Pod undocumented
1127 0 local $_ = shift;
1128 0 my ($r, $l);
1129 0 ▶ while (/[\t\n]/) {
Branch: 1 branch
BranchTrueFalseTotal
if (/[\t\n]/) 0 0 0
1130 0 ▶ if ($& eq "\n") { $r.="$l$`\n"; $l=''; $_ = $'; }
Branch: 1 branch
BranchTrueFalseTotal
if ($& eq "\n") { } 0 0 0
1131 else {
1132 0 $l .= $`;
1133 0 $l .= ' ' x (8 - (length($l) & 7));
1134 0 $_ = $';
1135 }
1136 }
1137 0 return $r.$l.$_;
1138 }
1139  
1140 51 ▶sub getfile($) {
Subroutine getfile: called CC=3 SCAR=11.2
Pod documented
1141 50 my $f = shift;
1142 50 local *F;
1143 50 ▶ open(F, "<$f") or die "starfish:getfile:cannot open $f:$!";
Branch: 1 branch
BranchTrueFalseTotal
open F, "<$f" or die "starfish:getfile:cannot open ${f}:$!" 50 0 50
1144 50 my @r = <F>;
1145 50 close(F);
1146 50 ▶ return wantarray ? @r : join ('', @r);
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 50 50
1147 }
1148  
1149 100 ▶sub putfile($@) {
Subroutine putfile: called CC=4 SCAR=13.9
Pod documented
1150 99 my $f = shift;
1151 99 local *F;
1152 99 ▶ open(F, ">$f") or die "starfish:putfile:cannot open $f:$!";
Branch: 1 branch
BranchTrueFalseTotal
open F, ">$f" or die "starfish:putfile:cannot open ${f}:$!" 99 0 99
1153 99 ▶ print F '' unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 22 77 99
1154 99 ▶ while (@_) { print F shift(@_) }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 77 99 176
1155 99 close(F);
1156 }
1157  
1158 1 ▶sub appendfile($@) {
Subroutine appendfile: called CC=4 SCAR=30.0
Pod documented
1159 0 my $f = shift;
1160 0 local *F;
1161 0 ▶ open(F, ">>$f") or die "starfish:appendfile:cannot open $f:$!";
Branch: 1 branch
BranchTrueFalseTotal
open F, ">>$f" or die "starfish:appendfile:cannot open ${f}:$!" 0 0 0
1162 0 ▶ print F '' unless @_;
Branch: 1 branch
BranchTrueFalseTotal
unless @_ 0 0 0
1163 0 ▶ while (@_) { print F shift(@_) }
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
1164 0 close(F);
1165 }
1166  
1167 1 ▶sub htmlquote($) {
Subroutine htmlquote: called CC=1 SCAR=6.9
Pod documented
1168 0 local $_ = shift;
1169 0 s/&/&amp;/g;
1170 0 s/</&lt;/g;
1171 0 s/\"/&quot;/g;
1172 0 return $_;
1173 }
1174  
1175 1 ▶sub read_records($ ) {
Subroutine read_records: called CC=17 SCAR=57.2
Pod documented
1176 0 my $arg = shift;
1177 0 ▶ if ($arg =~ /^file=/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg =~ /^file=/) 0 0 0
1178 0 ▶ my $f = $'; local *F; open(F, $f) or croak "cannot open $f:$!";
Branch: 1 branch
BranchTrueFalseTotal
open F, $f or croak("cannot open ${f}:$!") 0 0 0
1179 0 $arg = join('', <F>);
1180 0 close(F);
1181 }
1182  
1183 0 my $db = [];
1184 0 ▶ while ($arg) {
Branch: 1 branch
BranchTrueFalseTotal
if ($arg) 0 0 0
1185 0 ▶ if ($arg =~ /^([ \t\r]*(#.*)?\n)+/) { $arg = $'; }
Branch: 1 branch
BranchTrueFalseTotal
if ($arg =~ /^([ \t\r]*(#.*)?\n)+/) 0 0 0
1186 0 ▶ last if $arg eq ''; my $record;
Branch: 1 branch
BranchTrueFalseTotal
if $arg eq "" 0 0 0
1187 0 ▶ if ($arg =~ /([ \t\r]*\n){2,}/) { $record = "$`\n"; $arg = $'; }
Branch: 1 branch
BranchTrueFalseTotal
if ($arg =~ /([ \t\r]*\n){2,}/) { } 0 0 0
1188 0 else { $record = $arg; $arg = ''; }
1189 0 my $r = {}; my $recordsave = $record;
1190 0 ▶ while ($record) {
Branch: 1 branch
BranchTrueFalseTotal
if ($record) 0 0 0
1191 0 ▶ if ($record =~ /^[ \t]*#.*\n/) { $record=$'; next; } # allow
Branch: 1 branch
BranchTrueFalseTotal
if ($record =~ /^[ \t]*#.*\n/) 0 0 0
1192 # comments in records
1193 0 ▶ $record =~ /^[ \t]*([^\n:]*?)[ \t]*:/ or
Branch: 1 branch
BranchTrueFalseTotal
$record =~ /^[ \t]*([^\n:]*?)[ \t]*:/ or croak("db8: no attribute in record: ($recordsave)") 0 0 0
1194 croak "db8: no attribute in record: ($recordsave)";
1195 0 my $k = $1; $record = $'; my $v;
1196 0 ▶ croak "empty key in ($recordsave)" if $k eq '';
Branch: 1 branch
BranchTrueFalseTotal
if $k eq "" 0 0 0
1197 0 while (1) { # .................... line continuation
1198 0 ▶ if ($record =~ /^(.*?)\\(\r?\n)/) { $v .= $1.$2; $record = $'; }
Branch: 3 branches
BranchTrueFalseTotal
if ($record =~ /^(.*?)\\(\r?\n)/) { } 0 0 0
elsif ($record =~ /^.*?\r?\n[ \t]/) { } 0 0 0
elsif ($record =~ /^(.*?)\r?\n/) { } 0 0 0
1199 0 elsif ($record =~ /^.*?\r?\n[ \t]/) { $v .= $&; $record = $'; }
1200 0 elsif ($record =~ /^(.*?)\r?\n/) { $v .= $1; $record = $'; last; }
1201 0 else { $v .= $record; $record = ''; last }
1202 }
1203 0 ▶ if (exists($r->{$k})) {
Branch: 1 branch
BranchTrueFalseTotal
if (exists $r->{$k}) 0 0 0
1204 0 my $c = 0;
1205 0 ▶ while (exists($r->{"$k-$c"})) { ++$c }
Branch: 1 branch
BranchTrueFalseTotal
if (exists $$r{"$k-$c"}) 0 0 0
1206 0 $k = "$k-$c";
1207 }
1208 0 $r->{$k} = $v;
1209 }
1210 0 push @{ $db }, $r;
1211 }
1212 0 ▶ return wantarray ? @{$db} : $db;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 0 0
1213 }
1214  
1215 0 ▶sub current_year { return POSIX::strftime("%Y", localtime(time)) }
Subroutine current_year: called CC=1 SCAR=6.9
Pod documented
1216  
1217 1 ▶sub last_update() {
Subroutine last_update: called CC=3 SCAR=24.8
Pod documented
1218 0 ▶ my $self = @_ ? shift : $::Star;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
1219 0 ▶ if ($self->{Loops} < 2) { $self->{Loops} = 2 }
Branch: 1 branch
BranchTrueFalseTotal
if ($self->{"Loops"} < 2) 0 0 0
1220 0 return POSIX::strftime("%d-%b-%Y", localtime($self->{LastUpdateTime}));
1221 }
1222  
1223 1 ▶sub file_modification_time() {
Subroutine file_modification_time: called CC=2 SCAR=17.9
Pod documented
1224 0 ▶ my $self = @_ ? shift : $::Star;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
1225 0 return (stat $self->{INFILE})[9];
1226 }
1227  
1228 1 ▶sub file_modification_date() {
Subroutine file_modification_date: called CC=2 SCAR=17.9
Pod documented
1229 0 ▶ my $self = @_ ? shift : $::Star;
Branch: 1 branch
BranchTrueFalseTotal
@_ ? : 0 0 0
1230  
1231 0 my $t = $self->file_modification_time();
1232 0 my @a = localtime($t); $a[5] += 1900;
1233 0 return qw/January February March April May June July
1234 August September October November December/
1235 [$a[4]]." $a[3], $a[5]";
1236 }
1237  
1238 1 ▶sub read_starfish_conf() {
Subroutine read_starfish_conf: called CC=6 SCAR=37.4
Pod documented
1239 0 ▶ return unless -e "starfish.conf";
Branch: 1 branch
BranchTrueFalseTotal
unless -e "starfish.conf" 0 0 0
1240 0 my @dirs = ( '.' );
1241 0 ▶ while ( -e "$dirs[0]/../starfish.conf" )
Branch: 1 branch
BranchTrueFalseTotal
if (-e "$dirs[0]/../starfish.conf") 0 0 0
1242 0 { unshift @dirs, "$dirs[0]/.." }
1243  
1244 0 my $currdir = cwd();
1245 0 foreach my $d (@dirs) {
1246 0 ▶ chdir $d or die "cannot chdir to $d";
Branch: 1 branch
BranchTrueFalseTotal
chdir $d or die "cannot chdir to $d" 0 0 0
1247 package main;
1248 0 require "$currdir/$d/starfish.conf";
1249 package Text::Starfish;
1250 0 ▶ chdir $currdir or die "cannot chdir to $currdir";
Branch: 1 branch
BranchTrueFalseTotal
chdir $currdir or die "cannot chdir to $currdir" 0 0 0
1251 }
1252 }
1253  
1254 2 ▶sub _croak {
Subroutine _croak: called CC=1 SCAR=0.0
1255 1 my $m = shift;
1256 1 require Carp;
1257 1 Carp::croak($m);
1258 }
1259  
1260 # used in makefile mode
1261 #kw:makefile
1262 1 ▶sub make_add_dirs_to_generate_if_needed {
Subroutine make_add_dirs_to_generate_if_needed: called CC=3 SCAR=24.8
Pod undocumented
1263 0 for my $d (@_) {
1264 0 ▶ next if grep { $_ eq $d } @DirGenerateIfNeeded;
Branch: 1 branch
BranchTrueFalseTotal
if grep {$_ eq $d;} @Text::Starfish::DirGenerateIfNeeded 0 0 0
1265 0 push @DirGenerateIfNeeded, $d;
1266 } }
1267 1 ▶sub make_gen_dirs_to_generate {
Subroutine make_gen_dirs_to_generate: called CC=2 SCAR=17.9
Pod undocumented
1268 0 foreach my $d (@DirGenerateIfNeeded) {
1269 0 echo "$d:; mkdir -p \$\@\n" } }
1270  
1271 4 1;
1272  
1273 __END__
↑ Summary testfiles/23-methods/test.pl »