line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package Mojo::Netdata::Util; |
2
|
5
|
|
|
5
|
|
230402
|
use Mojo::Base -strict, -signatures; |
|
5
|
|
|
|
|
165564
|
|
|
5
|
|
|
|
|
34
|
|
3
|
|
|
|
|
|
|
|
4
|
5
|
|
|
5
|
|
5232
|
use Exporter qw(import); |
|
5
|
|
|
|
|
10
|
|
|
5
|
|
|
|
|
140
|
|
5
|
5
|
|
|
5
|
|
1480
|
use Mojo::File; |
|
5
|
|
|
|
|
90532
|
|
|
5
|
|
|
|
|
1645
|
|
6
|
|
|
|
|
|
|
|
7
|
|
|
|
|
|
|
our @EXPORT_OK = qw(logf safe_id); |
8
|
|
|
|
|
|
|
|
9
|
23
|
|
|
23
|
1
|
100
|
sub logf ($level, $format, @args) { |
|
23
|
|
|
|
|
39
|
|
|
23
|
|
|
|
|
34
|
|
|
23
|
|
|
|
|
43
|
|
|
23
|
|
|
|
|
32
|
|
10
|
23
|
50
|
33
|
|
|
170
|
return 1 if $ENV{HARNESS_ACTIVE} and !$ENV{HARNESS_IS_VERBOSE}; |
11
|
0
|
0
|
0
|
|
|
0
|
return 1 if $level eq 'debug' and !$ENV{HARNESS_IS_VERBOSE} and !$ENV{NETDATA_DEBUG_FLAGS}; |
|
|
|
0
|
|
|
|
|
12
|
|
|
|
|
|
|
|
13
|
0
|
|
|
|
|
0
|
my $module_name = caller; |
14
|
0
|
|
|
|
|
0
|
my ($s, $m, $h, $day, $month, $year) = localtime time; |
15
|
|
|
|
|
|
|
|
16
|
0
|
|
|
|
|
0
|
state $program_name = Mojo::File->new($0)->basename; |
17
|
0
|
|
|
|
|
0
|
printf STDERR "%s-%02s-%02s %02s:%02s:%02s: %s: %s: %s: $format\n", $year + 1900, $month + 1, |
18
|
|
|
|
|
|
|
$day, $h, $m, $s, $program_name, uc $level, $module_name, @args; |
19
|
0
|
|
|
|
|
0
|
return 1; |
20
|
|
|
|
|
|
|
} |
21
|
|
|
|
|
|
|
|
22
|
125
|
|
|
125
|
1
|
7004
|
sub safe_id ($str) { |
|
125
|
|
|
|
|
157
|
|
|
125
|
|
|
|
|
137
|
|
23
|
125
|
|
|
|
|
397
|
$str =~ s![^A-Za-z0-9]!_!g; |
24
|
125
|
|
|
|
|
379
|
$str =~ s!_+$!!g; |
25
|
125
|
|
|
|
|
160
|
$str =~ s!^_+!!g; |
26
|
125
|
|
|
|
|
314
|
return $str; |
27
|
|
|
|
|
|
|
} |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
1; |
30
|
|
|
|
|
|
|
|
31
|
|
|
|
|
|
|
=encoding utf8 |
32
|
|
|
|
|
|
|
|
33
|
|
|
|
|
|
|
=head1 NAME |
34
|
|
|
|
|
|
|
|
35
|
|
|
|
|
|
|
Mojo::Netdata::Util - Utility functions for Mojo::Netdata |
36
|
|
|
|
|
|
|
|
37
|
|
|
|
|
|
|
=head1 SYNOPSIS |
38
|
|
|
|
|
|
|
|
39
|
|
|
|
|
|
|
use Mojo::Netdata::Util qw(safe_id); |
40
|
|
|
|
|
|
|
print safe_id 'Not%co.ol'; |
41
|
|
|
|
|
|
|
|
42
|
|
|
|
|
|
|
=head1 DESCRIPTION |
43
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
L as functions that can be useful when working with |
45
|
|
|
|
|
|
|
L classes. |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
=head1 EXPORTED FUNCTIONS |
48
|
|
|
|
|
|
|
|
49
|
|
|
|
|
|
|
=head2 logf |
50
|
|
|
|
|
|
|
|
51
|
|
|
|
|
|
|
logf $level, $format, @args; |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
Used to log messages to STDERR. C<$level> can be "debug", "info", "warnings", |
54
|
|
|
|
|
|
|
"error", "fatal". |
55
|
|
|
|
|
|
|
|
56
|
|
|
|
|
|
|
=head2 safe_id |
57
|
|
|
|
|
|
|
|
58
|
|
|
|
|
|
|
$str = safe_id $str; |
59
|
|
|
|
|
|
|
|
60
|
|
|
|
|
|
|
Turns an "unsafe" string into a string you can use for things like "id" or |
61
|
|
|
|
|
|
|
"type". This is called by L and |
62
|
|
|
|
|
|
|
L to make sure the output strings are |
63
|
|
|
|
|
|
|
safe. |
64
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
=head1 SEE ALSO |
66
|
|
|
|
|
|
|
|
67
|
|
|
|
|
|
|
L. |
68
|
|
|
|
|
|
|
|
69
|
|
|
|
|
|
|
=cut |