line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
|
2
|
|
|
|
|
|
|
use strict; |
3
|
1
|
|
|
1
|
|
24677
|
use warnings; |
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
26
|
|
4
|
1
|
|
|
1
|
|
4
|
|
|
1
|
|
|
|
|
3
|
|
|
1
|
|
|
|
|
36
|
|
5
|
|
|
|
|
|
|
our $VERSION = '1.0.2'; |
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
use feature 'state'; |
8
|
1
|
|
|
1
|
|
7
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
77
|
|
9
|
|
|
|
|
|
|
use autodie; |
10
|
1
|
|
|
1
|
|
5
|
use File::Spec::Functions qw( catfile ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
9
|
|
11
|
1
|
|
|
1
|
|
6544
|
use File::Basename qw( dirname ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
67
|
|
12
|
1
|
|
|
1
|
|
6
|
use Hash::Merge (); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
75
|
|
13
|
1
|
|
|
1
|
|
1395
|
use Log::Log4perl qw( :easy ); |
|
1
|
|
|
|
|
7066
|
|
|
1
|
|
|
|
|
23
|
|
14
|
1
|
|
|
1
|
|
7
|
use Scalar::Util qw( blessed ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
10
|
|
15
|
1
|
|
|
1
|
|
788
|
use Type::Params qw( compile compile_named ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
57
|
|
16
|
1
|
|
|
1
|
|
6
|
use Types::Standard qw( Str StrMatch HashRef Any slurpy ); |
|
1
|
|
|
|
|
1
|
|
|
1
|
|
|
|
|
8
|
|
17
|
1
|
|
|
1
|
|
349
|
use YAML::Any qw( Dump LoadFile ); |
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
12
|
|
18
|
1
|
|
|
1
|
|
1102
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
16
|
|
19
|
|
|
|
|
|
|
use Google::RestApi::Types qw( ReadableFile ); |
20
|
1
|
|
|
1
|
|
627
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
10
|
|
21
|
|
|
|
|
|
|
no autovivification; |
22
|
1
|
|
|
1
|
|
335
|
|
|
1
|
|
|
|
|
2
|
|
|
1
|
|
|
|
|
6
|
|
23
|
|
|
|
|
|
|
use Exporter qw(import); |
24
|
1
|
|
|
1
|
|
46
|
our @EXPORT_OK = qw( |
|
1
|
|
|
|
|
11
|
|
|
1
|
|
|
|
|
1181
|
|
25
|
|
|
|
|
|
|
named_extra |
26
|
|
|
|
|
|
|
merge_config_file resolve_config_file_path |
27
|
|
|
|
|
|
|
flatten_range |
28
|
|
|
|
|
|
|
bool |
29
|
|
|
|
|
|
|
dim_any dims_any dims_all |
30
|
|
|
|
|
|
|
cl_black cl_white |
31
|
|
|
|
|
|
|
strip |
32
|
|
|
|
|
|
|
); |
33
|
|
|
|
|
|
|
our %EXPORT_TAGS = (all => [ @EXPORT_OK ]); |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
# used by validation with type::params. |
36
|
|
|
|
|
|
|
# similar to allow_extra in params::validate, simply returns the |
37
|
|
|
|
|
|
|
# extra key/value pairs we aren't interested in in the checked |
38
|
|
|
|
|
|
|
# argument hash. |
39
|
|
|
|
|
|
|
state $check = compile_named( |
40
|
|
|
|
|
|
|
_extra_ => HashRef, |
41
|
932
|
|
|
932
|
0
|
23637
|
validated => slurpy HashRef, |
42
|
|
|
|
|
|
|
); |
43
|
|
|
|
|
|
|
my $p = $check->(@_); |
44
|
|
|
|
|
|
|
my $extra = delete $p->{_extra_}; |
45
|
932
|
|
|
|
|
3556
|
|
46
|
931
|
|
|
|
|
18668
|
my %p; |
47
|
|
|
|
|
|
|
%p = %{ $p->{validated} } if $p->{validated}; # these are validated by the caller. |
48
|
931
|
|
|
|
|
1481
|
@p{ keys %$extra } = values %$extra; # stuff back the ones the caller wasn't interested in. |
49
|
931
|
50
|
|
|
|
3028
|
return \%p; |
|
931
|
|
|
|
|
2693
|
|
50
|
931
|
|
|
|
|
3472
|
} |
51
|
931
|
|
|
|
|
3244
|
|
52
|
|
|
|
|
|
|
state $check = compile_named( |
53
|
|
|
|
|
|
|
config_file => ReadableFile, { optional => 1 }, |
54
|
|
|
|
|
|
|
_extra_ => slurpy Any, |
55
|
301
|
|
|
301
|
0
|
3658
|
); |
56
|
|
|
|
|
|
|
my $passed_config = named_extra($check->(@_)); |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
my $config_file = $passed_config->{config_file}; |
59
|
301
|
|
|
|
|
2597
|
return $passed_config if !$config_file; |
60
|
|
|
|
|
|
|
|
61
|
299
|
|
|
|
|
1027
|
my $config_from_file = eval { LoadFile($config_file); }; |
62
|
299
|
100
|
|
|
|
1180
|
LOGDIE "Unable to load config file '$config_file': $@" if $@; |
63
|
|
|
|
|
|
|
|
64
|
154
|
|
|
|
|
316
|
# left_precedence, the passed config wins over anything in the file. |
|
154
|
|
|
|
|
853
|
|
65
|
154
|
50
|
|
|
|
539393
|
# can't merge coderefs, error comes from Storable buried deep in hash::merge. |
66
|
|
|
|
|
|
|
my $merged_config = Hash::Merge::merge($passed_config, $config_from_file); |
67
|
|
|
|
|
|
|
TRACE("Config used:\n". Dump($merged_config)); |
68
|
|
|
|
|
|
|
|
69
|
154
|
|
|
|
|
1042
|
return $merged_config; |
70
|
154
|
|
|
|
|
16524
|
} |
71
|
|
|
|
|
|
|
|
72
|
154
|
|
|
|
|
438714
|
# a standard way to store file names in a config and resolve them |
73
|
|
|
|
|
|
|
# to a full path. can be used in Auth configs, possibly others. |
74
|
|
|
|
|
|
|
# see sub RestApi::auth for more. |
75
|
|
|
|
|
|
|
state $check = compile(HashRef, Str); |
76
|
|
|
|
|
|
|
my ($config, $file_key) = $check->(@_); |
77
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
my $config_file = $config->{$file_key} or return; |
79
|
288
|
|
|
288
|
0
|
4499
|
return $config_file if -f $config_file; |
80
|
288
|
|
|
|
|
1705
|
|
81
|
|
|
|
|
|
|
my $full_file_path; |
82
|
288
|
100
|
|
|
|
4077
|
if ($file_key ne 'config_file' && $config->{config_file}) { |
83
|
145
|
100
|
|
|
|
2659
|
my $dir = dirname($config->{config_file}); |
84
|
|
|
|
|
|
|
my $path = catfile($dir, $config_file); |
85
|
143
|
|
|
|
|
489
|
$full_file_path = $path if -f $path |
86
|
143
|
100
|
66
|
|
|
1190
|
} |
87
|
2
|
|
|
|
|
111
|
|
88
|
2
|
|
|
|
|
15
|
if (!$full_file_path) { |
89
|
2
|
100
|
|
|
|
73
|
my $dir = $config->{config_dir}; |
90
|
|
|
|
|
|
|
if ($dir) { |
91
|
|
|
|
|
|
|
my $path = catfile($dir, $config_file); |
92
|
143
|
100
|
|
|
|
429
|
$full_file_path = $path if -f $path |
93
|
142
|
|
|
|
|
426
|
} |
94
|
142
|
100
|
|
|
|
731
|
} |
95
|
139
|
|
|
|
|
1135
|
|
96
|
139
|
50
|
|
|
|
3631
|
LOGDIE("Unable to resolve config file '$file_key => $config_file' to a full file path") |
97
|
|
|
|
|
|
|
if !$full_file_path; |
98
|
|
|
|
|
|
|
|
99
|
|
|
|
|
|
|
# action at a distance, but is convenient to stuff the real file name in the config here. |
100
|
143
|
100
|
|
|
|
493
|
$config->{$file_key} = $full_file_path; |
101
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
return $full_file_path; |
103
|
|
|
|
|
|
|
} |
104
|
140
|
|
|
|
|
414
|
|
105
|
|
|
|
|
|
|
# these are just used for debug message just above |
106
|
140
|
|
|
|
|
405
|
# to display the original range in a pretty format. |
107
|
|
|
|
|
|
|
my $range = shift; |
108
|
|
|
|
|
|
|
$range = $range->range_to_hash() if blessed($range); |
109
|
|
|
|
|
|
|
return 'False' if !$range; |
110
|
|
|
|
|
|
|
return $range if !ref($range); |
111
|
|
|
|
|
|
|
return _flatten_range_hash($range) if ref($range) eq 'HASH'; |
112
|
861
|
|
|
861
|
0
|
74164
|
return _flatten_range_array($range) if ref($range) eq 'ARRAY'; |
113
|
861
|
100
|
|
|
|
2525
|
LOGDIE("Unable to flatten: " . ref($range)); |
114
|
861
|
100
|
|
|
|
1687
|
} |
115
|
818
|
100
|
|
|
|
2867
|
|
116
|
254
|
100
|
|
|
|
681
|
my $range = shift; |
117
|
104
|
50
|
|
|
|
474
|
my @flat = map { "$_ => " . flatten_range($range->{$_}); } sort keys %$range; |
118
|
0
|
|
|
|
|
0
|
my $flat = join(', ', @flat); |
119
|
|
|
|
|
|
|
return "{ $flat }"; |
120
|
|
|
|
|
|
|
} |
121
|
|
|
|
|
|
|
|
122
|
150
|
|
|
150
|
|
232
|
my $range = shift; |
123
|
150
|
|
|
|
|
741
|
my @flat = map { flatten_range($_); } @$range; |
|
287
|
|
|
|
|
648
|
|
124
|
150
|
|
|
|
|
382
|
my $flat = join(', ', @flat); |
125
|
150
|
|
|
|
|
623
|
return "[ $flat ]"; |
126
|
|
|
|
|
|
|
} |
127
|
|
|
|
|
|
|
|
128
|
|
|
|
|
|
|
# changes perl boolean to json boolean. |
129
|
104
|
|
|
104
|
|
170
|
my $bool = shift; |
130
|
104
|
|
|
|
|
213
|
return 'true' if !defined $bool; # bold() should turn on bold. |
|
187
|
|
|
|
|
297
|
|
131
|
104
|
|
|
|
|
265
|
return 'false' if $bool =~ qr/^false$/i; |
132
|
104
|
|
|
|
|
565
|
return $bool ? 'true' : 'false'; # converts bold(0) to 'false'. |
133
|
|
|
|
|
|
|
} |
134
|
|
|
|
|
|
|
|
135
|
|
|
|
|
|
|
state $check = compile(StrMatch[qr/^(col|row)/i]); |
136
|
|
|
|
|
|
|
my ($dims) = $check->(@_); |
137
|
25
|
|
|
25
|
0
|
4835
|
return $dims =~ /^col/i ? "COLUMNS" : "ROWS"; |
138
|
25
|
100
|
|
|
|
129
|
} |
139
|
12
|
100
|
|
|
|
106
|
|
140
|
10
|
100
|
|
|
|
80
|
my $dims = eval { dims_any(@_); }; |
141
|
|
|
|
|
|
|
return $dims if $dims; |
142
|
|
|
|
|
|
|
state $check = compile(StrMatch[qr/^all/i]); |
143
|
|
|
|
|
|
|
($dims) = $check->(@_); |
144
|
223
|
|
|
223
|
0
|
610
|
return "ALL"; |
145
|
223
|
|
|
|
|
2391
|
} |
146
|
222
|
100
|
|
|
|
3920
|
|
147
|
|
|
|
|
|
|
|
148
|
|
|
|
|
|
|
my $p = shift // ''; |
149
|
|
|
|
|
|
|
$p =~ s/^\s+|\s+$//g; |
150
|
3
|
|
|
3
|
0
|
7
|
return $p; |
|
3
|
|
|
|
|
8
|
|
151
|
3
|
100
|
|
|
|
210
|
} |
152
|
1
|
|
|
|
|
8
|
|
153
|
1
|
|
|
|
|
1827
|
1; |