| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Told::Client; |
|
2
|
|
|
|
|
|
|
|
|
3
|
18
|
|
|
18
|
|
638946
|
use 5.016002; |
|
|
18
|
|
|
|
|
67
|
|
|
|
18
|
|
|
|
|
578
|
|
|
4
|
18
|
|
|
18
|
|
93
|
use strict; |
|
|
18
|
|
|
|
|
40
|
|
|
|
18
|
|
|
|
|
602
|
|
|
5
|
18
|
|
|
18
|
|
81
|
use warnings; |
|
|
18
|
|
|
|
|
39
|
|
|
|
18
|
|
|
|
|
703
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
18
|
|
|
18
|
|
20981
|
use JSON; |
|
|
18
|
|
|
|
|
264475
|
|
|
|
18
|
|
|
|
|
171
|
|
|
8
|
18
|
|
|
18
|
|
29893
|
use LWP; |
|
|
18
|
|
|
|
|
1025764
|
|
|
|
18
|
|
|
|
|
32614
|
|
|
9
|
|
|
|
|
|
|
|
|
10
|
|
|
|
|
|
|
require Exporter; |
|
11
|
|
|
|
|
|
|
|
|
12
|
|
|
|
|
|
|
our @ISA = qw(Exporter); |
|
13
|
|
|
|
|
|
|
|
|
14
|
|
|
|
|
|
|
our %EXPORT_TAGS = ( 'all' => [ qw( |
|
15
|
|
|
|
|
|
|
tell |
|
16
|
|
|
|
|
|
|
setDebug |
|
17
|
|
|
|
|
|
|
setConnectionType |
|
18
|
|
|
|
|
|
|
setHost |
|
19
|
|
|
|
|
|
|
setType |
|
20
|
|
|
|
|
|
|
setTags |
|
21
|
|
|
|
|
|
|
setDefaulttags |
|
22
|
|
|
|
|
|
|
) ] ); |
|
23
|
|
|
|
|
|
|
|
|
24
|
|
|
|
|
|
|
our @EXPORT_OK = ( @{ $EXPORT_TAGS{'all'} } ); |
|
25
|
|
|
|
|
|
|
|
|
26
|
|
|
|
|
|
|
our @EXPORT = qw( |
|
27
|
|
|
|
|
|
|
getParams |
|
28
|
|
|
|
|
|
|
); |
|
29
|
|
|
|
|
|
|
|
|
30
|
|
|
|
|
|
|
our $VERSION = '0.01'; |
|
31
|
|
|
|
|
|
|
|
|
32
|
|
|
|
|
|
|
sub new { |
|
33
|
19
|
|
|
19
|
0
|
1526
|
my $package = shift; |
|
34
|
19
|
|
|
|
|
37
|
my $config = shift; |
|
35
|
19
|
|
|
|
|
37
|
my $recref = {}; |
|
36
|
19
|
|
|
|
|
131
|
bless $recref, $package; |
|
37
|
19
|
|
100
|
|
|
139
|
$recref->setHost( $config->{'host'} || ''); |
|
38
|
19
|
|
100
|
|
|
186
|
$recref->setType( $config->{'type'} || ''); |
|
39
|
19
|
100
|
|
|
|
59
|
$recref->setDefaulttags( @{$config->{'defaulttags'}}) if($config->{'defaulttags'}); |
|
|
2
|
|
|
|
|
9
|
|
|
40
|
19
|
100
|
|
|
|
71
|
$recref->setTags( @{$config->{'tags'}}) if($config->{'tags'}); |
|
|
4
|
|
|
|
|
15
|
|
|
41
|
19
|
|
50
|
|
|
154
|
$recref->setConnectionType( $config->{'connection'} || 'POST'); |
|
42
|
|
|
|
|
|
|
|
|
43
|
19
|
|
|
|
|
79
|
return $recref; |
|
44
|
|
|
|
|
|
|
} |
|
45
|
|
|
|
|
|
|
|
|
46
|
|
|
|
|
|
|
sub setDebug { |
|
47
|
0
|
|
|
0
|
0
|
0
|
my $self = shift; |
|
48
|
0
|
0
|
|
|
|
0
|
if(@_) { |
|
49
|
0
|
|
|
|
|
0
|
$self->{'verbose'} = shift; |
|
50
|
|
|
|
|
|
|
} |
|
51
|
0
|
0
|
|
|
|
0
|
print "Told::Client in debug mode.\n" if $self->{'verbose'}; |
|
52
|
|
|
|
|
|
|
} |
|
53
|
|
|
|
|
|
|
|
|
54
|
|
|
|
|
|
|
sub getParams { |
|
55
|
9
|
|
|
9
|
0
|
23
|
my $self = shift; |
|
56
|
9
|
|
|
|
|
44
|
my $param = { |
|
57
|
|
|
|
|
|
|
'host' => $self->{'host'} |
|
58
|
|
|
|
|
|
|
, 'type' => $self->{'type'} |
|
59
|
|
|
|
|
|
|
, 'defaulttags' => $self->{'defaulttags'} |
|
60
|
|
|
|
|
|
|
, 'tags' => $self->{'tags'} |
|
61
|
|
|
|
|
|
|
}; |
|
62
|
9
|
|
|
|
|
22
|
return $param; |
|
63
|
|
|
|
|
|
|
} |
|
64
|
|
|
|
|
|
|
|
|
65
|
|
|
|
|
|
|
|
|
66
|
|
|
|
|
|
|
sub setConnectionType { |
|
67
|
33
|
|
|
33
|
0
|
80
|
my $self = shift; |
|
68
|
33
|
|
|
|
|
55
|
my $type = shift; |
|
69
|
33
|
50
|
|
|
|
90
|
if($type) { |
|
70
|
33
|
100
|
|
|
|
244
|
if($type =~ /GET|POST|UDP/i){ |
|
71
|
32
|
|
|
|
|
73
|
$self->{'connectiontype'} = $type; |
|
72
|
|
|
|
|
|
|
} else { |
|
73
|
1
|
50
|
|
|
|
7
|
warn("Connectiontype ".$type." is not known.") if $self->{'verbose'}; |
|
74
|
1
|
|
|
|
|
5
|
return 0; |
|
75
|
|
|
|
|
|
|
} |
|
76
|
|
|
|
|
|
|
} |
|
77
|
32
|
|
|
|
|
83
|
return 1; |
|
78
|
|
|
|
|
|
|
} |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
|
|
81
|
|
|
|
|
|
|
sub setHost { |
|
82
|
20
|
|
|
20
|
0
|
35
|
my $self = shift; |
|
83
|
20
|
50
|
|
|
|
77
|
if(@_) { |
|
84
|
20
|
|
|
|
|
130
|
$self->{'host'} = shift; |
|
85
|
|
|
|
|
|
|
} |
|
86
|
20
|
50
|
|
|
|
111
|
print "Setting host to: ". $self->{'host'} ."\n" if $self->{'verbose'}; |
|
87
|
|
|
|
|
|
|
} |
|
88
|
|
|
|
|
|
|
|
|
89
|
|
|
|
|
|
|
sub setType { |
|
90
|
21
|
|
|
21
|
0
|
44
|
my $self = shift; |
|
91
|
21
|
50
|
|
|
|
68
|
if(@_) { |
|
92
|
21
|
|
|
|
|
55
|
$self->{'type'} = shift; |
|
93
|
|
|
|
|
|
|
} |
|
94
|
21
|
50
|
|
|
|
85
|
print "Setting type to: ". $self->{'type'} ."\n" if $self->{'verbose'}; |
|
95
|
|
|
|
|
|
|
} |
|
96
|
|
|
|
|
|
|
|
|
97
|
|
|
|
|
|
|
sub setTags { |
|
98
|
6
|
|
|
6
|
0
|
797
|
my $self = shift; |
|
99
|
6
|
|
|
|
|
8
|
my @tags; |
|
100
|
6
|
|
|
|
|
20
|
while(@_){ |
|
101
|
10
|
|
|
|
|
25
|
push(@tags, shift); |
|
102
|
|
|
|
|
|
|
} |
|
103
|
6
|
|
|
|
|
13
|
$self->{'tags'} = \@tags; |
|
104
|
6
|
50
|
|
|
|
23
|
print "Setting tags to: ". join(", ", @{$self->{'tags'}}) ."\n" if $self->{'verbose'}; |
|
|
0
|
|
|
|
|
0
|
|
|
105
|
|
|
|
|
|
|
} |
|
106
|
|
|
|
|
|
|
|
|
107
|
|
|
|
|
|
|
sub setDefaulttags { |
|
108
|
4
|
|
|
4
|
0
|
841
|
my $self = shift; |
|
109
|
4
|
|
|
|
|
6
|
my @defaulttags; |
|
110
|
4
|
|
|
|
|
11
|
while(@_){ |
|
111
|
6
|
|
|
|
|
16
|
push(@defaulttags, shift); |
|
112
|
|
|
|
|
|
|
} |
|
113
|
4
|
|
|
|
|
10
|
$self->{'defaulttags'} = \@defaulttags; |
|
114
|
4
|
50
|
|
|
|
15
|
print "Setting defaulttags to: ". join(", ", @{$self->{'defaulttags'}}) ."\n" if $self->{'verbose'}; |
|
|
0
|
|
|
|
|
0
|
|
|
115
|
|
|
|
|
|
|
} |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
sub tell { |
|
118
|
17
|
|
|
17
|
0
|
5982
|
my $self = shift; |
|
119
|
17
|
|
|
|
|
68
|
my ($_message, $_type, @_tags) = @_; |
|
120
|
|
|
|
|
|
|
|
|
121
|
17
|
|
|
|
|
145
|
my $browser = LWP::UserAgent->new; |
|
122
|
17
|
50
|
33
|
|
|
39161
|
if(!$self->{'host'} || length($self->{'host'}) == 0){ |
|
123
|
0
|
0
|
|
|
|
0
|
warn "No host ist set\n" if $self->{'verbose'}; |
|
124
|
0
|
|
|
|
|
0
|
return 0; |
|
125
|
|
|
|
|
|
|
} |
|
126
|
17
|
|
|
|
|
175
|
$self->{'host'} =~ s/^(([a-z]{0,5}\:\/\/)?([^\/]+))\/?$/$1/isg; |
|
127
|
|
|
|
|
|
|
|
|
128
|
17
|
|
|
|
|
71
|
my @tags = (); |
|
129
|
17
|
|
|
|
|
35
|
my $cnt_fn_tags = @_tags; |
|
130
|
17
|
100
|
|
|
|
67
|
my $cnt_known_tags = @{$self->{'tags'}} if($self->{'tags'}); |
|
|
9
|
|
|
|
|
18
|
|
|
131
|
17
|
50
|
66
|
|
|
71
|
@tags = @{$self->{'defaulttags'}} if($self->{'defaulttags'} && ($cnt_fn_tags <= 0 && $cnt_known_tags <= 0)); |
|
|
0
|
|
66
|
|
|
0
|
|
|
132
|
|
|
|
|
|
|
|
|
133
|
17
|
|
|
|
|
26
|
foreach my $t(@{$self->{'tags'}} ){ |
|
|
17
|
|
|
|
|
56
|
|
|
134
|
11
|
|
|
|
|
21
|
push(@tags, $t); |
|
135
|
|
|
|
|
|
|
} |
|
136
|
17
|
100
|
|
|
|
50
|
if($cnt_fn_tags > 0){ |
|
137
|
6
|
|
|
|
|
11
|
foreach my $t(@_tags){ |
|
138
|
8
|
|
|
|
|
15
|
push(@tags, $t); |
|
139
|
|
|
|
|
|
|
} |
|
140
|
|
|
|
|
|
|
|
|
141
|
|
|
|
|
|
|
} |
|
142
|
|
|
|
|
|
|
|
|
143
|
17
|
|
100
|
|
|
328
|
my $type = $_type || $self->{'type'} || ""; |
|
144
|
17
|
|
|
|
|
29
|
my $message; |
|
145
|
17
|
100
|
|
|
|
52
|
if (ref($_message) eq "HASH") { |
|
146
|
|
|
|
|
|
|
|
|
147
|
5
|
100
|
|
|
|
28
|
if($_message->{type}){ |
|
148
|
1
|
50
|
|
|
|
4
|
$type = $_message->{type} if($type eq ''); |
|
149
|
1
|
|
|
|
|
2
|
delete $_message->{type}; |
|
150
|
|
|
|
|
|
|
} |
|
151
|
5
|
100
|
|
|
|
19
|
if($_message->{tags}){ |
|
152
|
1
|
|
|
|
|
1
|
foreach my $t(@{$_message->{tags}}){ |
|
|
1
|
|
|
|
|
3
|
|
|
153
|
2
|
|
|
|
|
3
|
push(@tags, $t); |
|
154
|
|
|
|
|
|
|
}; |
|
155
|
1
|
|
|
|
|
2
|
delete $_message->{tags}; |
|
156
|
|
|
|
|
|
|
} |
|
157
|
|
|
|
|
|
|
# if there is only one message as string: |
|
158
|
5
|
100
|
|
|
|
20
|
if( ref($_message->{message}) eq '' ){ |
|
159
|
3
|
|
|
|
|
7
|
$message = $_message->{message}; |
|
160
|
|
|
|
|
|
|
} else { |
|
161
|
2
|
|
|
|
|
4
|
$message = $_message; |
|
162
|
2
|
50
|
|
|
|
9
|
if($self->{'connectiontype'} eq 'GET'){ |
|
163
|
0
|
0
|
|
|
|
0
|
warn("This message can not be send via get. Set the Type to POST automaticly for this message.") if $self->{'verbose'}; |
|
164
|
0
|
|
|
|
|
0
|
$self->{'connectiontype'} = 'POST'; |
|
165
|
|
|
|
|
|
|
} |
|
166
|
|
|
|
|
|
|
} |
|
167
|
|
|
|
|
|
|
} |
|
168
|
|
|
|
|
|
|
|
|
169
|
17
|
|
|
|
|
23
|
my $result; |
|
170
|
17
|
100
|
|
|
|
67
|
if($self->{'connectiontype'} eq 'GET'){ |
|
|
|
50
|
|
|
|
|
|
|
|
|
0
|
|
|
|
|
|
|
171
|
14
|
|
|
|
|
16
|
my $query; |
|
172
|
14
|
100
|
|
|
|
43
|
$query .= "message=". $message if($message); |
|
173
|
14
|
|
|
|
|
28
|
my $anz_tags = @tags; |
|
174
|
14
|
100
|
|
|
|
38
|
if($anz_tags > 0){ |
|
175
|
10
|
100
|
66
|
|
|
37
|
$query .= "&" if($message && length($message) > 0); |
|
176
|
10
|
|
|
|
|
18
|
$query .= 'tags='; |
|
177
|
10
|
|
|
|
|
29
|
$query .= join(",", uniq(@tags)); |
|
178
|
10
|
100
|
|
|
|
48
|
$query .= "&" if(length($type) > 0) |
|
179
|
|
|
|
|
|
|
} |
|
180
|
14
|
100
|
|
|
|
49
|
$query .= "etype=". $type if(length($type) > 0); |
|
181
|
|
|
|
|
|
|
|
|
182
|
14
|
50
|
|
|
|
70
|
if($self->{'host'} =~ /^test/){ |
|
183
|
14
|
|
|
|
|
43
|
$result = $self->{'host'}."/log?". $query; |
|
184
|
|
|
|
|
|
|
} else { |
|
185
|
0
|
|
|
|
|
0
|
$result = $browser->get($self->{'host'}."/log?". $query); |
|
186
|
|
|
|
|
|
|
} |
|
187
|
|
|
|
|
|
|
} |
|
188
|
|
|
|
|
|
|
elsif($self->{'connectiontype'} eq 'POST'){ |
|
189
|
3
|
|
|
|
|
6
|
my %data; |
|
190
|
3
|
|
|
|
|
8
|
$data{'etype'} = $type; |
|
191
|
3
|
|
|
|
|
9
|
$data{'tags'} = \@tags; |
|
192
|
3
|
|
|
|
|
8
|
$data{'message'} = $message; |
|
193
|
|
|
|
|
|
|
|
|
194
|
3
|
50
|
|
|
|
15
|
if($self->{'host'} =~ /^test/){ |
|
195
|
3
|
|
|
|
|
72
|
$result = encode_json(\%data); |
|
196
|
|
|
|
|
|
|
} else { |
|
197
|
0
|
|
|
|
|
0
|
$result = $browser->post($self->{'host'}."/log" |
|
198
|
|
|
|
|
|
|
, encode_json \%data |
|
199
|
|
|
|
|
|
|
); |
|
200
|
|
|
|
|
|
|
} |
|
201
|
|
|
|
|
|
|
} elsif($self->{'connectiontype'} eq 'UDP'){ |
|
202
|
0
|
|
|
|
|
0
|
die("UDP is not supported, yet"); |
|
203
|
|
|
|
|
|
|
} else { |
|
204
|
0
|
0
|
|
|
|
0
|
warn("Connection type ". $self->{'connectiontype'} |
|
205
|
|
|
|
|
|
|
." is not supportet.\nSet the Type to POST automaticly for this message.") |
|
206
|
|
|
|
|
|
|
if $self->{'verbose'}; |
|
207
|
0
|
|
|
|
|
0
|
$self->setConnectionType("POST"); |
|
208
|
0
|
|
|
|
|
0
|
$result = $self->tell($_message, $_type, @_tags); |
|
209
|
|
|
|
|
|
|
} |
|
210
|
17
|
|
|
|
|
457
|
return $result; |
|
211
|
|
|
|
|
|
|
} |
|
212
|
|
|
|
|
|
|
|
|
213
|
|
|
|
|
|
|
### PRIVATES ### |
|
214
|
|
|
|
|
|
|
|
|
215
|
|
|
|
|
|
|
sub uniq { |
|
216
|
10
|
|
|
10
|
0
|
12
|
return keys %{{ map { $_ => 1 } @_ }}; |
|
|
10
|
|
|
|
|
21
|
|
|
|
21
|
|
|
|
|
81
|
|
|
217
|
|
|
|
|
|
|
} |
|
218
|
|
|
|
|
|
|
|
|
219
|
|
|
|
|
|
|
1; |
|
220
|
|
|
|
|
|
|
__END__ |