Quiq/Http/Client/Lwp.pm

filter: Statementstmt 52.3% 22 / 42 Branchbran 0.0% 0 / 12 Conditioncond 0.0% 0 / 3 MC/DCmcdc 0.0% 0 / 2 Subroutinesub 87.5% 7 / 8 Podpod 100% 1 / 1 totaltotal 44.1% 30 / 68 CC 8 SCAR 36.6
CC
8
Cov
39%
get
72.0
BEGIN
1.0
BEGIN
1.0
CRAP 38.9
« Quiq/Database/Connection.pm ↑ Summary Quiq/Html/Table/List.pm »
1 # -----------------------------------------------------------------------------
2  
3 =encoding utf8
4  
5 =head1 NAME
6  
7 Quiq::Http::Client::Lwp - HTTP Operationen
8  
9 =head1 BASE CLASS
10  
11 L<Quiq::Object>
12  
13 =cut
14  
15 # -----------------------------------------------------------------------------
16  
17 package Quiq::Http::Client::Lwp;
18 1 ▶use base qw/Quiq::Object/;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 1 ▶use v5.10;
Subroutine BEGIN: called CC=1 SCAR=0.0
21 1 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
22 1 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
23  
24 1 our $VERSION = '1.240';
25  
26 1 ▶use Quiq::Option;
Subroutine BEGIN: called CC=1 SCAR=0.0
27 1 ▶use LWP::UserAgent ();
Subroutine BEGIN: called CC=1 SCAR=0.0
28 1 ▶use HTTP::Request ();
Subroutine BEGIN: called CC=1 SCAR=0.0
29  
30 # -----------------------------------------------------------------------------
31  
32 =head1 METHODS
33  
34 =head2 Klassenmethoden
35  
36 =head3 get() - Führe GET-Request aus
37  
38 =head4 Synopsis
39  
40 $data = $class->get($url,@opt);
41  
42 =head4 Options
43  
44 =over 4
45  
46 =item -debug => $bool (Default: 1)
47  
48 Gib Request auf STDOUT aus.
49  
50 =item -header => $bool (Default: 0)
51  
52 Ergänze die Antwort um die vom Server gesetzten Response-Header.
53 Per Default wird nur der Rumpf der HTTP-Antwort geliefert.
54  
55 =item -redirect => $bool (Default: 1)
56  
57 Führe Redirection automatisch aus.
58  
59 =item -sloppy => $bool (Default: 0)
60  
61 Wirf im Fehlerfall keine Exception, sondern liefere die Fehlerantwort.
62  
63 =item -timeout => $n (Default: 0)
64  
65 Timeout.
66  
67 =back
68  
69 =head4 Description
70  
71 Führe HTTP-Request für URL $url aus und liefere die vom
72 Server gelieferte Antwort zurück.
73  
74 =cut
75  
76 # -----------------------------------------------------------------------------
77  
78 0 ▶sub get {
Subroutine get: not called CC=8 SCAR=42.8
Pod documented
79 0 my $class = shift;
80 0 my $url = shift;
81 # @_: @opt
82  
83 0 my $debug = 0;
84 0 my $header = 0;
85 0 my $redirect = 1;
86 0 my $sloppy = 1;
87 0 my $timeout = 0;
88  
89 0 ▶ if (@_) {
Branch: 1 branch
BranchTrueFalseTotal
if (@_) 0 0 0
90 0 Quiq::Option->extract(\@_,
91 -debug => \$debug,
92 -header => \$header,
93 -redirect => \$redirect,
94 -sloppy => \$sloppy,
95 -timeout => \$timeout,
96 );
97 }
98  
99 0 my $ua = LWP::UserAgent->new;
100 0 $ua->env_proxy; # Lies etwaiges Proxy-Environment
101 0 ▶ if ($timeout) {
Branch: 1 branch
BranchTrueFalseTotal
if ($timeout) 0 0 0
102 0 $ua->timeout($timeout);
103 }
104 0 my $req = HTTP::Request->new(GET=>$url);
105  
106 0 ▶ if ($debug) {
Branch: 1 branch
BranchTrueFalseTotal
if ($debug) 0 0 0
107 0 print $req->as_string;
108 }
109  
110 0 ▶ my $res = $redirect? $ua->request($req): $ua->simple_request($req);
Branch: 1 branch
BranchTrueFalseTotal
$redirect ? : 0 0 0
111 0 ▶ if ($res->is_error && !$sloppy) {
Branch: 1 branch
BranchTrueFalseTotal
if ($res->is_error and not $sloppy) 0 0 0
Condition0%0/3
$res->is_error and not $sloppy
!ll&&!rl&&r
000
MC/DC0%0/2
$res->is_error and not $sloppy
$res->is_error not $sloppy
Truth table0%0/3
A and not(B)
A= $res->is_errorB= not $sloppy
ABresult
0X0
100
111
112 0 $class->throw(
113 'HTTP-00001: GET Request failed',
114 Url => $url,
115 StatusLine => $res->status_line,
116 );
117 }
118  
119 0 ▶ return $header? $res->as_string: $res->content;
Branch: 1 branch
BranchTrueFalseTotal
$header ? : 0 0 0
120 }
121  
122 # -----------------------------------------------------------------------------
123  
124 =head1 VERSION
125  
126 1.240
127  
128 =head1 AUTHOR
129  
130 Frank Seitz, L<http://fseitz.de/>
131  
132 =head1 COPYRIGHT
133  
134 Copyright (C) 2026 Frank Seitz
135  
136 =head1 LICENSE
137  
138 This code is free software; you can redistribute it and/or modify
139 it under the same terms as Perl itself.
140  
141 =cut
142  
143 # -----------------------------------------------------------------------------
144  
145 1 1;
146  
147 # eof
« Quiq/Database/Connection.pm ↑ Summary Quiq/Html/Table/List.pm »