| 1 | package Pod::Literate; | ||||||||||||||||||||||||||||||||||||||||||||
| 2 | 1 | ▶ | use parent 'Pod::Simple'; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 3 | 1 | our $VERSION='0.0.5'; | |||||||||||||||||||||||||||||||||||||||||||
| 4 | 1 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 5 | 1 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||||
| 7 | 1 | my $cache='--PODLITERATECACHE--'; | |||||||||||||||||||||||||||||||||||||||||||
| 8 | 1 | my $tagL='#<'; | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 1 | my $tagR='>#'; | |||||||||||||||||||||||||||||||||||||||||||
| 10 | 1 | my $reSection=qr/$tagL\h*(.+?)\h*$tagR/; | |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||||
| 12 | 4 | ▶ | sub new { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
new: called CC=2 SCAR=7.2
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||||
| 13 | 4 | my ($class)=@_; | |||||||||||||||||||||||||||||||||||||||||||
| 14 | 4 | my $self=$class->SUPER::new(); | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 0 | ▶ | if(exists($$self{$cache})) { die 'Basic Pod::Simple object unexpectedly contains the Pod::Literate cache key' } | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 16 | 4 | $$self{$cache}={ | |||||||||||||||||||||||||||||||||||||||||||
| 17 | ofn =>[], # the output filenames for the tangled application | ||||||||||||||||||||||||||||||||||||||||||||
| 18 | section =>{}, # the collection of named sections | ||||||||||||||||||||||||||||||||||||||||||||
| 19 | mode =>'', # scanning mode, to distinguish begin/for tags | ||||||||||||||||||||||||||||||||||||||||||||
| 20 | target =>undef, # defined and destroyed while scanning | ||||||||||||||||||||||||||||||||||||||||||||
| 21 | collector=>undef, # defined and destroyed while scanning | ||||||||||||||||||||||||||||||||||||||||||||
| 22 | # | ||||||||||||||||||||||||||||||||||||||||||||
| 23 | dep =>{}, # used during tangling to compute dependencies | ||||||||||||||||||||||||||||||||||||||||||||
| 24 | }; | ||||||||||||||||||||||||||||||||||||||||||||
| 25 | 4 | return $self; | |||||||||||||||||||||||||||||||||||||||||||
| 26 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||||
| 28 | 13 | ▶ | sub targetSet { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
targetSet: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||
| 29 | 13 | my ($self,$name)=@_; | |||||||||||||||||||||||||||||||||||||||||||
| 30 | 13 | $$self{$cache}{target}=$name; | |||||||||||||||||||||||||||||||||||||||||||
| 31 | 13 | return $self; | |||||||||||||||||||||||||||||||||||||||||||
| 32 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 33 | |||||||||||||||||||||||||||||||||||||||||||||
| 34 | 35 | ▶ | sub target { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
target: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||
| 35 | 35 | my ($self)=@_; | |||||||||||||||||||||||||||||||||||||||||||
| 36 | 35 | return $$self{$cache}{target}; | |||||||||||||||||||||||||||||||||||||||||||
| 37 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||||
| 39 | 13 | ▶ | sub sectionAppend { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sectionAppend: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||
| 40 | 13 | my ($self,$section,$text)=@_; | |||||||||||||||||||||||||||||||||||||||||||
| 41 | 13 | $$self{$cache}{section}{$section}.=$text; | |||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||||
| 44 | 3 | ▶ | sub section { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
section: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||
| 45 | 3 | my ($self,$section)=@_; | |||||||||||||||||||||||||||||||||||||||||||
| 46 | 3 | return $$self{$cache}{section}{$section}; | |||||||||||||||||||||||||||||||||||||||||||
| 47 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 48 | |||||||||||||||||||||||||||||||||||||||||||||
| 49 | 12 | ▶ | sub sectionRegexp { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sectionRegexp: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||
| 50 | 12 | my ($name)=@_; | |||||||||||||||||||||||||||||||||||||||||||
| 51 | 12 | return qr/$tagL\h*\Q$name\E\h*$tagR/; | |||||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 53 | |||||||||||||||||||||||||||||||||||||||||||||
| 54 | 28 | ▶ | sub initCollection { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
initCollection: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||
| 55 | 28 | my ($self,$text)=@_; | |||||||||||||||||||||||||||||||||||||||||||
| 56 | 28 | ▶ | $$self{$cache}{collector}=$text//''; | ||||||||||||||||||||||||||||||||||||||||||
|
Condition50%1/2
$text // ""
MC/DC0%0/1
$text // ""
$text
Truth table50%1/2
A
A= $text
| |||||||||||||||||||||||||||||||||||||||||||||
| 57 | 28 | return $self; | |||||||||||||||||||||||||||||||||||||||||||
| 58 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 59 | |||||||||||||||||||||||||||||||||||||||||||||
| 60 | 12 | ▶ | sub collected { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
collected: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||
| 61 | 12 | my ($self)=@_; | |||||||||||||||||||||||||||||||||||||||||||
| 62 | 12 | return unindent($$self{$cache}{collector}); | |||||||||||||||||||||||||||||||||||||||||||
| 63 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 64 | |||||||||||||||||||||||||||||||||||||||||||||
| 65 | 16 | ▶ | sub clearCollection { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
clearCollection: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||
| 66 | 16 | my ($self)=@_; | |||||||||||||||||||||||||||||||||||||||||||
| 67 | 16 | delete(@{$$self{$cache}}{qw/target collector/}); | |||||||||||||||||||||||||||||||||||||||||||
| 68 | 16 | return $self; | |||||||||||||||||||||||||||||||||||||||||||
| 69 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 70 | |||||||||||||||||||||||||||||||||||||||||||||
| 71 | 15 | ▶ | sub unindent { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
unindent: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||
| 72 | 15 | my ($s)=@_; | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 15 | ▶ | if($s=~/^(\h+)/) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 74 | 13 | my $indent=$1; | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 13 | $s=~s/^\Q$indent\E//mg; | |||||||||||||||||||||||||||||||||||||||||||
| 76 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 77 | 15 | return $s; | |||||||||||||||||||||||||||||||||||||||||||
| 78 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 79 | |||||||||||||||||||||||||||||||||||||||||||||
| 80 | 8 | ▶ | sub indent { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
indent: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||
| 81 | 8 | my ($code,$indent)=@_; | |||||||||||||||||||||||||||||||||||||||||||
| 82 | 8 | ▶ | if(!$indent) { return $code } | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 83 | 2 | $code=~s/^/$indent/emg; | |||||||||||||||||||||||||||||||||||||||||||
| 84 | 2 | return $code; | |||||||||||||||||||||||||||||||||||||||||||
| 85 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||||
| 87 | 59 | ▶ | sub _handle_element_start { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_handle_element_start: called CC=9 SCAR=22.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 88 | 59 | my ($self,$element,$attribute)=@_; | |||||||||||||||||||||||||||||||||||||||||||
| 89 | 59 | ▶ | my $target=$$attribute{target}//''; | ||||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$attribute->{"target"} // ""
MC/DC100%1/1
$attribute->{"target"} // ""
$attribute->{"target"}
Truth table100%2/2
A
A= $attribute->{"target"}
| |||||||||||||||||||||||||||||||||||||||||||||
| 90 | 59 | ▶ | if($target eq ':literate') { die 'Non-data paragraphs are not currently supported via ":literate"' } | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 91 | 57 | ▶ | if($element eq 'D') { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 92 | 2 | $$self{$cache}{mode}='declare'; | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 2 | $self->clearCollection()->initCollection(); | |||||||||||||||||||||||||||||||||||||||||||
| 94 | 2 | return; | |||||||||||||||||||||||||||||||||||||||||||
| 95 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 96 | 55 | ▶ | if($target!~/^literate(?::command)?$/) { return } | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 97 | 18 | ▶ | if(my $name=$self->target()) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 98 | 6 | $self->sectionAppend($name, $self->collected()); | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 6 | $self->clearCollection()->initCollection(); | |||||||||||||||||||||||||||||||||||||||||||
| 100 | 6 | return; | |||||||||||||||||||||||||||||||||||||||||||
| 101 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 102 | 12 | ▶ | if($element eq 'for') { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 103 | 12 | ▶ | if($target eq 'literate:command') { $$self{$cache}{mode}='command' } | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 104 | 10 | else { $$self{$cache}{mode}=$$attribute{'~really'} } | |||||||||||||||||||||||||||||||||||||||||||
| 105 | 12 | ▶ | if($$attribute{title}) { my $s=$$attribute{title}; $s=~s/^\+//; $self->targetSet($s) } | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 106 | 12 | $self->initCollection(); | |||||||||||||||||||||||||||||||||||||||||||
| 107 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 108 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 109 | |||||||||||||||||||||||||||||||||||||||||||||
| 110 | 56 | ▶ | sub _handle_element_end { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_handle_element_end: called CC=15 SCAR=28.0
| |||||||||||||||||||||||||||||||||||||||||||||
| 111 | 56 | my ($self,$element,$attribute)=@_; | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 56 | ▶ | if($element eq 'for') { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 4 branches
| |||||||||||||||||||||||||||||||||||||||||||||
| 113 | 18 | my ($mode,$collected)=@{$$self{$cache}}{qw/mode collector/}; | |||||||||||||||||||||||||||||||||||||||||||
| 114 | 18 | ▶ | if(($mode eq 'command')&&($collected=~/^target=(.+)$/)) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
Condition66%2/3
$mode eq "command" and $collected =~ /^target=(.+)$/
MC/DC50%1/2
$mode eq "command" and $collected =~ /^target=(.+)$/
$mode eq "command"
$collected =~ /^target=(.+)$/
Truth table66%2/3
A and B
A= $mode eq "command"B= $collected =~ /^target=(.+)$/
| |||||||||||||||||||||||||||||||||||||||||||||
| 115 | 2 | push @{$$self{$cache}{ofn}},$1; | |||||||||||||||||||||||||||||||||||||||||||
| 116 | 2 | $self->clearCollection(); | |||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 118 | ▶ | elsif(($mode eq '=for')&&($collected=~/^target:(.+)$/)) { | |||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$mode eq "=for" and $collected =~ /^target:(.+)$/
MC/DC0%0/2
$mode eq "=for" and $collected =~ /^target:(.+)$/
$mode eq "=for"
$collected =~ /^target:(.+)$/
Truth table66%2/3
A and B
A= $mode eq "=for"B= $collected =~ /^target:(.+)$/
| |||||||||||||||||||||||||||||||||||||||||||||
| 119 | 0 | print STDERR "=for literate target: is deprecated; use =for literate:command\n"; | |||||||||||||||||||||||||||||||||||||||||||
| 120 | 0 | push @{$$self{$cache}{ofn}},$1; | |||||||||||||||||||||||||||||||||||||||||||
| 121 | 0 | $self->clearCollection(); | |||||||||||||||||||||||||||||||||||||||||||
| 122 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 123 | ▶ | elsif(($mode eq '=for')&&($collected eq ".\n")) { | |||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$mode eq "=for" and $collected eq ".\n"
MC/DC0%0/2
$mode eq "=for" and $collected eq ".\n"
$mode eq "=for"
$collected eq ".\n"
Truth table66%2/3
A and B
A= $mode eq "=for"B= $collected eq ".\n"
| |||||||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | $self->clearCollection(); | |||||||||||||||||||||||||||||||||||||||||||
| 125 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 126 | elsif($mode eq '=for') { | ||||||||||||||||||||||||||||||||||||||||||||
| 127 | 6 | my $s=$collected; $s=~s/^\+//; $s=~s/\n$//s; | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 6 | $self->targetSet($s); | |||||||||||||||||||||||||||||||||||||||||||
| 129 | 6 | $self->initCollection(); | |||||||||||||||||||||||||||||||||||||||||||
| 130 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 131 | elsif($self->target()) { | ||||||||||||||||||||||||||||||||||||||||||||
| 132 | 4 | $self->sectionAppend($self->target(), $self->collected()); | |||||||||||||||||||||||||||||||||||||||||||
| 133 | 4 | $self->clearCollection(); | |||||||||||||||||||||||||||||||||||||||||||
| 134 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 135 | 18 | $$self{$cache}{mode}=''; | |||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 137 | ▶ | elsif(($element eq 'D')&&('declare' eq $$self{$cache}{mode})) { | |||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$element eq "D" and "declare" eq $self->{$cache}{"mode"}
MC/DC50%1/2
$element eq "D" and "declare" eq $self->{$cache}{"mode"}
$element eq "D"
"declare" eq $self->{$cache}{"mode"}
Truth table66%2/3
A and B
A= $element eq "D"B= "declare" eq $self->{$cache}{"mode"}
| |||||||||||||||||||||||||||||||||||||||||||||
| 138 | 2 | my $s=$$self{$cache}{collector}; $s=~s/^\s*\+?//; $s=~s/\s*\n*$//; | |||||||||||||||||||||||||||||||||||||||||||
| 139 | 2 | $self->targetSet($s); | |||||||||||||||||||||||||||||||||||||||||||
| 140 | 2 | $self->initCollection(); | |||||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 142 | ▶ | elsif(($element eq 'C')&&('declare' eq $$self{$cache}{mode})) { | |||||||||||||||||||||||||||||||||||||||||||
|
Condition66%2/3
$element eq "C" and "declare" eq $self->{$cache}{"mode"}
MC/DC50%1/2
$element eq "C" and "declare" eq $self->{$cache}{"mode"}
$element eq "C"
"declare" eq $self->{$cache}{"mode"}
Truth table66%2/3
A and B
A= $element eq "C"B= "declare" eq $self->{$cache}{"mode"}
| |||||||||||||||||||||||||||||||||||||||||||||
| 143 | 2 | my $collected=$self->collected(); | |||||||||||||||||||||||||||||||||||||||||||
| 144 | 2 | $collected=~s/^\s*=//; | |||||||||||||||||||||||||||||||||||||||||||
| 145 | 2 | $self->sectionAppend($self->target(),$collected); | |||||||||||||||||||||||||||||||||||||||||||
| 146 | 2 | $self->clearCollection(); | |||||||||||||||||||||||||||||||||||||||||||
| 147 | 2 | $$self{$cache}{mode}=''; | |||||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 149 | elsif($element eq 'Document') { | ||||||||||||||||||||||||||||||||||||||||||||
| 150 | 1 | $self->tangle(); | |||||||||||||||||||||||||||||||||||||||||||
| 151 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 152 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 153 | |||||||||||||||||||||||||||||||||||||||||||||
| 154 | 39 | ▶ | sub _handle_text { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
_handle_text: called CC=2 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||||
| 155 | 39 | my ($self,$text)=@_; | |||||||||||||||||||||||||||||||||||||||||||
| 156 | 39 | ▶ | if(defined($$self{$cache}{collector})) { $$self{$cache}{collector}.=$text."\n" } | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 157 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 158 | |||||||||||||||||||||||||||||||||||||||||||||
| 159 | 1 | ▶ | sub tangle { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tangle: called CC=8 SCAR=20.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||
| 160 | 1 | my ($self)=@_; | |||||||||||||||||||||||||||||||||||||||||||
| 161 | 1 | my (%tobuild,@todo); # prebuild to keep the loops separate | |||||||||||||||||||||||||||||||||||||||||||
| 162 | 1 | $self->prepareSections(); | |||||||||||||||||||||||||||||||||||||||||||
| 163 | 1 | ▶ | while(my ($ka,$refb)=each %{$$self{$cache}{dep}}) { $tobuild{$ka}={map {$_=>1} keys(%$refb)} } | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 164 | 1 | ▶ | while(my @names=sort grep {!%{$tobuild{$_}}} keys(%tobuild)) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 165 | 3 | push @todo,@names; | |||||||||||||||||||||||||||||||||||||||||||
| 166 | 3 | delete(@tobuild{@names}); | |||||||||||||||||||||||||||||||||||||||||||
| 167 | 3 | foreach my $name (values %tobuild) { delete(@$name{@names}) } | |||||||||||||||||||||||||||||||||||||||||||
| 168 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 169 | 1 | foreach my $name (@todo) { $self->tangleSection($name) } | |||||||||||||||||||||||||||||||||||||||||||
| 170 | 1 | foreach my $ofn (@{$$self{$cache}{ofn}}) { | |||||||||||||||||||||||||||||||||||||||||||
| 171 | 2 | ▶ | if(my $oft=$self->section($ofn)) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 172 | 2 | ▶ | open(my $fh,'>',$ofn) or die "open: $!"; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 173 | 2 | print $fh $oft; | |||||||||||||||||||||||||||||||||||||||||||
| 174 | 2 | close($fh); | |||||||||||||||||||||||||||||||||||||||||||
| 175 | } } | ||||||||||||||||||||||||||||||||||||||||||||
| 176 | 1 | return $self; | |||||||||||||||||||||||||||||||||||||||||||
| 177 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 178 | |||||||||||||||||||||||||||||||||||||||||||||
| 179 | 10 | ▶ | sub tangleSection { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
tangleSection: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||
| 180 | 10 | my ($self,$name)=@_; | |||||||||||||||||||||||||||||||||||||||||||
| 181 | 10 | my $section=$$self{$cache}{section}{$name}; | |||||||||||||||||||||||||||||||||||||||||||
| 182 | 10 | foreach my $import (keys %{$$self{$cache}{dep}{$name}}) { | |||||||||||||||||||||||||||||||||||||||||||
| 183 | 10 | my $re=sectionRegexp($import); | |||||||||||||||||||||||||||||||||||||||||||
| 184 | 10 | my $code=$$self{$cache}{section}{$import}; $code=~s/\n$//s; | |||||||||||||||||||||||||||||||||||||||||||
| 185 | 10 | ▶ | while($section=~/^(\h*)$re\h*$/m) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 186 | 6 | my $icode=indent($code,$1); | |||||||||||||||||||||||||||||||||||||||||||
| 187 | 6 | $section=~s/^\h*$re\h*$/$icode/em; | |||||||||||||||||||||||||||||||||||||||||||
| 188 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 189 | 10 | $section=~s/$re/$code/ge; | |||||||||||||||||||||||||||||||||||||||||||
| 190 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 191 | 10 | $$self{$cache}{section}{$name}=$section; | |||||||||||||||||||||||||||||||||||||||||||
| 192 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 193 | |||||||||||||||||||||||||||||||||||||||||||||
| 194 | 11 | ▶ | sub codeSectionNames { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
codeSectionNames: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||
| 195 | 11 | my ($code)=@_; | |||||||||||||||||||||||||||||||||||||||||||
| 196 | 11 | my %names; | |||||||||||||||||||||||||||||||||||||||||||
| 197 | 11 | ▶ | while($code=~m/$reSection/g) { $names{$1}=1 } | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 198 | 11 | return keys(%names); | |||||||||||||||||||||||||||||||||||||||||||
| 199 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 200 | |||||||||||||||||||||||||||||||||||||||||||||
| 201 | 1 | ▶ | sub prepareSections { | ||||||||||||||||||||||||||||||||||||||||||
|
Subroutine
prepareSections: called CC=13 SCAR=26.7
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||||
| 202 | 1 | my ($self)=@_; | |||||||||||||||||||||||||||||||||||||||||||
| 203 | 1 | my ($changed,$sections,%dep,%missing,%cyclic)=(1); | |||||||||||||||||||||||||||||||||||||||||||
| 204 | 1 | $sections=$$self{$cache}{section}; | |||||||||||||||||||||||||||||||||||||||||||
| 205 | 1 | ▶ | while(my ($k,$code)=each %$sections) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 206 | 10 | foreach my $name (codeSectionNames($code)) { | |||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | ▶ | if(!defined($$sections{$name})) { $missing{$name}=1 } | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 208 | 9 | $dep{$k}{$name}=1; | |||||||||||||||||||||||||||||||||||||||||||
| 209 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 210 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | ▶ | if(%missing) { die 'Name referenced but not defined: '.join(q{; },sort keys %missing) } | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 212 | 1 | ▶ | while($changed) { $changed=0; | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 213 | 2 | foreach my $ka (keys %dep) { | |||||||||||||||||||||||||||||||||||||||||||
| 214 | 13 | foreach my $kb (keys %{$dep{$ka}}) { | |||||||||||||||||||||||||||||||||||||||||||
| 215 | 19 | foreach my $kc (keys %{$dep{$kb}}) { | |||||||||||||||||||||||||||||||||||||||||||
| 216 | 2 | my $d=$dep{$ka}{$kb}+$dep{$kb}{$kc}; | |||||||||||||||||||||||||||||||||||||||||||
| 217 | 2 | ▶ | if(!defined($dep{$ka}{$kc})||($dep{$ka}{$kc}<$d)) { | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
not defined $dep{$ka}{$kc} or $dep{$ka}{$kc} < $d
MC/DC50%1/2
not defined $dep{$ka}{$kc} or $dep{$ka}{$kc} < $d
not defined $dep{$ka}{$kc}
$dep{$ka}{$kc} < $d
Truth table66%2/3
not(A) or B
A= not defined $dep{$ka}{$kc}B= $dep{$ka}{$kc} < $d
| |||||||||||||||||||||||||||||||||||||||||||||
| 218 | 1 | $dep{$ka}{$kc}=$d; $changed=1; | |||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | ▶ | if($ka eq $kc) { $cyclic{$ka}=1 } | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 220 | } } | ||||||||||||||||||||||||||||||||||||||||||||
| 221 | } } | ||||||||||||||||||||||||||||||||||||||||||||
| 222 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 223 | 0 | ▶ | if(%cyclic) { die 'Sections contain cyclic dependencies: '.join(q{, },sort keys %cyclic) } | ||||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||||
| 224 | 1 | $$self{$cache}{dep}=\%dep; | |||||||||||||||||||||||||||||||||||||||||||
| 225 | 1 | return $self; | |||||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||||
| 228 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||||
| 230 | __END__ | ||||||||||||||||||||||||||||||||||||||||||||