| 1 | package Muster::Hook::MindMap; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | 1 | $Muster::Hook::MindMap::VERSION = '0.96'; | |||||||||||||||||||||||||||||||||||||||||
| 3 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 4 | |||||||||||||||||||||||||||||||||||||||||||
| 5 | Muster::Hook::MindMap - Muster hook for mind maps | ||||||||||||||||||||||||||||||||||||||||||
| 6 | |||||||||||||||||||||||||||||||||||||||||||
| 7 | =head1 VERSION | ||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | version 0.96 | ||||||||||||||||||||||||||||||||||||||||||
| 10 | |||||||||||||||||||||||||||||||||||||||||||
| 11 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 12 | |||||||||||||||||||||||||||||||||||||||||||
| 13 | # CamelCase plugin name | ||||||||||||||||||||||||||||||||||||||||||
| 14 | package Muster::Hook::MindMap; | ||||||||||||||||||||||||||||||||||||||||||
| 15 | use Mojo::Base 'Muster::Hook'; | ||||||||||||||||||||||||||||||||||||||||||
| 16 | |||||||||||||||||||||||||||||||||||||||||||
| 17 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 18 | |||||||||||||||||||||||||||||||||||||||||||
| 19 | L<Muster::Hook::MindMap> does mind maps: | ||||||||||||||||||||||||||||||||||||||||||
| 20 | transforming a tagged unordered list into a connected graph. | ||||||||||||||||||||||||||||||||||||||||||
| 21 | Base mind-maps on lists, cross-linked. | ||||||||||||||||||||||||||||||||||||||||||
| 22 | Depends on GraphViz plugin to display the maps as maps. | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | The pattern for mind maps is "* mindmap" | ||||||||||||||||||||||||||||||||||||||||||
| 25 | |||||||||||||||||||||||||||||||||||||||||||
| 26 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 27 | |||||||||||||||||||||||||||||||||||||||||||
| 28 | 1 | ▶ | use Mojo::Base 'Muster::Hook'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 29 | 1 | ▶ | use Muster::Hooks; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 30 | 1 | ▶ | use Muster::LeafFile; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 31 | 1 | ▶ | use YAML::Any; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | 1 | our $DEBUG = ''; | |||||||||||||||||||||||||||||||||||||||||
| 34 | |||||||||||||||||||||||||||||||||||||||||||
| 35 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 36 | |||||||||||||||||||||||||||||||||||||||||||
| 37 | =head2 register | ||||||||||||||||||||||||||||||||||||||||||
| 38 | |||||||||||||||||||||||||||||||||||||||||||
| 39 | Initialize, and register hooks. | ||||||||||||||||||||||||||||||||||||||||||
| 40 | |||||||||||||||||||||||||||||||||||||||||||
| 41 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 42 | 0 | ▶ | sub register { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
register: not called CC=1 SCAR=6.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 43 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 44 | 0 | my $hookmaster = shift; | |||||||||||||||||||||||||||||||||||||||||
| 45 | 0 | my $conf = shift; | |||||||||||||||||||||||||||||||||||||||||
| 46 | |||||||||||||||||||||||||||||||||||||||||||
| 47 | # we need to be able to look things up in the database | ||||||||||||||||||||||||||||||||||||||||||
| 48 | 0 | $self->{metadb} = $hookmaster->{metadb}; | |||||||||||||||||||||||||||||||||||||||||
| 49 | |||||||||||||||||||||||||||||||||||||||||||
| 50 | 0 | ▶ | $hookmaster->add_hook('mindmap' => sub { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: not called CC=1 SCAR=6.9
| |||||||||||||||||||||||||||||||||||||||||||
| 51 | 0 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 52 | |||||||||||||||||||||||||||||||||||||||||||
| 53 | 0 | return $self->process(%args); | |||||||||||||||||||||||||||||||||||||||||
| 54 | }, | ||||||||||||||||||||||||||||||||||||||||||
| 55 | 0 | ); | |||||||||||||||||||||||||||||||||||||||||
| 56 | 0 | return $self; | |||||||||||||||||||||||||||||||||||||||||
| 57 | } # register | ||||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | =head2 process | ||||||||||||||||||||||||||||||||||||||||||
| 60 | |||||||||||||||||||||||||||||||||||||||||||
| 61 | Process (modify) a leaf object. | ||||||||||||||||||||||||||||||||||||||||||
| 62 | In scanning phase, this will do nothing. | ||||||||||||||||||||||||||||||||||||||||||
| 63 | In assembly phase, this will detect matching lists, | ||||||||||||||||||||||||||||||||||||||||||
| 64 | and create a graphviz directive (to later be processed by the graphviz plugin). | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | my $new_leaf = $self->process(%args); | ||||||||||||||||||||||||||||||||||||||||||
| 67 | |||||||||||||||||||||||||||||||||||||||||||
| 68 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 69 | 0 | ▶ | sub process { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
process: not called CC=2 SCAR=17.9
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 70 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 71 | 0 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 72 | |||||||||||||||||||||||||||||||||||||||||||
| 73 | 0 | my $leaf = $args{leaf}; | |||||||||||||||||||||||||||||||||||||||||
| 74 | 0 | my $phase = $args{phase}; | |||||||||||||||||||||||||||||||||||||||||
| 75 | |||||||||||||||||||||||||||||||||||||||||||
| 76 | 0 | ▶ | if ($phase ne $Muster::Hooks::PHASE_BUILD) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 77 | { | ||||||||||||||||||||||||||||||||||||||||||
| 78 | 0 | return $leaf; | |||||||||||||||||||||||||||||||||||||||||
| 79 | } | ||||||||||||||||||||||||||||||||||||||||||
| 80 | |||||||||||||||||||||||||||||||||||||||||||
| 81 | 0 | my $content = $leaf->cooked(); | |||||||||||||||||||||||||||||||||||||||||
| 82 | |||||||||||||||||||||||||||||||||||||||||||
| 83 | # Look for a "mindmap" list, and create a graphviz directive for it. | ||||||||||||||||||||||||||||||||||||||||||
| 84 | 0 | $content =~ s/\n[*]\s*mindmap\s*\((.*?)\)\n(.*?)\n\n/$self->create_mindmap($leaf,$2,$1)/sieg; | |||||||||||||||||||||||||||||||||||||||||
| 85 | 0 | $content =~ s/\n[*]\s*mindmap\n(.*?)\n\n/$self->create_mindmap($leaf,$1)/sieg; | |||||||||||||||||||||||||||||||||||||||||
| 86 | |||||||||||||||||||||||||||||||||||||||||||
| 87 | 0 | $leaf->{cooked} = $content; | |||||||||||||||||||||||||||||||||||||||||
| 88 | 0 | return $leaf; | |||||||||||||||||||||||||||||||||||||||||
| 89 | } # process | ||||||||||||||||||||||||||||||||||||||||||
| 90 | |||||||||||||||||||||||||||||||||||||||||||
| 91 | sub build_map_levels ($%); | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | =head2 create_mindmap | ||||||||||||||||||||||||||||||||||||||||||
| 94 | |||||||||||||||||||||||||||||||||||||||||||
| 95 | Create a mindmap from the given list | ||||||||||||||||||||||||||||||||||||||||||
| 96 | |||||||||||||||||||||||||||||||||||||||||||
| 97 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 98 | 0 | ▶ | sub create_mindmap ($$$;$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
create_mindmap: not called CC=13 SCAR=52.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 99 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 100 | 0 | my $leaf = shift; | |||||||||||||||||||||||||||||||||||||||||
| 101 | 0 | my $list_str = shift; | |||||||||||||||||||||||||||||||||||||||||
| 102 | |||||||||||||||||||||||||||||||||||||||||||
| 103 | # Optional parameters | ||||||||||||||||||||||||||||||||||||||||||
| 104 | 0 | ▶ | my $params = (@_ ? shift : ''); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 105 | 0 | my %params; | |||||||||||||||||||||||||||||||||||||||||
| 106 | 0 | ▶ | while ($params =~ m{ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 107 | (?:([-.\w]+)=)? # 1: named parameter key? | ||||||||||||||||||||||||||||||||||||||||||
| 108 | (?: | ||||||||||||||||||||||||||||||||||||||||||
| 109 | """(.*?)""" # 2: triple-quoted value | ||||||||||||||||||||||||||||||||||||||||||
| 110 | | | ||||||||||||||||||||||||||||||||||||||||||
| 111 | "([^"]*?)" # 3: single-quoted value | ||||||||||||||||||||||||||||||||||||||||||
| 112 | | | ||||||||||||||||||||||||||||||||||||||||||
| 113 | '''(.*?)''' # 4: triple-single-quote | ||||||||||||||||||||||||||||||||||||||||||
| 114 | | | ||||||||||||||||||||||||||||||||||||||||||
| 115 | <<([a-zA-Z]+)\n # 5: heredoc start | ||||||||||||||||||||||||||||||||||||||||||
| 116 | (.*?)\n\5 # 6: heredoc value | ||||||||||||||||||||||||||||||||||||||||||
| 117 | | | ||||||||||||||||||||||||||||||||||||||||||
| 118 | (\S+) # 7: unquoted value | ||||||||||||||||||||||||||||||||||||||||||
| 119 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 120 | (?:\s+|$) # delimiter to next param | ||||||||||||||||||||||||||||||||||||||||||
| 121 | }msgx) { | ||||||||||||||||||||||||||||||||||||||||||
| 122 | 0 | my $key=$1; | |||||||||||||||||||||||||||||||||||||||||
| 123 | 0 | my $val; | |||||||||||||||||||||||||||||||||||||||||
| 124 | 0 | ▶ | if (defined $2) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 5 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 125 | 0 | $val=$2; | |||||||||||||||||||||||||||||||||||||||||
| 126 | 0 | $val=~s/\r\n/\n/mg; | |||||||||||||||||||||||||||||||||||||||||
| 127 | 0 | $val=~s/^\n+//g; | |||||||||||||||||||||||||||||||||||||||||
| 128 | 0 | $val=~s/\n+$//g; | |||||||||||||||||||||||||||||||||||||||||
| 129 | } | ||||||||||||||||||||||||||||||||||||||||||
| 130 | elsif (defined $3) { | ||||||||||||||||||||||||||||||||||||||||||
| 131 | 0 | $val=$3; | |||||||||||||||||||||||||||||||||||||||||
| 132 | } | ||||||||||||||||||||||||||||||||||||||||||
| 133 | elsif (defined $4) { | ||||||||||||||||||||||||||||||||||||||||||
| 134 | 0 | $val=$4; | |||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||
| 136 | elsif (defined $7) { | ||||||||||||||||||||||||||||||||||||||||||
| 137 | 0 | $val=$7; | |||||||||||||||||||||||||||||||||||||||||
| 138 | } | ||||||||||||||||||||||||||||||||||||||||||
| 139 | elsif (defined $6) { | ||||||||||||||||||||||||||||||||||||||||||
| 140 | 0 | $val=$6; | |||||||||||||||||||||||||||||||||||||||||
| 141 | } | ||||||||||||||||||||||||||||||||||||||||||
| 142 | |||||||||||||||||||||||||||||||||||||||||||
| 143 | 0 | ▶ | if (defined $key) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 144 | 0 | $params{$key} = $val; | |||||||||||||||||||||||||||||||||||||||||
| 145 | } | ||||||||||||||||||||||||||||||||||||||||||
| 146 | else { | ||||||||||||||||||||||||||||||||||||||||||
| 147 | 0 | $params{$val} = ''; | |||||||||||||||||||||||||||||||||||||||||
| 148 | } | ||||||||||||||||||||||||||||||||||||||||||
| 149 | } | ||||||||||||||||||||||||||||||||||||||||||
| 150 | |||||||||||||||||||||||||||||||||||||||||||
| 151 | 0 | ▶ | my $prog = (exists $params{'prog'} ? $params{'prog'} : 'dot'); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 152 | 0 | ▶ | $params{top} = 'Mindmap' if !defined $params{top}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 153 | 0 | ▶ | $params{legend} = 'Map Legend' if !defined $params{legend}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 154 | |||||||||||||||||||||||||||||||||||||||||||
| 155 | 0 | my $map =<<EOT; | |||||||||||||||||||||||||||||||||||||||||
| 156 | [[!graph | ||||||||||||||||||||||||||||||||||||||||||
| 157 | prog=$prog | ||||||||||||||||||||||||||||||||||||||||||
| 158 | src=""" | ||||||||||||||||||||||||||||||||||||||||||
| 159 | rankdir=LR; | ||||||||||||||||||||||||||||||||||||||||||
| 160 | node [ fontsize = 10 ]; | ||||||||||||||||||||||||||||||||||||||||||
| 161 | edge [ color = grey30 ]; | ||||||||||||||||||||||||||||||||||||||||||
| 162 | EOT | ||||||||||||||||||||||||||||||||||||||||||
| 163 | 0 | my @lines = split(/^/, $list_str); | |||||||||||||||||||||||||||||||||||||||||
| 164 | 0 | my %terms = (); | |||||||||||||||||||||||||||||||||||||||||
| 165 | 0 | my %xref = (); | |||||||||||||||||||||||||||||||||||||||||
| 166 | 0 | my %inverted = (); | |||||||||||||||||||||||||||||||||||||||||
| 167 | 0 | my @ret = $self->parse_lines(lines=>\@lines, | |||||||||||||||||||||||||||||||||||||||||
| 168 | terms=>\%terms, | ||||||||||||||||||||||||||||||||||||||||||
| 169 | xref=>\%xref, | ||||||||||||||||||||||||||||||||||||||||||
| 170 | inverted=>\%inverted, | ||||||||||||||||||||||||||||||||||||||||||
| 171 | prev_indent=>0, | ||||||||||||||||||||||||||||||||||||||||||
| 172 | parent=>''); | ||||||||||||||||||||||||||||||||||||||||||
| 173 | 0 | my %legend = $self->extract_legend(%params, list=>\@ret, terms=>\%terms); | |||||||||||||||||||||||||||||||||||||||||
| 174 | 0 | $self->apply_legend(terms=>\%terms, legend=>\%legend, inverted=>\%inverted); | |||||||||||||||||||||||||||||||||||||||||
| 175 | 0 | my %derived = $self->derive_xrefs(terms=>\%terms, inverted=>\%inverted); | |||||||||||||||||||||||||||||||||||||||||
| 176 | 0 | $map .= $self->start_map(terms=>\%terms); | |||||||||||||||||||||||||||||||||||||||||
| 177 | 0 | $map .= $self->build_map_levels(%params, list=>\@ret, level=>0); | |||||||||||||||||||||||||||||||||||||||||
| 178 | 0 | $map .= $self->build_xrefs(xref=>\%xref, edge_color=>'blue3'); | |||||||||||||||||||||||||||||||||||||||||
| 179 | 0 | $map .= $self->build_xrefs(xref=>\%derived, edge_colour=>'green3'); | |||||||||||||||||||||||||||||||||||||||||
| 180 | |||||||||||||||||||||||||||||||||||||||||||
| 181 | 0 | $map .=<<EOT; | |||||||||||||||||||||||||||||||||||||||||
| 182 | """]] | ||||||||||||||||||||||||||||||||||||||||||
| 183 | EOT | ||||||||||||||||||||||||||||||||||||||||||
| 184 | |||||||||||||||||||||||||||||||||||||||||||
| 185 | 0 | my $out = "\n\n" . $list_str . "\n\n" . $map . "\n\n"; | |||||||||||||||||||||||||||||||||||||||||
| 186 | 0 | ▶ | if ($DEBUG) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | { | ||||||||||||||||||||||||||||||||||||||||||
| 188 | 0 | my $dump1 = Dump(\@ret); | |||||||||||||||||||||||||||||||||||||||||
| 189 | 0 | my $dump2 = Dump(\%legend); | |||||||||||||||||||||||||||||||||||||||||
| 190 | 0 | $out .= "<pre>\\$map\n\n$dump1\n\n$dump2</pre>\n\n"; | |||||||||||||||||||||||||||||||||||||||||
| 191 | } | ||||||||||||||||||||||||||||||||||||||||||
| 192 | 0 | return $out; | |||||||||||||||||||||||||||||||||||||||||
| 193 | } # create_mindmap | ||||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | =head2 parse_lines | ||||||||||||||||||||||||||||||||||||||||||
| 196 | |||||||||||||||||||||||||||||||||||||||||||
| 197 | Parse the lines of a list, including recursing down the levels. | ||||||||||||||||||||||||||||||||||||||||||
| 198 | |||||||||||||||||||||||||||||||||||||||||||
| 199 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 200 | 0 | ▶ | sub parse_lines ($%) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parse_lines: not called CC=15 SCAR=54.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 203 | |||||||||||||||||||||||||||||||||||||||||||
| 204 | 0 | my $lines_ref = $args{lines}; | |||||||||||||||||||||||||||||||||||||||||
| 205 | 0 | my $terms_ref = $args{terms}; | |||||||||||||||||||||||||||||||||||||||||
| 206 | 0 | my $xref_ref = $args{xref}; | |||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | my $inverted_ref = $args{inverted}; | |||||||||||||||||||||||||||||||||||||||||
| 208 | 0 | my $prev_indent = $args{prev_indent}; | |||||||||||||||||||||||||||||||||||||||||
| 209 | 0 | my $parent = $args{parent}; | |||||||||||||||||||||||||||||||||||||||||
| 210 | |||||||||||||||||||||||||||||||||||||||||||
| 211 | 0 | ▶ | if (@{$lines_ref}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 212 | { | ||||||||||||||||||||||||||||||||||||||||||
| 213 | 0 | my @siblings = (); | |||||||||||||||||||||||||||||||||||||||||
| 214 | 0 | my $this_indent = 0; | |||||||||||||||||||||||||||||||||||||||||
| 215 | 0 | my $next_line = undef; | |||||||||||||||||||||||||||||||||||||||||
| 216 | 0 | my $next_indent = -1; | |||||||||||||||||||||||||||||||||||||||||
| 217 | |||||||||||||||||||||||||||||||||||||||||||
| 218 | 0 | ▶ | my $this_line = (@{$lines_ref} ? $lines_ref->[0] : undef); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 219 | 0 | my ($ws) = $this_line =~ /^( *)[^ ]/; | |||||||||||||||||||||||||||||||||||||||||
| 220 | 0 | $this_indent = length($ws); | |||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | 0 | ▶ | if ($this_indent < $prev_indent) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 223 | { | ||||||||||||||||||||||||||||||||||||||||||
| 224 | # higher-level list | ||||||||||||||||||||||||||||||||||||||||||
| 225 | 0 | return (); | |||||||||||||||||||||||||||||||||||||||||
| 226 | } | ||||||||||||||||||||||||||||||||||||||||||
| 227 | |||||||||||||||||||||||||||||||||||||||||||
| 228 | 0 | ▶ | do { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $next_line or $next_indent != $this_indent
MC/DC0%0/2
not $next_line or $next_indent != $this_indent
not $next_line
$next_indent != $this_indent
Truth table0%0/3
not(A) or B
A= not $next_lineB= $next_indent != $this_indent
| |||||||||||||||||||||||||||||||||||||||||||
| 229 | 0 | $this_line = shift @{$lines_ref}; | |||||||||||||||||||||||||||||||||||||||||
| 230 | |||||||||||||||||||||||||||||||||||||||||||
| 231 | # Labels are going to be in double-quotes, so replace all double-quotes with single quotes | ||||||||||||||||||||||||||||||||||||||||||
| 232 | 0 | $this_line =~ tr{"}{'}; | |||||||||||||||||||||||||||||||||||||||||
| 233 | |||||||||||||||||||||||||||||||||||||||||||
| 234 | 0 | my ($term, $rest_of_line, $number) = $self->listprefix($this_line); | |||||||||||||||||||||||||||||||||||||||||
| 235 | 0 | ▶ | while ($rest_of_line =~ /\(See ([-\s\w]+)\)/) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 236 | { | ||||||||||||||||||||||||||||||||||||||||||
| 237 | 0 | my $xref = $1; | |||||||||||||||||||||||||||||||||||||||||
| 238 | 0 | $rest_of_line =~ s/\s*\(See [-\s\w]+\)\s*//; | |||||||||||||||||||||||||||||||||||||||||
| 239 | 0 | ▶ | if (!$xref_ref->{$term}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 240 | { | ||||||||||||||||||||||||||||||||||||||||||
| 241 | 0 | $xref_ref->{$term} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 242 | } | ||||||||||||||||||||||||||||||||||||||||||
| 243 | 0 | ▶ | if (!defined $xref_ref->{$term}->{$xref}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 244 | { | ||||||||||||||||||||||||||||||||||||||||||
| 245 | 0 | $xref_ref->{$term}->{$xref} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 246 | } | ||||||||||||||||||||||||||||||||||||||||||
| 247 | 0 | $xref_ref->{$term}->{$xref}++; | |||||||||||||||||||||||||||||||||||||||||
| 248 | } | ||||||||||||||||||||||||||||||||||||||||||
| 249 | 0 | ▶ | while ($rest_of_line =~ /\(Ref ([-\s\w]+)\)/) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 250 | { | ||||||||||||||||||||||||||||||||||||||||||
| 251 | 0 | my $xref = $1; | |||||||||||||||||||||||||||||||||||||||||
| 252 | 0 | $rest_of_line =~ s/\s*\(Ref [-\s\w]+\)\s*//; | |||||||||||||||||||||||||||||||||||||||||
| 253 | 0 | ▶ | if (!$xref_ref->{$xref}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 254 | { | ||||||||||||||||||||||||||||||||||||||||||
| 255 | 0 | $xref_ref->{$xref} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 256 | } | ||||||||||||||||||||||||||||||||||||||||||
| 257 | 0 | ▶ | if (!defined $xref_ref->{$xref}->{$term}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 258 | { | ||||||||||||||||||||||||||||||||||||||||||
| 259 | 0 | $xref_ref->{$xref}->{$term} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 260 | } | ||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | $xref_ref->{$xref}->{$term}++; | |||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||
| 263 | 0 | push @siblings, {term => $term, | |||||||||||||||||||||||||||||||||||||||||
| 264 | line => $rest_of_line, | ||||||||||||||||||||||||||||||||||||||||||
| 265 | parent => $parent, | ||||||||||||||||||||||||||||||||||||||||||
| 266 | number => $number}; | ||||||||||||||||||||||||||||||||||||||||||
| 267 | 0 | $terms_ref->{$term} = { | |||||||||||||||||||||||||||||||||||||||||
| 268 | line=>$rest_of_line, | ||||||||||||||||||||||||||||||||||||||||||
| 269 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 270 | 0 | $inverted_ref->{$term} = $parent; | |||||||||||||||||||||||||||||||||||||||||
| 271 | |||||||||||||||||||||||||||||||||||||||||||
| 272 | # count the number of leading spaces | ||||||||||||||||||||||||||||||||||||||||||
| 273 | 0 | my ($ws) = $this_line =~ /^( *)[^ ]/; | |||||||||||||||||||||||||||||||||||||||||
| 274 | 0 | $this_indent = length($ws); | |||||||||||||||||||||||||||||||||||||||||
| 275 | |||||||||||||||||||||||||||||||||||||||||||
| 276 | 0 | ▶ | $next_line = (@{$lines_ref} ? $lines_ref->[0] : undef); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 277 | 0 | ▶ | if ($next_line) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 278 | { | ||||||||||||||||||||||||||||||||||||||||||
| 279 | 0 | ($ws) = $next_line =~ /^( *)[^ ]/; | |||||||||||||||||||||||||||||||||||||||||
| 280 | 0 | $next_indent = length($ws); | |||||||||||||||||||||||||||||||||||||||||
| 281 | } | ||||||||||||||||||||||||||||||||||||||||||
| 282 | } until (!$next_line | ||||||||||||||||||||||||||||||||||||||||||
| 283 | or $next_indent != $this_indent); | ||||||||||||||||||||||||||||||||||||||||||
| 284 | |||||||||||||||||||||||||||||||||||||||||||
| 285 | # okay, no more siblings | ||||||||||||||||||||||||||||||||||||||||||
| 286 | # next line must be (a) parent, (b) child, (c) empty | ||||||||||||||||||||||||||||||||||||||||||
| 287 | |||||||||||||||||||||||||||||||||||||||||||
| 288 | 0 | ▶ | if ($next_indent > $this_indent) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 289 | { | ||||||||||||||||||||||||||||||||||||||||||
| 290 | # next item is a child | ||||||||||||||||||||||||||||||||||||||||||
| 291 | my @children = $self->parse_lines(lines=>$lines_ref, | ||||||||||||||||||||||||||||||||||||||||||
| 292 | terms=>$terms_ref, | ||||||||||||||||||||||||||||||||||||||||||
| 293 | xref=>$xref_ref, | ||||||||||||||||||||||||||||||||||||||||||
| 294 | inverted=>$inverted_ref, | ||||||||||||||||||||||||||||||||||||||||||
| 295 | prev_indent=>$this_indent, | ||||||||||||||||||||||||||||||||||||||||||
| 296 | 0 | parent=>$siblings[$#siblings]->{term}); | |||||||||||||||||||||||||||||||||||||||||
| 297 | 0 | $siblings[$#siblings]->{children} = \@children; | |||||||||||||||||||||||||||||||||||||||||
| 298 | 0 | return (@siblings, $self->parse_lines(lines=>$lines_ref, | |||||||||||||||||||||||||||||||||||||||||
| 299 | terms=>$terms_ref, | ||||||||||||||||||||||||||||||||||||||||||
| 300 | xref=>$xref_ref, | ||||||||||||||||||||||||||||||||||||||||||
| 301 | inverted=>$inverted_ref, | ||||||||||||||||||||||||||||||||||||||||||
| 302 | prev_indent=>$this_indent, | ||||||||||||||||||||||||||||||||||||||||||
| 303 | parent=>$parent)); | ||||||||||||||||||||||||||||||||||||||||||
| 304 | } | ||||||||||||||||||||||||||||||||||||||||||
| 305 | else | ||||||||||||||||||||||||||||||||||||||||||
| 306 | { | ||||||||||||||||||||||||||||||||||||||||||
| 307 | # coming to the end of a sub-list | ||||||||||||||||||||||||||||||||||||||||||
| 308 | 0 | return @siblings; | |||||||||||||||||||||||||||||||||||||||||
| 309 | } | ||||||||||||||||||||||||||||||||||||||||||
| 310 | } | ||||||||||||||||||||||||||||||||||||||||||
| 311 | 0 | return (); | |||||||||||||||||||||||||||||||||||||||||
| 312 | } # parse_lines | ||||||||||||||||||||||||||||||||||||||||||
| 313 | |||||||||||||||||||||||||||||||||||||||||||
| 314 | =head2 listprefix | ||||||||||||||||||||||||||||||||||||||||||
| 315 | |||||||||||||||||||||||||||||||||||||||||||
| 316 | Process one line, doing list-prefix stuff? | ||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||
| 318 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 319 | 0 | ▶ | sub listprefix ($$) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
listprefix: not called CC=12 SCAR=50.5
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 320 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 321 | 0 | my $line = shift; | |||||||||||||||||||||||||||||||||||||||||
| 322 | |||||||||||||||||||||||||||||||||||||||||||
| 323 | 0 | my ($number, $term); | |||||||||||||||||||||||||||||||||||||||||
| 324 | 0 | my $rest_of_line = $line; | |||||||||||||||||||||||||||||||||||||||||
| 325 | 0 | my $fg = ''; | |||||||||||||||||||||||||||||||||||||||||
| 326 | 0 | my $bg = ''; | |||||||||||||||||||||||||||||||||||||||||
| 327 | |||||||||||||||||||||||||||||||||||||||||||
| 328 | 0 | my $bullets = '*'; | |||||||||||||||||||||||||||||||||||||||||
| 329 | 0 | my $bullets_ordered = ''; | |||||||||||||||||||||||||||||||||||||||||
| 330 | 0 | my $number_match = '(\d+|[^\W\d])'; | |||||||||||||||||||||||||||||||||||||||||
| 331 | 0 | ▶ | if ($bullets_ordered) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 332 | { | ||||||||||||||||||||||||||||||||||||||||||
| 333 | 0 | $number_match = '(\d+|[[:alpha:]]|[' . "${bullets_ordered}])"; | |||||||||||||||||||||||||||||||||||||||||
| 334 | } | ||||||||||||||||||||||||||||||||||||||||||
| 335 | 0 | ▶ | return ('', $rest_of_line, 0) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$line =~ /^\s*[$bullets]\s+\S/u or $line =~ /^\s*${number_match}[\.\)\]:]\s+\S/u
MC/DC0%0/2
$line =~ /^\s*[$bullets]\s+\S/u or $line =~ /^\s*${number_match}[\.\)\]:]\s+\S/u
$line =~ /^\s*[$bullets]\s+\S/u
$line =~ /^\s*${number_match}[\.\)\]:]\s+\S/u
Truth table0%0/3
A or B
A= $line =~ /^\s*[$bullets]\s+\S/uB= $line =~ /^\s*${number_match}[\.\)\]:]\s+\S/u
| |||||||||||||||||||||||||||||||||||||||||||
| 336 | if ( !($line =~ /^\s*[${bullets}]\s+\S/) | ||||||||||||||||||||||||||||||||||||||||||
| 337 | && !($line =~ /^\s*${number_match}[\.\)\]:]\s+\S/)); | ||||||||||||||||||||||||||||||||||||||||||
| 338 | |||||||||||||||||||||||||||||||||||||||||||
| 339 | 0 | ▶ | if ($line =~ /^\s*${number_match}[\.\)\]:]\s+(\S.*)/) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 340 | { | ||||||||||||||||||||||||||||||||||||||||||
| 341 | 0 | $number = $1; | |||||||||||||||||||||||||||||||||||||||||
| 342 | 0 | $rest_of_line = $2; | |||||||||||||||||||||||||||||||||||||||||
| 343 | } | ||||||||||||||||||||||||||||||||||||||||||
| 344 | 0 | ▶ | $number = 0 unless defined($number); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 345 | 0 | ▶ | if ( $bullets_ordered | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$bullets_ordered and $number =~ /[$bullets_ordered]/u
MC/DC0%0/2
$bullets_ordered and $number =~ /[$bullets_ordered]/u
$bullets_ordered
$number =~ /[$bullets_ordered]/u
Truth table0%0/3
A and B
A= $bullets_orderedB= $number =~ /[$bullets_ordered]/u
| |||||||||||||||||||||||||||||||||||||||||||
| 346 | && $number =~ /[${bullets_ordered}]/) | ||||||||||||||||||||||||||||||||||||||||||
| 347 | { | ||||||||||||||||||||||||||||||||||||||||||
| 348 | 0 | $number = 1; | |||||||||||||||||||||||||||||||||||||||||
| 349 | } | ||||||||||||||||||||||||||||||||||||||||||
| 350 | |||||||||||||||||||||||||||||||||||||||||||
| 351 | 0 | ▶ | if (!$number) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 352 | { | ||||||||||||||||||||||||||||||||||||||||||
| 353 | 0 | ▶ | if ($line =~ /^(\s*[${bullets}].)\s*(.*)/) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 354 | { | ||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | $rest_of_line = $2; | |||||||||||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||||||||||
| 358 | 0 | my $term_match = '(\w\w+)'; | |||||||||||||||||||||||||||||||||||||||||
| 359 | 0 | ▶ | if (!$term) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 360 | { | ||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | ($term) = $rest_of_line =~ /^\s*${term_match}:/; | |||||||||||||||||||||||||||||||||||||||||
| 362 | 0 | $rest_of_line =~ s/^\s*${term_match}:\s*//; | |||||||||||||||||||||||||||||||||||||||||
| 363 | } | ||||||||||||||||||||||||||||||||||||||||||
| 364 | |||||||||||||||||||||||||||||||||||||||||||
| 365 | 0 | ▶ | if (!$term) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 366 | { | ||||||||||||||||||||||||||||||||||||||||||
| 367 | 0 | $term = $rest_of_line; | |||||||||||||||||||||||||||||||||||||||||
| 368 | } | ||||||||||||||||||||||||||||||||||||||||||
| 369 | 0 | ($term, $rest_of_line, $number, $fg, $bg); | |||||||||||||||||||||||||||||||||||||||||
| 370 | } # listprefix | ||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||
| 372 | =head2 derive_xrefs | ||||||||||||||||||||||||||||||||||||||||||
| 373 | |||||||||||||||||||||||||||||||||||||||||||
| 374 | Search for references to existing terms inside other nodes | ||||||||||||||||||||||||||||||||||||||||||
| 375 | |||||||||||||||||||||||||||||||||||||||||||
| 376 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 377 | 0 | ▶ | sub derive_xrefs ($%) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
derive_xrefs: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 378 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 379 | 0 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||
| 381 | 0 | my $terms_ref = $args{terms}; | |||||||||||||||||||||||||||||||||||||||||
| 382 | 0 | my $inverted_ref = $args{inverted}; | |||||||||||||||||||||||||||||||||||||||||
| 383 | |||||||||||||||||||||||||||||||||||||||||||
| 384 | 0 | my %derived = (); | |||||||||||||||||||||||||||||||||||||||||
| 385 | |||||||||||||||||||||||||||||||||||||||||||
| 386 | # search for references to existing terms | ||||||||||||||||||||||||||||||||||||||||||
| 387 | # inside other nodes | ||||||||||||||||||||||||||||||||||||||||||
| 388 | # but don't link a child to a parent | ||||||||||||||||||||||||||||||||||||||||||
| 389 | 0 | foreach my $term (sort keys %{$terms_ref}) | |||||||||||||||||||||||||||||||||||||||||
| 390 | { | ||||||||||||||||||||||||||||||||||||||||||
| 391 | 0 | foreach my $term2 (sort keys %{$terms_ref}) | |||||||||||||||||||||||||||||||||||||||||
| 392 | { | ||||||||||||||||||||||||||||||||||||||||||
| 393 | 0 | ▶ | if ($term2 ne $term) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 394 | { | ||||||||||||||||||||||||||||||||||||||||||
| 395 | 0 | my $line = $terms_ref->{$term2}->{line}; | |||||||||||||||||||||||||||||||||||||||||
| 396 | 0 | ▶ | if ($line =~ /\b$term\b/i) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 397 | { | ||||||||||||||||||||||||||||||||||||||||||
| 398 | 0 | ▶ | if ($inverted_ref->{$term2} ne $term) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 399 | { | ||||||||||||||||||||||||||||||||||||||||||
| 400 | 0 | ▶ | if (!$derived{$term2}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 401 | { | ||||||||||||||||||||||||||||||||||||||||||
| 402 | 0 | $derived{$term2} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 403 | } | ||||||||||||||||||||||||||||||||||||||||||
| 404 | 0 | ▶ | if (!defined $derived{$term2}->{$term}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 405 | { | ||||||||||||||||||||||||||||||||||||||||||
| 406 | 0 | $derived{$term2}->{$term} = 0; | |||||||||||||||||||||||||||||||||||||||||
| 407 | } | ||||||||||||||||||||||||||||||||||||||||||
| 408 | 0 | $derived{$term2}->{$term}++; | |||||||||||||||||||||||||||||||||||||||||
| 409 | } | ||||||||||||||||||||||||||||||||||||||||||
| 410 | } | ||||||||||||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||||||||||||
| 412 | } | ||||||||||||||||||||||||||||||||||||||||||
| 413 | } | ||||||||||||||||||||||||||||||||||||||||||
| 414 | |||||||||||||||||||||||||||||||||||||||||||
| 415 | 0 | return %derived; | |||||||||||||||||||||||||||||||||||||||||
| 416 | } # derive_xrefs | ||||||||||||||||||||||||||||||||||||||||||
| 417 | |||||||||||||||||||||||||||||||||||||||||||
| 418 | =head2 extract_legend | ||||||||||||||||||||||||||||||||||||||||||
| 419 | |||||||||||||||||||||||||||||||||||||||||||
| 420 | Extract the legend information. | ||||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||
| 422 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 423 | 0 | ▶ | sub extract_legend ($%) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
extract_legend: not called CC=8 SCAR=42.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 424 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 425 | 0 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||
| 427 | 0 | my $list_ref = $args{list}; | |||||||||||||||||||||||||||||||||||||||||
| 428 | 0 | my $terms_ref = $args{terms}; | |||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||
| 430 | # If there is a top-level item which is a map-legend | ||||||||||||||||||||||||||||||||||||||||||
| 431 | # it will tell us what colours to put for matching nodes | ||||||||||||||||||||||||||||||||||||||||||
| 432 | |||||||||||||||||||||||||||||||||||||||||||
| 433 | 0 | my %legend = (); | |||||||||||||||||||||||||||||||||||||||||
| 434 | 0 | my $legend = $args{legend}; | |||||||||||||||||||||||||||||||||||||||||
| 435 | 0 | my $found = 0; | |||||||||||||||||||||||||||||||||||||||||
| 436 | 0 | ▶ | for (my $i = 0; !$found and $i < @{$list_ref}; $i++) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
not $found and $i < @{$list_ref;}
MC/DC0%0/2
not $found and $i < @{$list_ref;}
not $found
$i < @{$list_ref;}
Truth table0%0/3
not(A) and B
A= not $foundB= $i < @{$list_ref;}
| |||||||||||||||||||||||||||||||||||||||||||
| 437 | { | ||||||||||||||||||||||||||||||||||||||||||
| 438 | 0 | my $item = $list_ref->[$i]; | |||||||||||||||||||||||||||||||||||||||||
| 439 | 0 | my $term = $item->{term}; | |||||||||||||||||||||||||||||||||||||||||
| 440 | 0 | my $line = $item->{line}; | |||||||||||||||||||||||||||||||||||||||||
| 441 | 0 | ▶ | if ($term eq $legend) # this is the legend | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 442 | { | ||||||||||||||||||||||||||||||||||||||||||
| 443 | 0 | $found = 1; | |||||||||||||||||||||||||||||||||||||||||
| 444 | # The children of the legend contain terms and colours | ||||||||||||||||||||||||||||||||||||||||||
| 445 | 0 | ▶ | if ($item->{children}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 446 | { | ||||||||||||||||||||||||||||||||||||||||||
| 447 | 0 | ▶ | for (my $j = 0; $j < @{$item->{children}}; $j++) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 448 | { | ||||||||||||||||||||||||||||||||||||||||||
| 449 | 0 | my $child = $item->{children}->[$j]; | |||||||||||||||||||||||||||||||||||||||||
| 450 | 0 | my $ch_term = $child->{term}; | |||||||||||||||||||||||||||||||||||||||||
| 451 | 0 | my $ch_line = $child->{line}; | |||||||||||||||||||||||||||||||||||||||||
| 452 | 0 | my $fg = ''; | |||||||||||||||||||||||||||||||||||||||||
| 453 | 0 | my $bg = ''; | |||||||||||||||||||||||||||||||||||||||||
| 454 | |||||||||||||||||||||||||||||||||||||||||||
| 455 | 0 | ▶ | if ($ch_line =~ /\b(\w\w+)\/(\w\w+)\b/) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 456 | { | ||||||||||||||||||||||||||||||||||||||||||
| 457 | 0 | $fg = $1; | |||||||||||||||||||||||||||||||||||||||||
| 458 | 0 | $bg = $2; | |||||||||||||||||||||||||||||||||||||||||
| 459 | } | ||||||||||||||||||||||||||||||||||||||||||
| 460 | elsif ($ch_line =~ /\b(\w\w+)\b/) | ||||||||||||||||||||||||||||||||||||||||||
| 461 | { | ||||||||||||||||||||||||||||||||||||||||||
| 462 | 0 | $fg = $1; | |||||||||||||||||||||||||||||||||||||||||
| 463 | } | ||||||||||||||||||||||||||||||||||||||||||
| 464 | 0 | $legend{$ch_term} = { | |||||||||||||||||||||||||||||||||||||||||
| 465 | fg => $fg, | ||||||||||||||||||||||||||||||||||||||||||
| 466 | bg => $bg | ||||||||||||||||||||||||||||||||||||||||||
| 467 | }; | ||||||||||||||||||||||||||||||||||||||||||
| 468 | 0 | delete $terms_ref->{$ch_term}; | |||||||||||||||||||||||||||||||||||||||||
| 469 | } | ||||||||||||||||||||||||||||||||||||||||||
| 470 | # now we need to remove the legend from the map | ||||||||||||||||||||||||||||||||||||||||||
| 471 | 0 | delete $list_ref->[$i]; | |||||||||||||||||||||||||||||||||||||||||
| 472 | } | ||||||||||||||||||||||||||||||||||||||||||
| 473 | } | ||||||||||||||||||||||||||||||||||||||||||
| 474 | } | ||||||||||||||||||||||||||||||||||||||||||
| 475 | 0 | return %legend; | |||||||||||||||||||||||||||||||||||||||||
| 476 | } # extract_legend | ||||||||||||||||||||||||||||||||||||||||||
| 477 | |||||||||||||||||||||||||||||||||||||||||||
| 478 | =head2 apply_legend | ||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||
| 480 | Apply the legend information. | ||||||||||||||||||||||||||||||||||||||||||
| 481 | |||||||||||||||||||||||||||||||||||||||||||
| 482 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 483 | 0 | ▶ | sub apply_legend ($%) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
apply_legend: not called CC=11 SCAR=48.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 484 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 485 | 0 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||
| 487 | 0 | my $terms_ref = $args{terms}; | |||||||||||||||||||||||||||||||||||||||||
| 488 | 0 | my $legend_ref = $args{legend}; | |||||||||||||||||||||||||||||||||||||||||
| 489 | 0 | my $inverted_ref = $args{inverted}; | |||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||
| 491 | # search for references to Legend terms | ||||||||||||||||||||||||||||||||||||||||||
| 492 | # inside other nodes | ||||||||||||||||||||||||||||||||||||||||||
| 493 | # and add the appropriate colours | ||||||||||||||||||||||||||||||||||||||||||
| 494 | 0 | foreach my $lterm (sort keys %{$legend_ref}) | |||||||||||||||||||||||||||||||||||||||||
| 495 | { | ||||||||||||||||||||||||||||||||||||||||||
| 496 | 0 | foreach my $term (sort keys %{$terms_ref}) | |||||||||||||||||||||||||||||||||||||||||
| 497 | { | ||||||||||||||||||||||||||||||||||||||||||
| 498 | 0 | my $line = $terms_ref->{$term}->{line}; | |||||||||||||||||||||||||||||||||||||||||
| 499 | 0 | ▶ | if (($line =~ /\b${lterm}s?\b/i) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/3
$line =~ /\b${lterm}s?\b/iu or $term =~ /^${lterm}s?$/iu
MC/DC0%0/2
$line =~ /\b${lterm}s?\b/iu or $term =~ /^${lterm}s?$/iu
$line =~ /\b${lterm}s?\b/iu
$term =~ /^${lterm}s?$/iu
Truth table0%0/3
A or B
A= $line =~ /\b${lterm}s?\b/iuB= $term =~ /^${lterm}s?$/iu
| |||||||||||||||||||||||||||||||||||||||||||
| 500 | or ($term =~ /^${lterm}s?$/i) | ||||||||||||||||||||||||||||||||||||||||||
| 501 | ) | ||||||||||||||||||||||||||||||||||||||||||
| 502 | { | ||||||||||||||||||||||||||||||||||||||||||
| 503 | 0 | $terms_ref->{$term}->{fg} = $legend_ref->{$lterm}->{fg}; | |||||||||||||||||||||||||||||||||||||||||
| 504 | 0 | $terms_ref->{$term}->{bg} = $legend_ref->{$lterm}->{bg}; | |||||||||||||||||||||||||||||||||||||||||
| 505 | } | ||||||||||||||||||||||||||||||||||||||||||
| 506 | } | ||||||||||||||||||||||||||||||||||||||||||
| 507 | } | ||||||||||||||||||||||||||||||||||||||||||
| 508 | |||||||||||||||||||||||||||||||||||||||||||
| 509 | # make terms have the colours of their parent | ||||||||||||||||||||||||||||||||||||||||||
| 510 | # if they don't already have a colour | ||||||||||||||||||||||||||||||||||||||||||
| 511 | 0 | foreach my $term (sort keys %{$terms_ref}) | |||||||||||||||||||||||||||||||||||||||||
| 512 | { | ||||||||||||||||||||||||||||||||||||||||||
| 513 | 0 | my $iterm = $inverted_ref->{$term}; | |||||||||||||||||||||||||||||||||||||||||
| 514 | 0 | ▶ | if ($iterm and $term and !$terms_ref->{$term}->{fg}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition0%0/6
$iterm and $term and not $terms_ref->{$term}{"fg"}
$iterm and $term
MC/DC0%0/3
$iterm and $term and not $terms_ref->{$term}{"fg"}
$iterm
$term
not $terms_ref->{$term}{"fg"}
Truth table0%0/4
A and B and not(C)
A= $itermB= $termC= not $terms_ref->{$term}{"fg"}
| |||||||||||||||||||||||||||||||||||||||||||
| 515 | { | ||||||||||||||||||||||||||||||||||||||||||
| 516 | 0 | ▶ | if ($terms_ref->{$iterm}->{fg}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 517 | { | ||||||||||||||||||||||||||||||||||||||||||
| 518 | 0 | $terms_ref->{$term}->{fg} = $terms_ref->{$iterm}->{fg}; | |||||||||||||||||||||||||||||||||||||||||
| 519 | } | ||||||||||||||||||||||||||||||||||||||||||
| 520 | 0 | ▶ | if ($terms_ref->{$iterm}->{bg}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 521 | { | ||||||||||||||||||||||||||||||||||||||||||
| 522 | 0 | $terms_ref->{$term}->{bg} = $terms_ref->{$iterm}->{bg}; | |||||||||||||||||||||||||||||||||||||||||
| 523 | } | ||||||||||||||||||||||||||||||||||||||||||
| 524 | } | ||||||||||||||||||||||||||||||||||||||||||
| 525 | } | ||||||||||||||||||||||||||||||||||||||||||
| 526 | |||||||||||||||||||||||||||||||||||||||||||
| 527 | } # apply_legend | ||||||||||||||||||||||||||||||||||||||||||
| 528 | |||||||||||||||||||||||||||||||||||||||||||
| 529 | =head2 start_map | ||||||||||||||||||||||||||||||||||||||||||
| 530 | |||||||||||||||||||||||||||||||||||||||||||
| 531 | Start the map. | ||||||||||||||||||||||||||||||||||||||||||
| 532 | |||||||||||||||||||||||||||||||||||||||||||
| 533 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 534 | 0 | ▶ | sub start_map ($%) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
start_map: not called CC=6 SCAR=37.4
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 535 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 536 | 0 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||||||||||||
| 538 | 0 | my $terms_ref = $args{terms}; | |||||||||||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||||||||||||
| 540 | 0 | my $map = ''; | |||||||||||||||||||||||||||||||||||||||||
| 541 | # first do all the terms + labels | ||||||||||||||||||||||||||||||||||||||||||
| 542 | 0 | local $Text::Wrap::columns = 20; | |||||||||||||||||||||||||||||||||||||||||
| 543 | 0 | foreach my $term (sort keys %{$terms_ref}) | |||||||||||||||||||||||||||||||||||||||||
| 544 | { | ||||||||||||||||||||||||||||||||||||||||||
| 545 | 0 | my $fg = $terms_ref->{$term}->{fg}; | |||||||||||||||||||||||||||||||||||||||||
| 546 | 0 | my $bg = $terms_ref->{$term}->{bg}; | |||||||||||||||||||||||||||||||||||||||||
| 547 | 0 | my @nodeargs = (); | |||||||||||||||||||||||||||||||||||||||||
| 548 | 0 | ▶ | push @nodeargs, "fontcolor = $fg" if $fg; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 549 | 0 | ▶ | push @nodeargs, "fillcolor = $bg, style = filled" if $bg; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 550 | 0 | my $line = $terms_ref->{$term}->{line}; | |||||||||||||||||||||||||||||||||||||||||
| 551 | 0 | ▶ | if ($term ne $line) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 552 | { | ||||||||||||||||||||||||||||||||||||||||||
| 553 | 0 | my $label = wrap('', '', $line); | |||||||||||||||||||||||||||||||||||||||||
| 554 | 0 | $label =~ s/\n/\\n/sg; # replace newlines with newline escapes | |||||||||||||||||||||||||||||||||||||||||
| 555 | 0 | push @nodeargs, 'label="' . $label . '"'; | |||||||||||||||||||||||||||||||||||||||||
| 556 | } | ||||||||||||||||||||||||||||||||||||||||||
| 557 | 0 | ▶ | if (@nodeargs > 0) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 558 | { | ||||||||||||||||||||||||||||||||||||||||||
| 559 | 0 | $map .= '"' . $term . '" [ ' . join(',', @nodeargs) . " ];\n"; | |||||||||||||||||||||||||||||||||||||||||
| 560 | } | ||||||||||||||||||||||||||||||||||||||||||
| 561 | } | ||||||||||||||||||||||||||||||||||||||||||
| 562 | 0 | return $map; | |||||||||||||||||||||||||||||||||||||||||
| 563 | } # start_map | ||||||||||||||||||||||||||||||||||||||||||
| 564 | |||||||||||||||||||||||||||||||||||||||||||
| 565 | =head2 build_xrefs | ||||||||||||||||||||||||||||||||||||||||||
| 566 | |||||||||||||||||||||||||||||||||||||||||||
| 567 | Build the xrefs. | ||||||||||||||||||||||||||||||||||||||||||
| 568 | |||||||||||||||||||||||||||||||||||||||||||
| 569 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 570 | 0 | ▶ | sub build_xrefs ($%) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
build_xrefs: not called CC=3 SCAR=24.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 571 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 572 | 0 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 573 | |||||||||||||||||||||||||||||||||||||||||||
| 574 | 0 | my $xref_ref = $args{xref}; | |||||||||||||||||||||||||||||||||||||||||
| 575 | 0 | my $xref_edge_colour = $args{edge_colour}; | |||||||||||||||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||||||||||||||||
| 577 | 0 | my $map = ''; | |||||||||||||||||||||||||||||||||||||||||
| 578 | # do the cross-references | ||||||||||||||||||||||||||||||||||||||||||
| 579 | 0 | foreach my $term (sort keys %{$xref_ref}) | |||||||||||||||||||||||||||||||||||||||||
| 580 | { | ||||||||||||||||||||||||||||||||||||||||||
| 581 | 0 | foreach my $xref (sort keys %{$xref_ref->{$term}}) | |||||||||||||||||||||||||||||||||||||||||
| 582 | { | ||||||||||||||||||||||||||||||||||||||||||
| 583 | 0 | $map .= '"' . $term . '" -> "' . $xref . '"' . " [ color=$xref_edge_colour ];\n"; | |||||||||||||||||||||||||||||||||||||||||
| 584 | } | ||||||||||||||||||||||||||||||||||||||||||
| 585 | } | ||||||||||||||||||||||||||||||||||||||||||
| 586 | 0 | return $map; | |||||||||||||||||||||||||||||||||||||||||
| 587 | } # build_xrefs | ||||||||||||||||||||||||||||||||||||||||||
| 588 | |||||||||||||||||||||||||||||||||||||||||||
| 589 | =head2 build_map_levels | ||||||||||||||||||||||||||||||||||||||||||
| 590 | |||||||||||||||||||||||||||||||||||||||||||
| 591 | Build the map levels. | ||||||||||||||||||||||||||||||||||||||||||
| 592 | |||||||||||||||||||||||||||||||||||||||||||
| 593 | =cut | ||||||||||||||||||||||||||||||||||||||||||
| 594 | 0 | ▶ | sub build_map_levels ($%) { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
build_map_levels: not called CC=11 SCAR=48.8
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 595 | 0 | my $self = shift; | |||||||||||||||||||||||||||||||||||||||||
| 596 | 0 | my %args = @_; | |||||||||||||||||||||||||||||||||||||||||
| 597 | |||||||||||||||||||||||||||||||||||||||||||
| 598 | 0 | my $list_ref = $args{list}; | |||||||||||||||||||||||||||||||||||||||||
| 599 | 0 | my $level = $args{leve}; | |||||||||||||||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||||||||||||||||
| 601 | 0 | my $map = ''; | |||||||||||||||||||||||||||||||||||||||||
| 602 | |||||||||||||||||||||||||||||||||||||||||||
| 603 | 0 | my $ordered_colour = 'red3'; | |||||||||||||||||||||||||||||||||||||||||
| 604 | 0 | my $top = $args{top}; | |||||||||||||||||||||||||||||||||||||||||
| 605 | 0 | ▶ | for (my $i = 0; $i < @{$list_ref}; $i++) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 606 | { | ||||||||||||||||||||||||||||||||||||||||||
| 607 | 0 | my $item = $list_ref->[$i]; | |||||||||||||||||||||||||||||||||||||||||
| 608 | 0 | my $term = $item->{term}; | |||||||||||||||||||||||||||||||||||||||||
| 609 | 0 | my $line = $item->{line}; | |||||||||||||||||||||||||||||||||||||||||
| 610 | |||||||||||||||||||||||||||||||||||||||||||
| 611 | 0 | ▶ | next if !$term; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 612 | |||||||||||||||||||||||||||||||||||||||||||
| 613 | 0 | ▶ | if ($level == 0) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 614 | { | ||||||||||||||||||||||||||||||||||||||||||
| 615 | 0 | ▶ | if ($top) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 616 | { | ||||||||||||||||||||||||||||||||||||||||||
| 617 | 0 | $map .= '"' . $top . '"' . " [ fontsize = 14 ];\n"; | |||||||||||||||||||||||||||||||||||||||||
| 618 | } | ||||||||||||||||||||||||||||||||||||||||||
| 619 | 0 | $map .= '"' . $term . '"' . " [ fontsize = 12 ];\n"; | |||||||||||||||||||||||||||||||||||||||||
| 620 | 0 | ▶ | if ($top) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 621 | { | ||||||||||||||||||||||||||||||||||||||||||
| 622 | 0 | $map .= '"' . $top . '" -> "' . $term . '"' . ";\n"; | |||||||||||||||||||||||||||||||||||||||||
| 623 | } | ||||||||||||||||||||||||||||||||||||||||||
| 624 | } | ||||||||||||||||||||||||||||||||||||||||||
| 625 | # do child-items | ||||||||||||||||||||||||||||||||||||||||||
| 626 | 0 | ▶ | if ($item->{children}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 627 | { | ||||||||||||||||||||||||||||||||||||||||||
| 628 | # Link to the children | ||||||||||||||||||||||||||||||||||||||||||
| 629 | # If the children are an ordered list, | ||||||||||||||||||||||||||||||||||||||||||
| 630 | # link to the first and link them to each other | ||||||||||||||||||||||||||||||||||||||||||
| 631 | 0 | my $firstchild = $item->{children}->[0]; | |||||||||||||||||||||||||||||||||||||||||
| 632 | 0 | ▶ | if ($firstchild->{number}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 633 | { | ||||||||||||||||||||||||||||||||||||||||||
| 634 | 0 | $map .= '"' . $term . '" -> "' . $firstchild->{term} . '"' . ";\n"; | |||||||||||||||||||||||||||||||||||||||||
| 635 | } | ||||||||||||||||||||||||||||||||||||||||||
| 636 | 0 | ▶ | for (my $j = 0; $j < @{$item->{children}}; $j++) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 637 | { | ||||||||||||||||||||||||||||||||||||||||||
| 638 | 0 | my $child = $item->{children}->[$j]; | |||||||||||||||||||||||||||||||||||||||||
| 639 | 0 | ▶ | if ($firstchild->{number}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 640 | { | ||||||||||||||||||||||||||||||||||||||||||
| 641 | 0 | $map .= '"' . $child->{term} . '"' . " [ shape = box ];\n"; | |||||||||||||||||||||||||||||||||||||||||
| 642 | 0 | ▶ | if ($j + 1 < @{$item->{children}}) | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 643 | { | ||||||||||||||||||||||||||||||||||||||||||
| 644 | 0 | $map .= '"' . $child->{term} . '" -> "' . $item->{children}->[$j+1]->{term} . '"' . " [ color = $ordered_colour ];\n"; | |||||||||||||||||||||||||||||||||||||||||
| 645 | } | ||||||||||||||||||||||||||||||||||||||||||
| 646 | } | ||||||||||||||||||||||||||||||||||||||||||
| 647 | else | ||||||||||||||||||||||||||||||||||||||||||
| 648 | { | ||||||||||||||||||||||||||||||||||||||||||
| 649 | 0 | $map .= '"' . $term . '" -> "' . $child->{term} . '"' . ";\n"; | |||||||||||||||||||||||||||||||||||||||||
| 650 | } | ||||||||||||||||||||||||||||||||||||||||||
| 651 | } | ||||||||||||||||||||||||||||||||||||||||||
| 652 | 0 | $map .= build_map_levels(%args, list=>$item->{children}, level=>$level + 1); | |||||||||||||||||||||||||||||||||||||||||
| 653 | } | ||||||||||||||||||||||||||||||||||||||||||
| 654 | } | ||||||||||||||||||||||||||||||||||||||||||
| 655 | |||||||||||||||||||||||||||||||||||||||||||
| 656 | 0 | return $map; | |||||||||||||||||||||||||||||||||||||||||
| 657 | } # build_map_levels | ||||||||||||||||||||||||||||||||||||||||||
| 658 | |||||||||||||||||||||||||||||||||||||||||||
| 659 | 1 | 1; | |||||||||||||||||||||||||||||||||||||||||