line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
1
|
|
|
|
|
|
|
package InfluxDB::Client::DataSet; |
2
|
|
|
|
|
|
|
# ABSTRACT: simple container to hold and prepare data for Cwrite()> |
3
|
|
|
|
|
|
|
|
4
|
|
|
|
|
|
|
|
5
|
2
|
|
|
2
|
|
57069
|
use strict; |
|
2
|
|
|
|
|
13
|
|
|
2
|
|
|
|
|
55
|
|
6
|
2
|
|
|
2
|
|
9
|
use warnings; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
46
|
|
7
|
|
|
|
|
|
|
|
8
|
2
|
|
|
2
|
|
8
|
use Carp; |
|
2
|
|
|
|
|
3
|
|
|
2
|
|
|
|
|
92
|
|
9
|
2
|
|
|
2
|
|
581
|
use Time::HiRes; |
|
2
|
|
|
|
|
1917
|
|
|
2
|
|
|
|
|
7
|
|
10
|
2
|
|
|
2
|
|
651
|
use InfluxDB::LineProtocol; |
|
2
|
|
|
|
|
4190
|
|
|
2
|
|
|
|
|
10
|
|
11
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our $VERSION = '0.1'; |
13
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
sub new { |
15
|
1
|
|
|
1
|
1
|
2144
|
my ($class, %args ); |
16
|
|
|
|
|
|
|
# check if we have only one argument |
17
|
1
|
50
|
|
|
|
5
|
if ( @_ == 2 ) { |
18
|
0
|
|
|
|
|
0
|
my $measurement; |
19
|
0
|
|
|
|
|
0
|
( $class, $measurement ) = @_; |
20
|
0
|
|
|
|
|
0
|
$args{measurement} = $measurement; |
21
|
|
|
|
|
|
|
} else { |
22
|
|
|
|
|
|
|
# else we assume we got an hash |
23
|
1
|
|
|
|
|
5
|
( $class, %args ) = @_; |
24
|
|
|
|
|
|
|
} |
25
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
# check the precision |
27
|
1
|
|
50
|
|
|
7
|
$args{precision} //= 'ns'; |
28
|
|
|
|
|
|
|
|
29
|
|
|
|
|
|
|
# set our timestamp function |
30
|
1
|
|
|
|
|
1
|
my $get_ts; |
31
|
|
|
|
|
|
|
{ |
32
|
|
|
|
|
|
|
## no critic qw(TestingAndDebugging::ProhibitNoStrict) |
33
|
2
|
|
|
2
|
|
204
|
no strict 'refs'; |
|
2
|
|
|
|
|
4
|
|
|
2
|
|
|
|
|
931
|
|
|
1
|
|
|
|
|
2
|
|
34
|
1
|
|
|
|
|
3
|
my $ts_func = 'InfluxDB::LineProtocol::ts_' . $args{precision}; |
35
|
1
|
|
|
|
|
4
|
*{"$class\::get_ts"} = \&$ts_func; |
|
1
|
|
|
|
|
4
|
|
36
|
|
|
|
|
|
|
} |
37
|
|
|
|
|
|
|
|
38
|
|
|
|
|
|
|
# set the timestamp |
39
|
1
|
|
33
|
|
|
8
|
$args{timestamp} //= $class->get_ts(); |
40
|
|
|
|
|
|
|
|
41
|
|
|
|
|
|
|
# validate the measurement parameter |
42
|
|
|
|
|
|
|
croak 'no measurement given' |
43
|
1
|
50
|
|
|
|
13
|
unless defined $args{measurement}; |
44
|
|
|
|
|
|
|
croak 'measurement must not be a reference' |
45
|
1
|
50
|
|
|
|
3
|
if ( ref $args{measurement} ); |
46
|
|
|
|
|
|
|
|
47
|
|
|
|
|
|
|
# validate the values parameters |
48
|
1
|
50
|
33
|
|
|
7
|
if (exists $args{values} && defined $args{values}) { |
49
|
|
|
|
|
|
|
croak 'values must be a hash reference' |
50
|
1
|
50
|
33
|
|
|
7
|
unless (ref $args{values} && ref $args{values} eq 'HASH'); |
51
|
|
|
|
|
|
|
} |
52
|
|
|
|
|
|
|
|
53
|
|
|
|
|
|
|
# validate the tags parameters |
54
|
1
|
50
|
33
|
|
|
4
|
if (exists $args{tags} && defined $args{tags}) { |
55
|
|
|
|
|
|
|
croak 'values must be a hash reference' |
56
|
1
|
50
|
33
|
|
|
8
|
unless (ref $args{tags} && ref $args{tags} eq 'HASH'); |
57
|
|
|
|
|
|
|
} |
58
|
|
|
|
|
|
|
|
59
|
|
|
|
|
|
|
# construct $self |
60
|
|
|
|
|
|
|
my $self = bless { |
61
|
|
|
|
|
|
|
_measurement => $args{measurement}, |
62
|
|
|
|
|
|
|
_values => $args{values} // {}, |
63
|
|
|
|
|
|
|
_tags => $args{tags} // {}, |
64
|
|
|
|
|
|
|
_precision => $args{precision}, |
65
|
|
|
|
|
|
|
_ts => $args{timestamp} |
66
|
1
|
|
50
|
|
|
10
|
} => $class; |
|
|
|
50
|
|
|
|
|
67
|
1
|
|
|
|
|
4
|
return $self; |
68
|
|
|
|
|
|
|
} |
69
|
|
|
|
|
|
|
|
70
|
|
|
|
|
|
|
|
71
|
|
|
|
|
|
|
sub measurement { |
72
|
0
|
|
|
0
|
1
|
0
|
my ( $self, $m ) = @_; |
73
|
0
|
0
|
|
|
|
0
|
if ( $m ) { |
74
|
0
|
0
|
|
|
|
0
|
croak 'measurement must not be a reference' |
75
|
|
|
|
|
|
|
if ( ref $m ); |
76
|
0
|
|
|
|
|
0
|
$self->{_measurement} = $m; |
77
|
|
|
|
|
|
|
} |
78
|
0
|
|
|
|
|
0
|
return $self->{_measurement}; |
79
|
|
|
|
|
|
|
} |
80
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
sub value { |
83
|
0
|
|
|
0
|
1
|
0
|
$_[0]->_set_tag_or_values('values',@_); |
84
|
|
|
|
|
|
|
} |
85
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
sub tag { |
87
|
0
|
|
|
0
|
1
|
0
|
$_[0]->_set_tag_or_values('tags',@_); |
88
|
|
|
|
|
|
|
} |
89
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
sub precision { |
91
|
0
|
|
|
0
|
1
|
0
|
return $_[0]->{_precision}; |
92
|
|
|
|
|
|
|
} |
93
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
sub ts { |
95
|
1
|
|
|
1
|
1
|
179
|
my ( $self, $ts ) = @_; |
96
|
1
|
50
|
|
|
|
13
|
$self->{_ts} = $ts if $ts; |
97
|
1
|
|
|
|
|
4
|
return $self->{_ts}; |
98
|
|
|
|
|
|
|
} |
99
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
sub set_ts { |
101
|
0
|
|
|
0
|
1
|
0
|
my ( $self, $ts ) = @_; |
102
|
0
|
|
0
|
|
|
0
|
$self->ts($ts // $self->get_ts); |
103
|
|
|
|
|
|
|
} |
104
|
|
|
|
|
|
|
|
105
|
|
|
|
|
|
|
|
106
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub as_string { |
108
|
1
|
|
|
1
|
1
|
2109
|
my ( $self ) = @_; |
109
|
1
|
|
|
|
|
11
|
return InfluxDB::LineProtocol::data2line($self->{_measurement}, $self->{_values}, $self->{_tags}, $self->{_ts}); |
110
|
|
|
|
|
|
|
} |
111
|
|
|
|
|
|
|
|
112
|
|
|
|
|
|
|
# helper for the tag() and value() functions |
113
|
|
|
|
|
|
|
sub _set_tag_or_values { |
114
|
0
|
|
|
0
|
|
|
my $self = shift; |
115
|
0
|
|
|
|
|
|
my $elem = shift; |
116
|
|
|
|
|
|
|
# check if we have a single paramter |
117
|
0
|
0
|
|
|
|
|
if ( @_ == 1 ) { |
118
|
0
|
|
|
|
|
|
my ($p) = @_; |
119
|
|
|
|
|
|
|
# if the paramter is a hasreference, we override our internal storage |
120
|
0
|
0
|
|
|
|
|
if (ref $p ) { |
121
|
0
|
0
|
|
|
|
|
croak "either a $elem key or a hash reference wanted" |
122
|
|
|
|
|
|
|
unless (ref $p eq 'HASH'); |
123
|
|
|
|
|
|
|
# copy the hash reference |
124
|
0
|
|
|
|
|
|
$self->{'_'.$elem} = { %$p }; |
125
|
|
|
|
|
|
|
} else { |
126
|
|
|
|
|
|
|
# we just fetch the element and return it |
127
|
0
|
0
|
|
|
|
|
return $self->{'_'.$elem}{$p} if ( exists $self->{'_'.$elem}{$p} ); |
128
|
|
|
|
|
|
|
# return undef if the key does not exist |
129
|
0
|
|
|
|
|
|
return; |
130
|
|
|
|
|
|
|
} |
131
|
|
|
|
|
|
|
} else { |
132
|
0
|
|
|
|
|
|
my ( %pairs ) = @_; |
133
|
0
|
|
|
|
|
|
foreach my $k ( keys %pairs ) { |
134
|
0
|
|
|
|
|
|
$self->{'_'.$elem}{$k} = $pairs{$k}; |
135
|
|
|
|
|
|
|
} |
136
|
|
|
|
|
|
|
} |
137
|
|
|
|
|
|
|
# we return a copy of our internal storage |
138
|
0
|
|
|
|
|
|
return { %{$self->{'_'.$elem}} } |
|
0
|
|
|
|
|
|
|
139
|
|
|
|
|
|
|
} |
140
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
1; |
142
|
|
|
|
|
|
|
|
143
|
|
|
|
|
|
|
__END__ |