| line |
stmt |
bran |
cond |
sub |
pod |
time |
code |
|
1
|
|
|
|
|
|
|
package Lab::Moose::Connection::HTTP; |
|
2
|
|
|
|
|
|
|
$Lab::Moose::Connection::HTTP::VERSION = '3.881'; |
|
3
|
|
|
|
|
|
|
#ABSTRACT: Connection with Http requests |
|
4
|
|
|
|
|
|
|
|
|
5
|
1
|
|
|
1
|
|
2455
|
use v5.20; |
|
|
1
|
|
|
|
|
4
|
|
|
6
|
|
|
|
|
|
|
|
|
7
|
1
|
|
|
1
|
|
6
|
use Moose; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
9
|
|
|
8
|
1
|
|
|
1
|
|
7272
|
use MooseX::Params::Validate; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
10
|
|
|
9
|
1
|
|
|
1
|
|
584
|
use Moose::Util::TypeConstraints qw(enum); |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
11
|
|
|
10
|
1
|
|
|
1
|
|
544
|
use Carp; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
68
|
|
|
11
|
|
|
|
|
|
|
|
|
12
|
1
|
|
|
1
|
|
7
|
use Lab::Moose::Instrument qw/timeout_param read_length_param/; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
68
|
|
|
13
|
|
|
|
|
|
|
|
|
14
|
1
|
|
|
1
|
|
8
|
use LWP::UserAgent; |
|
|
1
|
|
|
|
|
4
|
|
|
|
1
|
|
|
|
|
33
|
|
|
15
|
1
|
|
|
1
|
|
6
|
use HTTP::Request; |
|
|
1
|
|
|
|
|
3
|
|
|
|
1
|
|
|
|
|
23
|
|
|
16
|
|
|
|
|
|
|
|
|
17
|
1
|
|
|
1
|
|
6
|
use namespace::autoclean; |
|
|
1
|
|
|
|
|
2
|
|
|
|
1
|
|
|
|
|
8
|
|
|
18
|
|
|
|
|
|
|
|
|
19
|
|
|
|
|
|
|
|
|
20
|
|
|
|
|
|
|
has ip => ( |
|
21
|
|
|
|
|
|
|
is => 'ro', |
|
22
|
|
|
|
|
|
|
isa => 'Str', |
|
23
|
|
|
|
|
|
|
required => 1, |
|
24
|
|
|
|
|
|
|
reader => 'get_ip', |
|
25
|
|
|
|
|
|
|
); |
|
26
|
|
|
|
|
|
|
|
|
27
|
|
|
|
|
|
|
has port => ( |
|
28
|
|
|
|
|
|
|
is => 'ro', |
|
29
|
|
|
|
|
|
|
isa => 'Lab::Moose::PosNum', |
|
30
|
|
|
|
|
|
|
required => 1, |
|
31
|
|
|
|
|
|
|
reader => 'get_port', |
|
32
|
|
|
|
|
|
|
); |
|
33
|
|
|
|
|
|
|
|
|
34
|
|
|
|
|
|
|
has ua => ( |
|
35
|
|
|
|
|
|
|
is => 'ro', |
|
36
|
|
|
|
|
|
|
isa => 'Any', |
|
37
|
|
|
|
|
|
|
builder => '_build_ua', |
|
38
|
|
|
|
|
|
|
); |
|
39
|
|
|
|
|
|
|
|
|
40
|
|
|
|
|
|
|
sub _build_ua { |
|
41
|
0
|
|
|
0
|
|
|
return LWP::UserAgent->new(); |
|
42
|
|
|
|
|
|
|
} |
|
43
|
|
|
|
|
|
|
|
|
44
|
|
|
|
|
|
|
sub Read { |
|
45
|
0
|
|
|
0
|
0
|
|
my ( $self, %args ) = validated_hash( |
|
46
|
|
|
|
|
|
|
\@_, |
|
47
|
|
|
|
|
|
|
endpoint => { isa => 'Str' }, |
|
48
|
|
|
|
|
|
|
); |
|
49
|
0
|
|
|
|
|
|
my $endpoint = $args{'endpoint'}; |
|
50
|
|
|
|
|
|
|
|
|
51
|
0
|
|
|
|
|
|
my $url = "http://". $self->get_ip(). ":" . $self->get_port() . $endpoint; |
|
52
|
0
|
|
|
|
|
|
my $req = HTTP::Request->new( 'GET', $url ); |
|
53
|
|
|
|
|
|
|
|
|
54
|
0
|
|
|
|
|
|
return $self->ua->request( $req ); |
|
55
|
|
|
|
|
|
|
} |
|
56
|
|
|
|
|
|
|
|
|
57
|
|
|
|
|
|
|
sub Write { |
|
58
|
0
|
|
|
0
|
0
|
|
my ( $self, %args ) = validated_hash( |
|
59
|
|
|
|
|
|
|
\@_, |
|
60
|
|
|
|
|
|
|
endpoint => { isa => 'Str' }, |
|
61
|
|
|
|
|
|
|
body => { isa => 'Str' }, |
|
62
|
|
|
|
|
|
|
); |
|
63
|
0
|
|
|
|
|
|
my $endpoint = $args{'endpoint'}; |
|
64
|
0
|
|
|
|
|
|
my $body = $args{'body'}; |
|
65
|
|
|
|
|
|
|
|
|
66
|
0
|
|
|
|
|
|
my $url = "http://". $self->get_ip(). ":" . $self->get_port() . $endpoint; |
|
67
|
0
|
|
|
|
|
|
my $req = HTTP::Request->new( 'POST', $url); |
|
68
|
0
|
|
|
|
|
|
$req->header( 'Content-Type' => 'application/json' ); |
|
69
|
0
|
|
|
|
|
|
$req->content( $body ); |
|
70
|
|
|
|
|
|
|
|
|
71
|
0
|
|
|
|
|
|
return $self->ua->request( $req ); |
|
72
|
|
|
|
|
|
|
} |
|
73
|
|
|
|
|
|
|
|
|
74
|
|
|
|
0
|
0
|
|
sub Clear { |
|
75
|
|
|
|
|
|
|
|
|
76
|
|
|
|
|
|
|
} |
|
77
|
|
|
|
|
|
|
|
|
78
|
|
|
|
|
|
|
with 'Lab::Moose::Connection'; |
|
79
|
|
|
|
|
|
|
|
|
80
|
|
|
|
|
|
|
__PACKAGE__->meta->make_immutable; |
|
81
|
|
|
|
|
|
|
|
|
82
|
|
|
|
|
|
|
1; |
|
83
|
|
|
|
|
|
|
|
|
84
|
|
|
|
|
|
|
__END__ |
|
85
|
|
|
|
|
|
|
|
|
86
|
|
|
|
|
|
|
=pod |
|
87
|
|
|
|
|
|
|
|
|
88
|
|
|
|
|
|
|
=encoding UTF-8 |
|
89
|
|
|
|
|
|
|
|
|
90
|
|
|
|
|
|
|
=head1 NAME |
|
91
|
|
|
|
|
|
|
|
|
92
|
|
|
|
|
|
|
Lab::Moose::Connection::HTTP - Connection with Http requests |
|
93
|
|
|
|
|
|
|
|
|
94
|
|
|
|
|
|
|
=head1 VERSION |
|
95
|
|
|
|
|
|
|
|
|
96
|
|
|
|
|
|
|
version 3.881 |
|
97
|
|
|
|
|
|
|
|
|
98
|
|
|
|
|
|
|
=head1 SYNOPSIS |
|
99
|
|
|
|
|
|
|
|
|
100
|
|
|
|
|
|
|
use Lab::Moose |
|
101
|
|
|
|
|
|
|
|
|
102
|
|
|
|
|
|
|
my $instrument = instrument( |
|
103
|
|
|
|
|
|
|
type => 'random_instrument', |
|
104
|
|
|
|
|
|
|
connection_type => 'HTTP', |
|
105
|
|
|
|
|
|
|
connection_options => {ip => 172.22.11.2, port => 8002}, |
|
106
|
|
|
|
|
|
|
); |
|
107
|
|
|
|
|
|
|
|
|
108
|
|
|
|
|
|
|
=head1 DESCRIPTION |
|
109
|
|
|
|
|
|
|
|
|
110
|
|
|
|
|
|
|
This module provides a connection for devices with an integrated web |
|
111
|
|
|
|
|
|
|
server. |
|
112
|
|
|
|
|
|
|
|
|
113
|
|
|
|
|
|
|
=head1 COPYRIGHT AND LICENSE |
|
114
|
|
|
|
|
|
|
|
|
115
|
|
|
|
|
|
|
This software is copyright (c) 2023 by the Lab::Measurement team; in detail: |
|
116
|
|
|
|
|
|
|
|
|
117
|
|
|
|
|
|
|
Copyright 2023 Andreas K. Huettel, Mia Schambeck |
|
118
|
|
|
|
|
|
|
|
|
119
|
|
|
|
|
|
|
|
|
120
|
|
|
|
|
|
|
This is free software; you can redistribute it and/or modify it under |
|
121
|
|
|
|
|
|
|
the same terms as the Perl 5 programming language system itself. |
|
122
|
|
|
|
|
|
|
|
|
123
|
|
|
|
|
|
|
=cut |