Moose/Connection/HTTP.pm

filter: Statementstmt 70.2% 33 / 47 Branchbran n/a Conditioncond n/a MC/DCmcdc n/a Subroutinesub 69.2% 9 / 13 Podpod 0.0% 0 / 3 totaltotal 66.6% 42 / 63 SCAR 0.3
CC
1
Cov
70%
_build_ua
2.0
Read
2.0
Write
2.0
CRAP 1.0
« Moose/Instrument/Agilent34410A.pm ↑ Summary Moose/Instrument/Keysight34470A.pm »
1 package Lab::Moose::Connection::HTTP;
2 1 $Lab::Moose::Connection::HTTP::VERSION = '3.881';
3 #ABSTRACT: Connection with Http requests
4  
5 1 ▶use v5.20;
Subroutine BEGIN: called CC=1 SCAR=0.0
6  
7 1 ▶use Moose;
Subroutine BEGIN: called CC=1 SCAR=0.0
8 1 ▶use MooseX::Params::Validate;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 1 ▶use Moose::Util::TypeConstraints qw(enum);
Subroutine BEGIN: called CC=1 SCAR=0.0
10 1 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
11  
12 1 ▶use Lab::Moose::Instrument qw/timeout_param read_length_param/;
Subroutine BEGIN: called CC=1 SCAR=0.0
13  
14 1 ▶use LWP::UserAgent;
Subroutine BEGIN: called CC=1 SCAR=0.0
15 1 ▶use HTTP::Request;
Subroutine BEGIN: called CC=1 SCAR=0.0
16  
17 1 ▶use namespace::autoclean;
Subroutine BEGIN: called CC=1 SCAR=0.0
18  
19  
20 1 has ip => (
21 is => 'ro',
22 isa => 'Str',
23 required => 1,
24 reader => 'get_ip',
25 );
26  
27 1 has port => (
28 is => 'ro',
29 isa => 'Lab::Moose::PosNum',
30 required => 1,
31 reader => 'get_port',
32 );
33  
34 1 has ua => (
35 is => 'ro',
36 isa => 'Any',
37 builder => '_build_ua',
38 );
39  
40 sub _build_ua {
41 0 ▶ return LWP::UserAgent->new();
Subroutine _build_ua: not called CC=1 SCAR=6.9
42 }
43  
44 sub Read {
45 0 ▶ my ( $self, %args ) = validated_hash(
Subroutine Read: not called CC=1 SCAR=6.9
Pod undocumented
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 ▶ my ( $self, %args ) = validated_hash(
Subroutine Write: not called CC=1 SCAR=6.9
Pod undocumented
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 ▶sub Clear {
Subroutine Clear: not called CC=1 SCAR=0.0
Pod undocumented
75  
76 }
77  
78 1 with 'Lab::Moose::Connection';
79  
80 1 __PACKAGE__->meta->make_immutable;
81  
82 1 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
« Moose/Instrument/Agilent34410A.pm ↑ Summary Moose/Instrument/Keysight34470A.pm »