| 1 | package App::Followme::BaseData; | ||||||||||||||||||||||||||||||||||||||||||
| 2 | |||||||||||||||||||||||||||||||||||||||||||
| 3 | 21 | ▶ | use 5.008005; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 4 | 21 | ▶ | use strict; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 5 | 21 | ▶ | use warnings; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 6 | 21 | ▶ | use integer; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 7 | 21 | ▶ | use lib '../..'; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 8 | |||||||||||||||||||||||||||||||||||||||||||
| 9 | 21 | ▶ | use base qw(App::Followme::ConfiguredObject); | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 10 | 21 | ▶ | use App::Followme::FIO; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 11 | |||||||||||||||||||||||||||||||||||||||||||
| 12 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 13 | # Default values of parameters | ||||||||||||||||||||||||||||||||||||||||||
| 14 | |||||||||||||||||||||||||||||||||||||||||||
| 15 | 372 | ▶ | sub parameters { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
parameters: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 16 | 372 | my ($pkg) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 17 | |||||||||||||||||||||||||||||||||||||||||||
| 18 | return ( | ||||||||||||||||||||||||||||||||||||||||||
| 19 | 372 | list_length => 5, | |||||||||||||||||||||||||||||||||||||||||
| 20 | target_prefix => 'target', | ||||||||||||||||||||||||||||||||||||||||||
| 21 | ); | ||||||||||||||||||||||||||||||||||||||||||
| 22 | } | ||||||||||||||||||||||||||||||||||||||||||
| 23 | |||||||||||||||||||||||||||||||||||||||||||
| 24 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 25 | # Build a new variable value given its name and context | ||||||||||||||||||||||||||||||||||||||||||
| 26 | |||||||||||||||||||||||||||||||||||||||||||
| 27 | 493 | ▶ | sub build { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
build: called CC=9 SCAR=22.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 28 | 493 | my ($self, $variable_name, $item, $loop) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 29 | |||||||||||||||||||||||||||||||||||||||||||
| 30 | # Extract the sigil from the variable name, if present | ||||||||||||||||||||||||||||||||||||||||||
| 31 | 493 | my ($sigil, $name) = $self->split_name($variable_name); | |||||||||||||||||||||||||||||||||||||||||
| 32 | |||||||||||||||||||||||||||||||||||||||||||
| 33 | # Extract the sort field from the variable name | ||||||||||||||||||||||||||||||||||||||||||
| 34 | 493 | my ($data_field, $sort_field, $sort_reverse); | |||||||||||||||||||||||||||||||||||||||||
| 35 | 493 | ($data_field, $sort_field) = split('_by_', $name); | |||||||||||||||||||||||||||||||||||||||||
| 36 | 493 | ▶ | if (defined $sort_field) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 37 | 56 | ▶ | if ($sort_field =~ s/_reversed$//) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 38 | 20 | $sort_reverse = 1; | |||||||||||||||||||||||||||||||||||||||||
| 39 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 40 | 36 | $sort_reverse = 0; | |||||||||||||||||||||||||||||||||||||||||
| 41 | } | ||||||||||||||||||||||||||||||||||||||||||
| 42 | } | ||||||||||||||||||||||||||||||||||||||||||
| 43 | |||||||||||||||||||||||||||||||||||||||||||
| 44 | 493 | my %cache = (); | |||||||||||||||||||||||||||||||||||||||||
| 45 | 493 | ▶ | if ($sigil eq '$') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 46 | 265 | ▶ | if (defined $item && | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%6/6
defined $item and !$self->{"cache"}{"item"} || $self->{"cache"}{"item"} ne $item
not $self->{"cache"}{"item"} or $self->{"cache"}{"item"} ne $item
MC/DC100%3/3
defined $item and !$self->{"cache"}{"item"} || $self->{"cache"}{"item"} ne $item
defined $item
not $self->{"cache"}{"item"}
$self->{"cache"}{"item"} ne $item
Truth table100%4/4
A and not(B) or C
A= defined $itemB= not $self->{"cache"}{"item"}C= $self->{"cache"}{"item"} ne $item
| |||||||||||||||||||||||||||||||||||||||||||
| 47 | (! $self->{cache}{item} || $self->{cache}{item} ne $item)) { | ||||||||||||||||||||||||||||||||||||||||||
| 48 | # Clear cache when argument to build changes | ||||||||||||||||||||||||||||||||||||||||||
| 49 | 66 | %cache = (item => $item); | |||||||||||||||||||||||||||||||||||||||||
| 50 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 51 | 199 | %cache = %{$self->{cache}}; | |||||||||||||||||||||||||||||||||||||||||
| 52 | } | ||||||||||||||||||||||||||||||||||||||||||
| 53 | } | ||||||||||||||||||||||||||||||||||||||||||
| 54 | |||||||||||||||||||||||||||||||||||||||||||
| 55 | # Build the value associated with a name if it is not in the cache | ||||||||||||||||||||||||||||||||||||||||||
| 56 | 493 | ▶ | unless (exists $cache{$data_field}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 57 | 411 | my %data = $self->fetch_data($data_field, $item, $loop); | |||||||||||||||||||||||||||||||||||||||||
| 58 | |||||||||||||||||||||||||||||||||||||||||||
| 59 | 411 | my $sorted_order = 0; | |||||||||||||||||||||||||||||||||||||||||
| 60 | 411 | my $sorted_data = $self->sort(\%data, $sort_field, $sort_reverse); | |||||||||||||||||||||||||||||||||||||||||
| 61 | 411 | $sorted_data = $self->format($sorted_order, $sorted_data); | |||||||||||||||||||||||||||||||||||||||||
| 62 | |||||||||||||||||||||||||||||||||||||||||||
| 63 | 411 | %cache = (%cache, %$sorted_data); | |||||||||||||||||||||||||||||||||||||||||
| 64 | } | ||||||||||||||||||||||||||||||||||||||||||
| 65 | |||||||||||||||||||||||||||||||||||||||||||
| 66 | # Check the value for agreement with the sigil and return reference | ||||||||||||||||||||||||||||||||||||||||||
| 67 | 493 | my $ref_value = $self->ref_value($cache{$data_field}, $sigil, $data_field); | |||||||||||||||||||||||||||||||||||||||||
| 68 | 493 | ▶ | $self->{cache} = \%cache if $sigil eq '$'; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 69 | 493 | return $ref_value; | |||||||||||||||||||||||||||||||||||||||||
| 70 | } | ||||||||||||||||||||||||||||||||||||||||||
| 71 | |||||||||||||||||||||||||||||||||||||||||||
| 72 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 73 | # Coerce the data to a hash | ||||||||||||||||||||||||||||||||||||||||||
| 74 | |||||||||||||||||||||||||||||||||||||||||||
| 75 | 707 | ▶ | sub coerce_data { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
coerce_data: called CC=4 SCAR=14.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 76 | 707 | my ($self, $name, @data) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 77 | |||||||||||||||||||||||||||||||||||||||||||
| 78 | 707 | my %data; | |||||||||||||||||||||||||||||||||||||||||
| 79 | 707 | ▶ | if (@data == 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 80 | 157 | %data = (); | |||||||||||||||||||||||||||||||||||||||||
| 81 | |||||||||||||||||||||||||||||||||||||||||||
| 82 | } elsif (@data == 1) { | ||||||||||||||||||||||||||||||||||||||||||
| 83 | 549 | %data = ($name => $data[0]); | |||||||||||||||||||||||||||||||||||||||||
| 84 | |||||||||||||||||||||||||||||||||||||||||||
| 85 | } elsif (@data % 2 == 0) { | ||||||||||||||||||||||||||||||||||||||||||
| 86 | 1 | %data = @data; | |||||||||||||||||||||||||||||||||||||||||
| 87 | |||||||||||||||||||||||||||||||||||||||||||
| 88 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 89 | 0 | my $pkg = ref $self; | |||||||||||||||||||||||||||||||||||||||||
| 90 | 0 | die "$name does not return a hash\n"; | |||||||||||||||||||||||||||||||||||||||||
| 91 | } | ||||||||||||||||||||||||||||||||||||||||||
| 92 | |||||||||||||||||||||||||||||||||||||||||||
| 93 | 707 | return %data; | |||||||||||||||||||||||||||||||||||||||||
| 94 | } | ||||||||||||||||||||||||||||||||||||||||||
| 95 | |||||||||||||||||||||||||||||||||||||||||||
| 96 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 97 | # Fetch the data for building a variable's value | ||||||||||||||||||||||||||||||||||||||||||
| 98 | |||||||||||||||||||||||||||||||||||||||||||
| 99 | 29 | ▶ | sub fetch_data { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
fetch_data: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 100 | 29 | my ($self, $name, $item, $loop) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 101 | |||||||||||||||||||||||||||||||||||||||||||
| 102 | 29 | my %data = $self->gather_data('get', $name, $item, $loop); | |||||||||||||||||||||||||||||||||||||||||
| 103 | 29 | return %data; | |||||||||||||||||||||||||||||||||||||||||
| 104 | } | ||||||||||||||||||||||||||||||||||||||||||
| 105 | |||||||||||||||||||||||||||||||||||||||||||
| 106 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 107 | # Choose the file comparison routine that matches the configuration | ||||||||||||||||||||||||||||||||||||||||||
| 108 | |||||||||||||||||||||||||||||||||||||||||||
| 109 | 159 | ▶ | sub file_comparer { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
file_comparer: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 110 | 159 | my ($self, $sort_reverse) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 111 | |||||||||||||||||||||||||||||||||||||||||||
| 112 | 159 | my $comparer; | |||||||||||||||||||||||||||||||||||||||||
| 113 | 159 | ▶ | if ($sort_reverse) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 114 | 54 | ▶ | $comparer = sub ($$) {$_[1]->[0] cmp $_[0]->[0]}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 115 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 116 | 105 | ▶ | $comparer = sub ($$) {$_[0]->[0] cmp $_[1]->[0]}; | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
__ANON__: called CC=1 SCAR=0.0
| |||||||||||||||||||||||||||||||||||||||||||
| 117 | } | ||||||||||||||||||||||||||||||||||||||||||
| 118 | |||||||||||||||||||||||||||||||||||||||||||
| 119 | 159 | return $comparer; | |||||||||||||||||||||||||||||||||||||||||
| 120 | } | ||||||||||||||||||||||||||||||||||||||||||
| 121 | |||||||||||||||||||||||||||||||||||||||||||
| 122 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 123 | # If there is omly a single field containing data, return its name | ||||||||||||||||||||||||||||||||||||||||||
| 124 | |||||||||||||||||||||||||||||||||||||||||||
| 125 | 412 | ▶ | sub find_data_field { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_data_field: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 126 | 412 | my ($self, $data) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 127 | |||||||||||||||||||||||||||||||||||||||||||
| 128 | 412 | my @keys = keys %$data; | |||||||||||||||||||||||||||||||||||||||||
| 129 | |||||||||||||||||||||||||||||||||||||||||||
| 130 | 412 | my $field; | |||||||||||||||||||||||||||||||||||||||||
| 131 | 412 | ▶ | if (@keys == 1 ) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 132 | 302 | my $key = $keys[0]; | |||||||||||||||||||||||||||||||||||||||||
| 133 | 302 | ▶ | if (ref $data->{$key} eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 134 | 125 | $field = $key; | |||||||||||||||||||||||||||||||||||||||||
| 135 | } | ||||||||||||||||||||||||||||||||||||||||||
| 136 | } | ||||||||||||||||||||||||||||||||||||||||||
| 137 | |||||||||||||||||||||||||||||||||||||||||||
| 138 | 412 | return $field; | |||||||||||||||||||||||||||||||||||||||||
| 139 | } | ||||||||||||||||||||||||||||||||||||||||||
| 140 | |||||||||||||||||||||||||||||||||||||||||||
| 141 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 142 | # Find the values to sort by and format them so they are in sort order | ||||||||||||||||||||||||||||||||||||||||||
| 143 | |||||||||||||||||||||||||||||||||||||||||||
| 144 | 142 | ▶ | sub find_sort_column { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_sort_column: called CC=4 SCAR=14.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 145 | 142 | my ($self, $data_column, $sort_field) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 146 | |||||||||||||||||||||||||||||||||||||||||||
| 147 | 142 | my $formatter = "format_$sort_field"; | |||||||||||||||||||||||||||||||||||||||||
| 148 | 142 | ▶ | $formatter = "format_nothing" unless $self->can($formatter); | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 149 | |||||||||||||||||||||||||||||||||||||||||||
| 150 | 142 | my @sort_column; | |||||||||||||||||||||||||||||||||||||||||
| 151 | 142 | my $sorted_order = 1; | |||||||||||||||||||||||||||||||||||||||||
| 152 | |||||||||||||||||||||||||||||||||||||||||||
| 153 | 142 | for my $data_item (@$data_column) { | |||||||||||||||||||||||||||||||||||||||||
| 154 | 218 | my %data = $self->fetch_data($sort_field, $data_item, $data_column); | |||||||||||||||||||||||||||||||||||||||||
| 155 | |||||||||||||||||||||||||||||||||||||||||||
| 156 | 218 | ▶ | if (exists $data{$sort_field}) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 157 | push(@sort_column, $self->$formatter($sorted_order, | ||||||||||||||||||||||||||||||||||||||||||
| 158 | 218 | $data{$sort_field})); | |||||||||||||||||||||||||||||||||||||||||
| 159 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 160 | 0 | warn "Sort field not found: $sort_field"; | |||||||||||||||||||||||||||||||||||||||||
| 161 | 0 | push(@sort_column, $data_item); | |||||||||||||||||||||||||||||||||||||||||
| 162 | } | ||||||||||||||||||||||||||||||||||||||||||
| 163 | |||||||||||||||||||||||||||||||||||||||||||
| 164 | } | ||||||||||||||||||||||||||||||||||||||||||
| 165 | |||||||||||||||||||||||||||||||||||||||||||
| 166 | 142 | return \@sort_column; | |||||||||||||||||||||||||||||||||||||||||
| 167 | } | ||||||||||||||||||||||||||||||||||||||||||
| 168 | |||||||||||||||||||||||||||||||||||||||||||
| 169 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 170 | # Find the target, return the target plus an offset | ||||||||||||||||||||||||||||||||||||||||||
| 171 | |||||||||||||||||||||||||||||||||||||||||||
| 172 | 30 | ▶ | sub find_target { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
find_target: called CC=7 SCAR=19.5
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 173 | 30 | my ($self, $offset, $item, $loop) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 174 | 30 | ▶ | die "Can't use \$target_* outside of for\n" unless $loop; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 175 | |||||||||||||||||||||||||||||||||||||||||||
| 176 | 30 | my $match = -999; | |||||||||||||||||||||||||||||||||||||||||
| 177 | 30 | foreach my $i (0 .. @$loop) { | |||||||||||||||||||||||||||||||||||||||||
| 178 | 60 | ▶ | if ($loop->[$i] eq $item) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 179 | 30 | $match = $i; | |||||||||||||||||||||||||||||||||||||||||
| 180 | 30 | last; | |||||||||||||||||||||||||||||||||||||||||
| 181 | } | ||||||||||||||||||||||||||||||||||||||||||
| 182 | } | ||||||||||||||||||||||||||||||||||||||||||
| 183 | |||||||||||||||||||||||||||||||||||||||||||
| 184 | 30 | my $index = $match + $offset + 1; | |||||||||||||||||||||||||||||||||||||||||
| 185 | 30 | ▶ | $index = 0 if $index < 1 || $index > @$loop; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition100%3/3
$index < 1 or $index > @$loop
MC/DC100%2/2
$index < 1 or $index > @$loop
$index < 1
$index > @$loop
Truth table100%3/3
A or B
A= $index < 1B= $index > @$loop
| |||||||||||||||||||||||||||||||||||||||||||
| 186 | 30 | ▶ | return $index ? $self->{target_prefix} . $index : ''; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 187 | } | ||||||||||||||||||||||||||||||||||||||||||
| 188 | |||||||||||||||||||||||||||||||||||||||||||
| 189 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 190 | # Apply an optional format to the data | ||||||||||||||||||||||||||||||||||||||||||
| 191 | |||||||||||||||||||||||||||||||||||||||||||
| 192 | 414 | ▶ | sub format { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
format: called CC=7 SCAR=21.2
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 193 | 414 | my ($self, $sorted_order, $sorted_data) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 194 | |||||||||||||||||||||||||||||||||||||||||||
| 195 | 414 | foreach my $name (keys %$sorted_data) { | |||||||||||||||||||||||||||||||||||||||||
| 196 | 829 | ▶ | next unless $sorted_data->{$name}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 197 | |||||||||||||||||||||||||||||||||||||||||||
| 198 | 786 | my $formatter = join('_', 'format', $name); | |||||||||||||||||||||||||||||||||||||||||
| 199 | 786 | ▶ | if ($self->can($formatter)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 200 | 200 | ▶ | if (ref $sorted_data->{$name} eq 'ARRAY') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 2 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 201 | 0 | for my $value (@{$sorted_data->{$name}}) { | |||||||||||||||||||||||||||||||||||||||||
| 202 | 0 | $value = $self->$formatter($sorted_order, | |||||||||||||||||||||||||||||||||||||||||
| 203 | $value); | ||||||||||||||||||||||||||||||||||||||||||
| 204 | } | ||||||||||||||||||||||||||||||||||||||||||
| 205 | |||||||||||||||||||||||||||||||||||||||||||
| 206 | } elsif (ref $sorted_data->{$name} eq 'HASH') { | ||||||||||||||||||||||||||||||||||||||||||
| 207 | 0 | die("Illegal data format for build: $name"); | |||||||||||||||||||||||||||||||||||||||||
| 208 | |||||||||||||||||||||||||||||||||||||||||||
| 209 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 210 | $sorted_data->{$name} = | ||||||||||||||||||||||||||||||||||||||||||
| 211 | 200 | $self->$formatter($sorted_order, $sorted_data->{$name}); | |||||||||||||||||||||||||||||||||||||||||
| 212 | } | ||||||||||||||||||||||||||||||||||||||||||
| 213 | } | ||||||||||||||||||||||||||||||||||||||||||
| 214 | } | ||||||||||||||||||||||||||||||||||||||||||
| 215 | |||||||||||||||||||||||||||||||||||||||||||
| 216 | 414 | return $sorted_data; | |||||||||||||||||||||||||||||||||||||||||
| 217 | } | ||||||||||||||||||||||||||||||||||||||||||
| 218 | |||||||||||||||||||||||||||||||||||||||||||
| 219 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 220 | # Don't format anything | ||||||||||||||||||||||||||||||||||||||||||
| 221 | |||||||||||||||||||||||||||||||||||||||||||
| 222 | 7 | ▶ | sub format_nothing { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
format_nothing: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 223 | 7 | my ($self, $sorted_order, $value) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 224 | 7 | return $value; | |||||||||||||||||||||||||||||||||||||||||
| 225 | } | ||||||||||||||||||||||||||||||||||||||||||
| 226 | |||||||||||||||||||||||||||||||||||||||||||
| 227 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 228 | # Gather the data for building a variable's value | ||||||||||||||||||||||||||||||||||||||||||
| 229 | |||||||||||||||||||||||||||||||||||||||||||
| 230 | 704 | ▶ | sub gather_data { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
gather_data: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 231 | 704 | my ($self, $method, $name, $item, $loop) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 232 | |||||||||||||||||||||||||||||||||||||||||||
| 233 | 704 | my @data; | |||||||||||||||||||||||||||||||||||||||||
| 234 | 704 | $method = join('_', $method, $name); | |||||||||||||||||||||||||||||||||||||||||
| 235 | |||||||||||||||||||||||||||||||||||||||||||
| 236 | 704 | ▶ | if ($self->can($method)) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 237 | 548 | @data = $self->$method($item, $loop); | |||||||||||||||||||||||||||||||||||||||||
| 238 | |||||||||||||||||||||||||||||||||||||||||||
| 239 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 240 | 156 | @data = (); | |||||||||||||||||||||||||||||||||||||||||
| 241 | } | ||||||||||||||||||||||||||||||||||||||||||
| 242 | |||||||||||||||||||||||||||||||||||||||||||
| 243 | 704 | my %data = $self->coerce_data($name, @data); | |||||||||||||||||||||||||||||||||||||||||
| 244 | 704 | return %data; | |||||||||||||||||||||||||||||||||||||||||
| 245 | } | ||||||||||||||||||||||||||||||||||||||||||
| 246 | |||||||||||||||||||||||||||||||||||||||||||
| 247 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 248 | # Get the count of the item in the list | ||||||||||||||||||||||||||||||||||||||||||
| 249 | |||||||||||||||||||||||||||||||||||||||||||
| 250 | 3 | ▶ | sub get_count { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_count: called CC=4 SCAR=14.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 251 | 3 | my ($self, $item, $loop) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 252 | 3 | ▶ | die "Can't use \$count outside of for\n" unless $loop; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 253 | |||||||||||||||||||||||||||||||||||||||||||
| 254 | 3 | foreach my $i (0 .. @$loop) { | |||||||||||||||||||||||||||||||||||||||||
| 255 | 6 | ▶ | if ($loop->[$i] eq $item) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 256 | 3 | my $count = $i + 1; | |||||||||||||||||||||||||||||||||||||||||
| 257 | 3 | return $count; | |||||||||||||||||||||||||||||||||||||||||
| 258 | } | ||||||||||||||||||||||||||||||||||||||||||
| 259 | } | ||||||||||||||||||||||||||||||||||||||||||
| 260 | |||||||||||||||||||||||||||||||||||||||||||
| 261 | 0 | return; | |||||||||||||||||||||||||||||||||||||||||
| 262 | } | ||||||||||||||||||||||||||||||||||||||||||
| 263 | |||||||||||||||||||||||||||||||||||||||||||
| 264 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 265 | # Is this the first item in the list? | ||||||||||||||||||||||||||||||||||||||||||
| 266 | |||||||||||||||||||||||||||||||||||||||||||
| 267 | 3 | ▶ | sub get_is_first { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_is_first: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 268 | 3 | my ($self, $item, $loop) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 269 | |||||||||||||||||||||||||||||||||||||||||||
| 270 | 3 | ▶ | die "Can't use \$is_first outside of for\n" unless $loop; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 271 | 3 | ▶ | return $loop->[0] eq $item ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 272 | } | ||||||||||||||||||||||||||||||||||||||||||
| 273 | |||||||||||||||||||||||||||||||||||||||||||
| 274 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 275 | # Is this the last item in the list? | ||||||||||||||||||||||||||||||||||||||||||
| 276 | |||||||||||||||||||||||||||||||||||||||||||
| 277 | 3 | ▶ | sub get_is_last { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_is_last: called CC=3 SCAR=11.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 278 | 3 | my ($self, $item, $loop) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 279 | |||||||||||||||||||||||||||||||||||||||||||
| 280 | 3 | ▶ | die "Can't use \$is_last outside of for\n" unless $loop; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 281 | 3 | ▶ | return $loop->[-1] eq $item ? 1 : 0; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 282 | } | ||||||||||||||||||||||||||||||||||||||||||
| 283 | |||||||||||||||||||||||||||||||||||||||||||
| 284 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 285 | # Return the current list of loop items | ||||||||||||||||||||||||||||||||||||||||||
| 286 | |||||||||||||||||||||||||||||||||||||||||||
| 287 | 1 | ▶ | sub get_loop { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_loop: called CC=2 SCAR=7.1
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 288 | 1 | my ($self, $item, $loop) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 289 | |||||||||||||||||||||||||||||||||||||||||||
| 290 | 1 | ▶ | die "Can't use \@loop outside of for\n" unless $loop; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 291 | 1 | return $loop; | |||||||||||||||||||||||||||||||||||||||||
| 292 | } | ||||||||||||||||||||||||||||||||||||||||||
| 293 | |||||||||||||||||||||||||||||||||||||||||||
| 294 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 295 | # Return the name of the current item in a loop | ||||||||||||||||||||||||||||||||||||||||||
| 296 | |||||||||||||||||||||||||||||||||||||||||||
| 297 | 144 | ▶ | sub get_name { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_name: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 298 | 144 | my ($self, $item) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 299 | 144 | return $item; | |||||||||||||||||||||||||||||||||||||||||
| 300 | } | ||||||||||||||||||||||||||||||||||||||||||
| 301 | |||||||||||||||||||||||||||||||||||||||||||
| 302 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 303 | # Get the current target | ||||||||||||||||||||||||||||||||||||||||||
| 304 | |||||||||||||||||||||||||||||||||||||||||||
| 305 | 12 | ▶ | sub get_target { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_target: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 306 | 12 | my ($self, $item, $loop) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 307 | 12 | return $self->find_target(0, $item, $loop); | |||||||||||||||||||||||||||||||||||||||||
| 308 | } | ||||||||||||||||||||||||||||||||||||||||||
| 309 | |||||||||||||||||||||||||||||||||||||||||||
| 310 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 311 | # Get the next target | ||||||||||||||||||||||||||||||||||||||||||
| 312 | |||||||||||||||||||||||||||||||||||||||||||
| 313 | 9 | ▶ | sub get_target_next { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_target_next: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 314 | 9 | my ($self, $item, $loop) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 315 | 9 | return $self->find_target(1, $item, $loop); | |||||||||||||||||||||||||||||||||||||||||
| 316 | } | ||||||||||||||||||||||||||||||||||||||||||
| 317 | |||||||||||||||||||||||||||||||||||||||||||
| 318 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 319 | # Get the previous target | ||||||||||||||||||||||||||||||||||||||||||
| 320 | |||||||||||||||||||||||||||||||||||||||||||
| 321 | 9 | ▶ | sub get_target_previous { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
get_target_previous: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 322 | 9 | my ($self, $item, $loop) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 323 | 9 | return $self->find_target(-1, $item, $loop); | |||||||||||||||||||||||||||||||||||||||||
| 324 | } | ||||||||||||||||||||||||||||||||||||||||||
| 325 | |||||||||||||||||||||||||||||||||||||||||||
| 326 | |||||||||||||||||||||||||||||||||||||||||||
| 327 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 328 | # Augment the array to be sorted with the column to sort it by | ||||||||||||||||||||||||||||||||||||||||||
| 329 | 142 | ▶ | sub make_augmented { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
make_augmented: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 330 | 142 | my ($self, $sort_column, $data_column) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 331 | |||||||||||||||||||||||||||||||||||||||||||
| 332 | 142 | my @augmented_list; | |||||||||||||||||||||||||||||||||||||||||
| 333 | 142 | ▶ | for (my $i = 0; $i < @$sort_column; $i++) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 334 | 218 | push(@augmented_list, [$sort_column->[$i], $data_column->[$i]]); | |||||||||||||||||||||||||||||||||||||||||
| 335 | } | ||||||||||||||||||||||||||||||||||||||||||
| 336 | |||||||||||||||||||||||||||||||||||||||||||
| 337 | 142 | return @augmented_list; | |||||||||||||||||||||||||||||||||||||||||
| 338 | } | ||||||||||||||||||||||||||||||||||||||||||
| 339 | |||||||||||||||||||||||||||||||||||||||||||
| 340 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 341 | # Merge two sorted lists of augmented filenames | ||||||||||||||||||||||||||||||||||||||||||
| 342 | |||||||||||||||||||||||||||||||||||||||||||
| 343 | 17 | ▶ | sub merge_augmented { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
merge_augmented: called CC=9 SCAR=22.3
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 344 | 17 | my ($self, $list1, $list2) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 345 | |||||||||||||||||||||||||||||||||||||||||||
| 346 | 17 | my @merged_list = (); | |||||||||||||||||||||||||||||||||||||||||
| 347 | 17 | my $sort_reverse = 1; | |||||||||||||||||||||||||||||||||||||||||
| 348 | 17 | my $comparer = $self->file_comparer($sort_reverse); | |||||||||||||||||||||||||||||||||||||||||
| 349 | |||||||||||||||||||||||||||||||||||||||||||
| 350 | 17 | ▶ | while(@$list1 && @$list2) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
Condition66%2/3
@$list1 and @$list2
MC/DC50%1/2
@$list1 and @$list2
@$list1
@$list2
Truth table66%2/3
A and B
A= @$list1B= @$list2
| |||||||||||||||||||||||||||||||||||||||||||
| 351 | 3 | ▶ | last if @merged_list == $self->{list_length}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 352 | 2 | ▶ | if ($comparer->($list1->[0], $list2->[0]) > 0) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 353 | 2 | push(@merged_list, shift @$list2); | |||||||||||||||||||||||||||||||||||||||||
| 354 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 355 | 0 | push(@merged_list, shift @$list1); | |||||||||||||||||||||||||||||||||||||||||
| 356 | } | ||||||||||||||||||||||||||||||||||||||||||
| 357 | } | ||||||||||||||||||||||||||||||||||||||||||
| 358 | |||||||||||||||||||||||||||||||||||||||||||
| 359 | 17 | ▶ | while (@$list1) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 360 | 1 | ▶ | last if @merged_list == $self->{list_length}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 361 | 0 | push(@merged_list, shift @$list1); | |||||||||||||||||||||||||||||||||||||||||
| 362 | } | ||||||||||||||||||||||||||||||||||||||||||
| 363 | |||||||||||||||||||||||||||||||||||||||||||
| 364 | 17 | ▶ | while (@$list2) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 365 | 20 | ▶ | last if @merged_list == $self->{list_length}; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 366 | 17 | push(@merged_list, shift @$list2); | |||||||||||||||||||||||||||||||||||||||||
| 367 | } | ||||||||||||||||||||||||||||||||||||||||||
| 368 | |||||||||||||||||||||||||||||||||||||||||||
| 369 | 17 | return \@merged_list; | |||||||||||||||||||||||||||||||||||||||||
| 370 | } | ||||||||||||||||||||||||||||||||||||||||||
| 371 | |||||||||||||||||||||||||||||||||||||||||||
| 372 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 373 | # Get a reference value and check it for agreement with the sigil | ||||||||||||||||||||||||||||||||||||||||||
| 374 | |||||||||||||||||||||||||||||||||||||||||||
| 375 | 496 | ▶ | sub ref_value { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
ref_value: called CC=8 SCAR=20.8
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 376 | 496 | my ($self, $value, $sigil, $data_field) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 377 | |||||||||||||||||||||||||||||||||||||||||||
| 378 | 496 | my ($check, $ref_value); | |||||||||||||||||||||||||||||||||||||||||
| 379 | 496 | ▶ | $value = '' unless defined $value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 380 | |||||||||||||||||||||||||||||||||||||||||||
| 381 | 496 | ▶ | if ($sigil eq '$'){ | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 3 branches
| |||||||||||||||||||||||||||||||||||||||||||
| 382 | 268 | ▶ | if (ref $value ne 'SCALAR') { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 383 | # Convert data structures for inclusion in template | ||||||||||||||||||||||||||||||||||||||||||
| 384 | 267 | $value = fio_flatten($value); | |||||||||||||||||||||||||||||||||||||||||
| 385 | 267 | $ref_value = \$value; | |||||||||||||||||||||||||||||||||||||||||
| 386 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 387 | 1 | $ref_value = $value; | |||||||||||||||||||||||||||||||||||||||||
| 388 | } | ||||||||||||||||||||||||||||||||||||||||||
| 389 | 268 | $check = ref $ref_value eq 'SCALAR'; | |||||||||||||||||||||||||||||||||||||||||
| 390 | |||||||||||||||||||||||||||||||||||||||||||
| 391 | } elsif ($sigil eq '@') { | ||||||||||||||||||||||||||||||||||||||||||
| 392 | 44 | $ref_value = $value; | |||||||||||||||||||||||||||||||||||||||||
| 393 | 44 | $check = ref $ref_value eq 'ARRAY'; | |||||||||||||||||||||||||||||||||||||||||
| 394 | |||||||||||||||||||||||||||||||||||||||||||
| 395 | } elsif ($sigil eq '') { | ||||||||||||||||||||||||||||||||||||||||||
| 396 | 184 | ▶ | $ref_value = ref $value ? $value : \$value; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 397 | 184 | $check = 1; | |||||||||||||||||||||||||||||||||||||||||
| 398 | } | ||||||||||||||||||||||||||||||||||||||||||
| 399 | |||||||||||||||||||||||||||||||||||||||||||
| 400 | 496 | ▶ | die "Unknown variable: $sigil$data_field\n" unless $check; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 401 | 496 | return $ref_value; | |||||||||||||||||||||||||||||||||||||||||
| 402 | } | ||||||||||||||||||||||||||||||||||||||||||
| 403 | |||||||||||||||||||||||||||||||||||||||||||
| 404 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 405 | # Set up the cache for data | ||||||||||||||||||||||||||||||||||||||||||
| 406 | |||||||||||||||||||||||||||||||||||||||||||
| 407 | 93 | ▶ | sub setup { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
setup: called CC=1 SCAR=0.0
Pod
documented
| |||||||||||||||||||||||||||||||||||||||||||
| 408 | 93 | my ($self) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 409 | |||||||||||||||||||||||||||||||||||||||||||
| 410 | 93 | $self->{cache} = {}; | |||||||||||||||||||||||||||||||||||||||||
| 411 | } | ||||||||||||||||||||||||||||||||||||||||||
| 412 | |||||||||||||||||||||||||||||||||||||||||||
| 413 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 414 | # Sort the data if it is in an array | ||||||||||||||||||||||||||||||||||||||||||
| 415 | |||||||||||||||||||||||||||||||||||||||||||
| 416 | 412 | ▶ | sub sort { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sort: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 417 | 412 | my ($self, $data, $sort_field, $sort_reverse) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 418 | |||||||||||||||||||||||||||||||||||||||||||
| 419 | 412 | my $sorted_data; | |||||||||||||||||||||||||||||||||||||||||
| 420 | 412 | my $data_field = $self->find_data_field($data); | |||||||||||||||||||||||||||||||||||||||||
| 421 | |||||||||||||||||||||||||||||||||||||||||||
| 422 | 412 | ▶ | if ($data_field) { | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 423 | 125 | my @augmented_data = $self->sort_with_field($data->{$data_field}, | |||||||||||||||||||||||||||||||||||||||||
| 424 | $sort_field, | ||||||||||||||||||||||||||||||||||||||||||
| 425 | $sort_reverse); | ||||||||||||||||||||||||||||||||||||||||||
| 426 | |||||||||||||||||||||||||||||||||||||||||||
| 427 | 125 | my @stripped_data = $self->strip_augmented(@augmented_data); | |||||||||||||||||||||||||||||||||||||||||
| 428 | 125 | $sorted_data = {$data_field => \@stripped_data}; | |||||||||||||||||||||||||||||||||||||||||
| 429 | |||||||||||||||||||||||||||||||||||||||||||
| 430 | } else { | ||||||||||||||||||||||||||||||||||||||||||
| 431 | 287 | $sorted_data = $data; | |||||||||||||||||||||||||||||||||||||||||
| 432 | } | ||||||||||||||||||||||||||||||||||||||||||
| 433 | |||||||||||||||||||||||||||||||||||||||||||
| 434 | 412 | return $sorted_data; | |||||||||||||||||||||||||||||||||||||||||
| 435 | } | ||||||||||||||||||||||||||||||||||||||||||
| 436 | |||||||||||||||||||||||||||||||||||||||||||
| 437 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 438 | # Sort augmented list by swartzian transform | ||||||||||||||||||||||||||||||||||||||||||
| 439 | |||||||||||||||||||||||||||||||||||||||||||
| 440 | 142 | ▶ | sub sort_augmented { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sort_augmented: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 441 | 142 | my ($self, $sort_reverse, @augmented_data) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 442 | |||||||||||||||||||||||||||||||||||||||||||
| 443 | 142 | my $comparer = $self->file_comparer($sort_reverse); | |||||||||||||||||||||||||||||||||||||||||
| 444 | 142 | @augmented_data = sort $comparer @augmented_data; | |||||||||||||||||||||||||||||||||||||||||
| 445 | 142 | return @augmented_data; | |||||||||||||||||||||||||||||||||||||||||
| 446 | } | ||||||||||||||||||||||||||||||||||||||||||
| 447 | |||||||||||||||||||||||||||||||||||||||||||
| 448 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 449 | # Sort data retaining the field you sort with | ||||||||||||||||||||||||||||||||||||||||||
| 450 | |||||||||||||||||||||||||||||||||||||||||||
| 451 | 142 | ▶ | sub sort_with_field { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
sort_with_field: called CC=3 SCAR=11.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 452 | 142 | my ($self, $data_column, $sort_field, $sort_reverse) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 453 | 142 | ▶ | $sort_field = 'name' unless defined $sort_field; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 454 | 142 | ▶ | $sort_reverse = 0 unless defined $sort_reverse; | ||||||||||||||||||||||||||||||||||||||||
|
Branch: 1 branch
| |||||||||||||||||||||||||||||||||||||||||||
| 455 | |||||||||||||||||||||||||||||||||||||||||||
| 456 | 142 | my $sort_column = $self->find_sort_column($data_column, $sort_field); | |||||||||||||||||||||||||||||||||||||||||
| 457 | |||||||||||||||||||||||||||||||||||||||||||
| 458 | 142 | return $self->sort_augmented($sort_reverse, | |||||||||||||||||||||||||||||||||||||||||
| 459 | $self->make_augmented($sort_column, $data_column)); | ||||||||||||||||||||||||||||||||||||||||||
| 460 | } | ||||||||||||||||||||||||||||||||||||||||||
| 461 | |||||||||||||||||||||||||||||||||||||||||||
| 462 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 463 | # Return the filenames from an augmented set of files | ||||||||||||||||||||||||||||||||||||||||||
| 464 | |||||||||||||||||||||||||||||||||||||||||||
| 465 | 134 | ▶ | sub strip_augmented { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
strip_augmented: called CC=1 SCAR=0.0
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 466 | 134 | my $self = shift @_; | |||||||||||||||||||||||||||||||||||||||||
| 467 | 134 | return map {$_->[1]} @_; | |||||||||||||||||||||||||||||||||||||||||
| 468 | } | ||||||||||||||||||||||||||||||||||||||||||
| 469 | |||||||||||||||||||||||||||||||||||||||||||
| 470 | #---------------------------------------------------------------------- | ||||||||||||||||||||||||||||||||||||||||||
| 471 | # Split the sigil off from the variable name from a template | ||||||||||||||||||||||||||||||||||||||||||
| 472 | |||||||||||||||||||||||||||||||||||||||||||
| 473 | 496 | ▶ | sub split_name { | ||||||||||||||||||||||||||||||||||||||||
|
Subroutine
split_name: called CC=2 SCAR=6.9
Pod
undocumented
| |||||||||||||||||||||||||||||||||||||||||||
| 474 | 496 | my ($self, $variable_name) = @_; | |||||||||||||||||||||||||||||||||||||||||
| 475 | |||||||||||||||||||||||||||||||||||||||||||
| 476 | 496 | my $name = $variable_name; | |||||||||||||||||||||||||||||||||||||||||
| 477 | 496 | $name =~ s/^([\$\@])//; | |||||||||||||||||||||||||||||||||||||||||
| 478 | 496 | ▶ | my $sigil = $1 || ''; | ||||||||||||||||||||||||||||||||||||||||
|
Condition100%2/2
$1 || ''
MC/DC100%1/1
$1 || ''
$1
Truth table100%2/2
A
A= $1
| |||||||||||||||||||||||||||||||||||||||||||
| 479 | |||||||||||||||||||||||||||||||||||||||||||
| 480 | 496 | return ($sigil, $name); | |||||||||||||||||||||||||||||||||||||||||
| 481 | } | ||||||||||||||||||||||||||||||||||||||||||
| 482 | |||||||||||||||||||||||||||||||||||||||||||
| 483 | 21 | 1; | |||||||||||||||||||||||||||||||||||||||||
| 484 | |||||||||||||||||||||||||||||||||||||||||||
| 485 | =pod | ||||||||||||||||||||||||||||||||||||||||||
| 486 | |||||||||||||||||||||||||||||||||||||||||||
| 487 | =encoding utf-8 | ||||||||||||||||||||||||||||||||||||||||||
| 488 | |||||||||||||||||||||||||||||||||||||||||||
| 489 | =head1 NAME | ||||||||||||||||||||||||||||||||||||||||||
| 490 | |||||||||||||||||||||||||||||||||||||||||||
| 491 | App::Followme::BaseData | ||||||||||||||||||||||||||||||||||||||||||
| 492 | |||||||||||||||||||||||||||||||||||||||||||
| 493 | =head1 SYNOPSIS | ||||||||||||||||||||||||||||||||||||||||||
| 494 | |||||||||||||||||||||||||||||||||||||||||||
| 495 | use App::Followme::BaseData; | ||||||||||||||||||||||||||||||||||||||||||
| 496 | my $meta = App::Followme::BaseData->new(); | ||||||||||||||||||||||||||||||||||||||||||
| 497 | my %data = $meta->build($name, $filename); | ||||||||||||||||||||||||||||||||||||||||||
| 498 | |||||||||||||||||||||||||||||||||||||||||||
| 499 | =head1 DESCRIPTION | ||||||||||||||||||||||||||||||||||||||||||
| 500 | |||||||||||||||||||||||||||||||||||||||||||
| 501 | This module is the base class for all metadata classes and provides the build | ||||||||||||||||||||||||||||||||||||||||||
| 502 | method used to interface metadata classes with the App::Followme::Template | ||||||||||||||||||||||||||||||||||||||||||
| 503 | class. | ||||||||||||||||||||||||||||||||||||||||||
| 504 | |||||||||||||||||||||||||||||||||||||||||||
| 505 | Followme uses templates to construct web pages. These templates contain | ||||||||||||||||||||||||||||||||||||||||||
| 506 | variables whose values are computed by calling the build method of the metadata | ||||||||||||||||||||||||||||||||||||||||||
| 507 | object, which is passed as an argument to the template function. The build | ||||||||||||||||||||||||||||||||||||||||||
| 508 | method returns either a reference to a scalar or list. The names correspond to | ||||||||||||||||||||||||||||||||||||||||||
| 509 | the variable names in the template. This class contains the build method, which | ||||||||||||||||||||||||||||||||||||||||||
| 510 | couples the variable name to the metadata object method that computes the value | ||||||||||||||||||||||||||||||||||||||||||
| 511 | of the variable. | ||||||||||||||||||||||||||||||||||||||||||
| 512 | |||||||||||||||||||||||||||||||||||||||||||
| 513 | =head1 METHODS | ||||||||||||||||||||||||||||||||||||||||||
| 514 | |||||||||||||||||||||||||||||||||||||||||||
| 515 | There is only one public method, build. | ||||||||||||||||||||||||||||||||||||||||||
| 516 | |||||||||||||||||||||||||||||||||||||||||||
| 517 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 518 | |||||||||||||||||||||||||||||||||||||||||||
| 519 | =item my %data = $meta->build($name, $filename); | ||||||||||||||||||||||||||||||||||||||||||
| 520 | |||||||||||||||||||||||||||||||||||||||||||
| 521 | Build a variable's value. The first argument is the name of the variable | ||||||||||||||||||||||||||||||||||||||||||
| 522 | to be built. The second argument is the filename the variable is computed for. | ||||||||||||||||||||||||||||||||||||||||||
| 523 | If the variable returned is a list of files, this variable should be left | ||||||||||||||||||||||||||||||||||||||||||
| 524 | undefined. | ||||||||||||||||||||||||||||||||||||||||||
| 525 | |||||||||||||||||||||||||||||||||||||||||||
| 526 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 527 | |||||||||||||||||||||||||||||||||||||||||||
| 528 | =head1 VARIABLES | ||||||||||||||||||||||||||||||||||||||||||
| 529 | |||||||||||||||||||||||||||||||||||||||||||
| 530 | The base metadata class can evaluate the following variables. When passing | ||||||||||||||||||||||||||||||||||||||||||
| 531 | a name to the build method, the sigil should not be used. All these variables | ||||||||||||||||||||||||||||||||||||||||||
| 532 | can only be used inside a for block. | ||||||||||||||||||||||||||||||||||||||||||
| 533 | |||||||||||||||||||||||||||||||||||||||||||
| 534 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 535 | |||||||||||||||||||||||||||||||||||||||||||
| 536 | =item @loop | ||||||||||||||||||||||||||||||||||||||||||
| 537 | |||||||||||||||||||||||||||||||||||||||||||
| 538 | A list with all the loop items from the immediately enclosing for block. | ||||||||||||||||||||||||||||||||||||||||||
| 539 | |||||||||||||||||||||||||||||||||||||||||||
| 540 | =item $count | ||||||||||||||||||||||||||||||||||||||||||
| 541 | |||||||||||||||||||||||||||||||||||||||||||
| 542 | The count of the current item in the for block.The count starts at one. | ||||||||||||||||||||||||||||||||||||||||||
| 543 | |||||||||||||||||||||||||||||||||||||||||||
| 544 | =item $is_first | ||||||||||||||||||||||||||||||||||||||||||
| 545 | |||||||||||||||||||||||||||||||||||||||||||
| 546 | One if this is the first item in the for block, zero otherwise. | ||||||||||||||||||||||||||||||||||||||||||
| 547 | |||||||||||||||||||||||||||||||||||||||||||
| 548 | =item $is_last | ||||||||||||||||||||||||||||||||||||||||||
| 549 | |||||||||||||||||||||||||||||||||||||||||||
| 550 | One if this is the last item in the for block, zero otherwise | ||||||||||||||||||||||||||||||||||||||||||
| 551 | |||||||||||||||||||||||||||||||||||||||||||
| 552 | =item $name | ||||||||||||||||||||||||||||||||||||||||||
| 553 | |||||||||||||||||||||||||||||||||||||||||||
| 554 | The name of the current item in the for block. | ||||||||||||||||||||||||||||||||||||||||||
| 555 | |||||||||||||||||||||||||||||||||||||||||||
| 556 | =item $target | ||||||||||||||||||||||||||||||||||||||||||
| 557 | |||||||||||||||||||||||||||||||||||||||||||
| 558 | A string that can be used as a target for the location of the current item | ||||||||||||||||||||||||||||||||||||||||||
| 559 | in the page. | ||||||||||||||||||||||||||||||||||||||||||
| 560 | |||||||||||||||||||||||||||||||||||||||||||
| 561 | =item $target_next | ||||||||||||||||||||||||||||||||||||||||||
| 562 | |||||||||||||||||||||||||||||||||||||||||||
| 563 | A string that can be used as a target for the location of the next item | ||||||||||||||||||||||||||||||||||||||||||
| 564 | in the page. Empty if there is no next item. | ||||||||||||||||||||||||||||||||||||||||||
| 565 | |||||||||||||||||||||||||||||||||||||||||||
| 566 | =item $target_previous | ||||||||||||||||||||||||||||||||||||||||||
| 567 | |||||||||||||||||||||||||||||||||||||||||||
| 568 | A string that can be used as a target for the location of the previous item | ||||||||||||||||||||||||||||||||||||||||||
| 569 | in the page. Empty if there is no previous item. | ||||||||||||||||||||||||||||||||||||||||||
| 570 | |||||||||||||||||||||||||||||||||||||||||||
| 571 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 572 | |||||||||||||||||||||||||||||||||||||||||||
| 573 | =head1 CONFIGURATION | ||||||||||||||||||||||||||||||||||||||||||
| 574 | |||||||||||||||||||||||||||||||||||||||||||
| 575 | There are two parameters: | ||||||||||||||||||||||||||||||||||||||||||
| 576 | |||||||||||||||||||||||||||||||||||||||||||
| 577 | =over 4 | ||||||||||||||||||||||||||||||||||||||||||
| 578 | |||||||||||||||||||||||||||||||||||||||||||
| 579 | =item list_length | ||||||||||||||||||||||||||||||||||||||||||
| 580 | |||||||||||||||||||||||||||||||||||||||||||
| 581 | This determines the number of filenames in a merged list. The default | ||||||||||||||||||||||||||||||||||||||||||
| 582 | value of this parameter is 5 | ||||||||||||||||||||||||||||||||||||||||||
| 583 | |||||||||||||||||||||||||||||||||||||||||||
| 584 | =item target_prefix | ||||||||||||||||||||||||||||||||||||||||||
| 585 | |||||||||||||||||||||||||||||||||||||||||||
| 586 | The prefix used to build the target names. The default value is 'target'. | ||||||||||||||||||||||||||||||||||||||||||
| 587 | |||||||||||||||||||||||||||||||||||||||||||
| 588 | =back | ||||||||||||||||||||||||||||||||||||||||||
| 589 | |||||||||||||||||||||||||||||||||||||||||||
| 590 | =head1 LICENSE | ||||||||||||||||||||||||||||||||||||||||||
| 591 | |||||||||||||||||||||||||||||||||||||||||||
| 592 | Copyright (C) Bernie Simon. | ||||||||||||||||||||||||||||||||||||||||||
| 593 | |||||||||||||||||||||||||||||||||||||||||||
| 594 | This library is free software; you can redistribute it and/or modify | ||||||||||||||||||||||||||||||||||||||||||
| 595 | it under the same terms as Perl itself. | ||||||||||||||||||||||||||||||||||||||||||
| 596 | |||||||||||||||||||||||||||||||||||||||||||
| 597 | =head1 AUTHOR | ||||||||||||||||||||||||||||||||||||||||||
| 598 | |||||||||||||||||||||||||||||||||||||||||||
| 599 | Bernie Simon E<lt>bernie.simon@gmail.comE<gt> | ||||||||||||||||||||||||||||||||||||||||||
| 600 | |||||||||||||||||||||||||||||||||||||||||||
| 601 | =cut | ||||||||||||||||||||||||||||||||||||||||||