DAV/Comms.pm

filter: Statementstmt 49.2% 98 / 199 Branchbran 30.6% 19 / 62 Conditioncond 12.7% 6 / 47 MC/DCmcdc 7.1% 2 / 28 Subroutinesub 55.5% 20 / 36 Podpod 0.0% 0 / 12 totaltotal 37.7% 145 / 384 CC 50 SCAR 49.7
CC
50
Cov
40%
do_http_request
512.0
get_basic_credentials
20.7
add_headers
20.0
CRAP 143.8
↑ Summary DAV/Resource.pm »
1 package HTTP::DAV::Comms;
2  
3 4 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
4 4 ▶use vars qw($VERSION $DEBUG);
Subroutine BEGIN: called CC=1 SCAR=0.0
5  
6 4 $VERSION = q(0.23);
7  
8 4 ▶use HTTP::DAV::Utils;
Subroutine BEGIN: called CC=1 SCAR=0.0
9 4 ▶use HTTP::DAV::Response;
Subroutine BEGIN: called CC=1 SCAR=0.0
10 4 ▶use LWP;
Subroutine BEGIN: called CC=1 SCAR=0.0
11 4 ▶use URI;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 ####
14 # Construct a new object and initialize it
15 1 ▶sub new {
Subroutine new: called CC=2 SCAR=7.4
Pod undocumented
16 1 my $class = shift;
17 1 ▶ my $self = bless {}, ref($class) || $class;
Condition33%1/3
ref $class || $class
l!l&&r!l&&!r
010
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table33%1/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
18  
19 #print Data::Dumper->Dump( [$self] , [ '$self' ] );
20 1 $self->_init(@_);
21 1 return $self;
22 }
23  
24 # Requires a reusable HTTP Agent.
25 # and some default headers, like, the user agent
26 1 ▶sub _init {
Subroutine _init: called CC=1 SCAR=0.0
27 1 my ( $self, @p ) = @_;
28 1 my ( $headers, $useragent )
29 = HTTP::DAV::Utils::rearrange( [ 'HEADERS', 'USERAGENT' ], @p );
30  
31 # This is cached in this object here so that each http request
32 # doesn't have to invoke a new useragent.
33 1 $self->init_user_agent($useragent);
34  
35 1 $self->set_headers($headers);
36 }
37  
38 1 ▶sub init_user_agent {
Subroutine init_user_agent: called CC=2 SCAR=7.4
Pod undocumented
39 1 my ( $self, $useragent ) = @_;
40 1 ▶ if ( defined $useragent ) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $useragent) { } 0 1 1
41 0 $self->{_user_agent} = $useragent;
42 }
43 else {
44 1 $self->{_user_agent} = HTTP::DAV::UserAgent->new;
45 1 $self->set_agent("DAV.pm/v$HTTP::DAV::VERSION");
46 }
47 }
48  
49 ####
50 # GET/SET
51  
52 # Sets a User-Agent as specified by user or as the default
53 1 ▶sub set_agent {
Subroutine set_agent: called CC=1 SCAR=0.0
Pod undocumented
54 1 my ( $self, $agent ) = @_;
55 1 $self->{_user_agent}->agent($agent);
56 }
57  
58 0 ▶sub set_header {
Subroutine set_header: not called CC=2 SCAR=17.9
Pod undocumented
59 0 my ( $self, $var, $val ) = @_;
60 0 ▶ $self->set_headers() unless defined $self->{_headers};
Branch: 1 branch
BranchTrueFalseTotal
unless defined $self->{"_headers"} 0 0 0
61 0 $self->{_headers}->header( $var, $val );
62 }
63  
64 0 ▶sub get_user_agent { $_[0]->{_user_agent}; }
Subroutine get_user_agent: not called CC=1 SCAR=6.9
Pod undocumented
65 0 ▶sub get_headers { $_[0]->{_headers}; }
Subroutine get_headers: not called CC=1 SCAR=6.9
Pod undocumented
66  
67 1 ▶sub set_headers {
Subroutine set_headers: called CC=6 SCAR=21.2
Pod undocumented
68 1 my ( $self, $headers ) = @_;
69  
70 1 my $dav_headers;
71  
72 1 ▶ if ( defined $headers && ref($headers) eq "HTTP::Headers" ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $headers and ref $headers eq 'HTTP::Headers') { } 0 1 1
elsif (defined $headers and ref $headers eq 'HASH') { } 1 0 1
Condition33%1/3
defined $headers and ref $headers eq "HTTP::Headers"
!ll&&!rl&&r
010
MC/DC0%0/2
defined $headers and ref $headers eq "HTTP::Headers"
defined $headers ref $headers eq "HTTP::Headers"
Truth table33%1/3
A and B
A= defined $headersB= ref $headers eq "HTTP::Headers"
ABresult
0X0
100
111
73 0 $dav_headers = HTTP::DAV::Headers->clone($headers);
74 }
75 ▶ elsif (defined $headers && ref($headers) eq "HASH") {
Condition33%1/3
defined $headers and ref $headers eq "HASH"
!ll&&!rl&&r
001
MC/DC0%0/2
defined $headers and ref $headers eq "HASH"
defined $headers ref $headers eq "HASH"
Truth table33%1/3
A and B
A= defined $headersB= ref $headers eq "HASH"
ABresult
0X0
100
111
76 1 $dav_headers = HTTP::DAV::Headers->new();
77 1 for (keys %{ $headers }) {
78 1 $dav_headers->header($_ => $headers->{$_});
79 }
80 } else {
81 0 $dav_headers = HTTP::DAV::Headers->new;
82 }
83  
84 1 $self->{_headers} = $dav_headers;
85 }
86  
87 0 ▶sub _set_last_request { $_[0]->{_last_request} = $_[1]; }
Subroutine _set_last_request: not called CC=1 SCAR=6.9
88 0 ▶sub _set_last_response { $_[0]->{_last_response} = $_[1]; }
Subroutine _set_last_response: not called CC=1 SCAR=6.9
89  
90 # Save the Server: header line into this object instance
91 # We will want to use it later to workaround server bugs.
92 # For instance mod_dav has a bug in the Destination: header
93 # whereby it incorrectly throws "Bad Gateway" errors.
94 # The only way we can munge around this is if the copy() routine
95 # has some idea of the server it is talking to.
96 # So this routine stores the "Server: Apache..." line into a host:port hash (i.e. localhost:443).
97 # so $comms->_set_server_type( "host.org:443", "Apache/1.3.22 (Unix) DAV/1.0.2 ")
98 # yields
99 # %_server_type = {
100 # "host.org:443" => "Apache/1.3.22 (Unix) DAV/1.0.2 SSL"
101 # "host.org:80" => "Apache/1.3.22 (Unix) DAV/1.0.2 "
102 # };
103 # Note that this is an instance hash NOT a class hash.
104 # So each comms object will be learning independently.
105 0 ▶sub _set_server_type { $_[0]->{_server_type}{ $_[1] } = $_[2]; }
Subroutine _set_server_type: not called CC=1 SCAR=6.9
106  
107 # $server = $comms->get_server_type( "host.org:443" )
108 0 ▶sub get_server_type { $_[0]->{_server_type}{ $_[1] } }
Subroutine get_server_type: not called CC=1 SCAR=6.9
Pod undocumented
109  
110 # Returns an HTTP::Request object
111 0 ▶sub get_last_request { $_[0]->{_last_request}; }
Subroutine get_last_request: not called CC=1 SCAR=6.9
Pod undocumented
112  
113 # Returns an HTTP::DAV::Response object
114 0 ▶sub get_last_response { $_[0]->{_last_response}; }
Subroutine get_last_response: not called CC=1 SCAR=6.9
Pod undocumented
115  
116 ####
117 # Ensure there is a Host: header based on the URL
118 #
119 0 ▶sub do_http_request {
Subroutine do_http_request: not called CC=23 SCAR=62.4
Pod undocumented
120 0 my ( $self, @p ) = @_;
121  
122 0 my ( $method, $url, $newheaders, $content, $save_to, $callback_func,
123 $chunk )
124 = HTTP::DAV::Utils::rearrange(
125 [ 'METHOD', [ 'URL', 'URI' ], 'HEADERS', 'CONTENT',
126 'SAVE_TO', 'CALLBACK', 'CHUNK'
127 ],
128 @p
129 );
130  
131 # Method management
132 0 ▶ if ( !defined $method || $method eq "" || $method !~ /^\w+$/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if (not defined $method or $method eq "" or not $method =~ /^\w+$/) 0 0 0
Condition0%0/6
not defined $method or $method eq "" or not $method =~ /^\w+$/
l!l&&r!l&&!r
000
not defined $method or $method eq ""
l!l&&r!l&&!r
000
MC/DC0%0/3
not defined $method or $method eq "" or not $method =~ /^\w+$/
not defined $method $method eq "" not $method =~ /^\w+$/
Truth table0%0/4
not(A) or B or not(C)
A= not defined $methodB= $method eq ""C= not $method =~ /^\w+$/
ABCresult
1XX1
01X1
0011
0000
133 0 die "Incorrect HTTP Method specified in do_http_request: \"$method\"";
134 }
135 0 $method = uc($method);
136  
137 # URL management
138 0 my $url_obj;
139 0 ▶ $url_obj = ( ref($url) =~ /URI/ ) ? $url : URI->new($url);
Branch: 1 branch
BranchTrueFalseTotal
ref($url) =~ /URI/ ? : 0 0 0
140  
141 0 ▶ die "Comms: Bad HTTP Url: \"$url_obj\"\n"
Branch: 1 branch
BranchTrueFalseTotal
unless $url_obj->scheme =~ /^http/ 0 0 0
142 if ( $url_obj->scheme !~ /^http/ );
143  
144 # If you see user:pass detail embedded in the URL. Then get it out.
145 0 ▶ if ( $url_obj->userinfo ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($url_obj->userinfo) 0 0 0
146 $self->{_user_agent}
147 0 ->credentials( $url, undef, split( ':', $url_obj->userinfo ) );
148 }
149  
150 # Header management
151 0 ▶ if ( $newheaders && ref($newheaders) !~ /Headers/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($newheaders and not ref($newheaders) =~ /Headers/) 0 0 0
Condition0%0/3
$newheaders and not ref($newheaders) =~ /Headers/
!ll&&!rl&&r
000
MC/DC0%0/2
$newheaders and not ref($newheaders) =~ /Headers/
$newheaders not ref($newheaders) =~ /Headers/
Truth table0%0/3
A and not(B)
A= $newheadersB= not ref($newheaders) =~ /Headers/
ABresult
0X0
100
111
152 0 die "Bad headers object: "
153 . Data::Dumper->Dump( [$newheaders], ['$newheaders'] );
154 }
155  
156 0 my $headers = HTTP::DAV::Headers->new();
157 0 $headers->add_headers( $self->{_headers} );
158 0 $headers->add_headers($newheaders);
159  
160 #$headers->header("Host", $url_obj->host);
161 0 $headers->header( "Host", $url_obj->host_port );
162  
163 0 ▶ my $length = ($content) ? length($content) : 0;
Branch: 1 branch
BranchTrueFalseTotal
$content ? : 0 0 0
164 0 $headers->header( "Content-Length", $length );
165  
166 #print "HTTP HEADERS\n" . $self->get_headers->as_string . "\n\n";
167  
168 # It would be good if, at this stage, we could prefill the
169 # username and password values to prevent the client having
170 # to submit 2 requests, submit->401, submit->200
171 # This is the same kind of username, password remembering
172 # functionality that a browser performs.
173 #@userpass = $self->{_user_agent}->get_basic_credentials(undef, $url);
174  
175 # Add a Content-type of text/xml if the body has <?xml in it
176 0 ▶ if ( $content && $content =~ /<\?xml/i ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($content and $content =~ /<\?xml/i) 0 0 0
Condition0%0/3
$content and $content =~ /<\?xml/i
!ll&&!rl&&r
000
MC/DC0%0/2
$content and $content =~ /<\?xml/i
$content $content =~ /<\?xml/i
Truth table0%0/3
A and B
A= $contentB= $content =~ /<\?xml/i
ABresult
0X0
100
111
177 0 $headers->header( "Content-Type", "text/xml" );
178 }
179  
180 ####
181 # Do the HTTP call
182 0 my $req
183 = HTTP::Request->new( $method, $url_obj, $headers->to_http_headers,
184 $content );
185  
186 # It really bugs me, but libwww-perl doesn't honour this call.
187 # I'll leave it here anyway for future compatibility.
188 0 $req->protocol("HTTP/1.1");
189  
190 0 my $resp;
191  
192 # If a callback is set and it is a ref to a function
193 # then pass it through to LWP::UserAgent::request.
194 # See man page of LWP for more details of callback.
195 # callback is primarily used by DAV::get();
196 #
197 0 ▶ if ( defined $save_to && $save_to ne "" ) {
Branch: 2 branches
BranchTrueFalseTotal
if (defined $save_to and $save_to ne '') { } 0 0 0
elsif (ref($callback_func) =~ /CODE/) { } 0 0 0
Condition0%0/3
defined $save_to and $save_to ne ""
!ll&&!rl&&r
000
MC/DC0%0/2
defined $save_to and $save_to ne ""
defined $save_to $save_to ne ""
Truth table0%0/3
A and B
A= defined $save_toB= $save_to ne ""
ABresult
0X0
100
111
198 0 $resp = $self->{_user_agent}->request( $req, $save_to );
199 }
200 elsif ( ref($callback_func) =~ /CODE/ ) {
201 0 $resp = $self->{_user_agent}->request( $req, $callback_func, $chunk );
202 }
203 else {
204 0 $resp = $self->{_user_agent}->request($req);
205 }
206  
207 # Redirect loop {{{
208 0 my $code = $resp->code;
209 0 ▶ if ( $code == &HTTP::Status::RC_MOVED_PERMANENTLY
Branch: 1 branch
BranchTrueFalseTotal
if ($code == &HTTP::Status::RC_MOVED_PERMANENTLY or $code == &HTTP::Status::RC_MOVED_TEMPORARILY) 0 0 0
Condition0%0/3
$code == &HTTP::Status::RC_MOVED_PERMANENTLY or $code == &HTTP::Status::RC_MOVED_TEMPORARILY
l!l&&r!l&&!r
000
MC/DC0%0/2
$code == &HTTP::Status::RC_MOVED_PERMANENTLY or $code == &HTTP::Status::RC_MOVED_TEMPORARILY
$code == &HTTP::Status::RC_MOVED_PERMANENTLY $code == &HTTP::Status::RC_MOVED_TEMPORARILY
Truth table0%0/3
A or B
A= $code == &HTTP::Status::RC_MOVED_PERMANENTLYB= $code == &HTTP::Status::RC_MOVED_TEMPORARILY
ABresult
1X1
011
000
210 or $code == &HTTP::Status::RC_MOVED_TEMPORARILY )
211 {
212  
213 # And then we update the URL based on the Location:-header.
214 0 my ($referral_uri) = $resp->header('Location');
215 {
216  
217 # Some servers erroneously return a relative URL for redirects,
218 # so make it absolute if it not already is.
219 0 local $URI::ABS_ALLOW_RELATIVE_SCHEME = 1;
220 0 my $base = $resp->base;
221 0 $referral_uri
222 = $HTTP::URI_CLASS->new( $referral_uri, $base )->abs($base);
223 }
224  
225 # Check for loop in the redirects
226 0 my $count = 0;
227 0 my $r = $resp;
228 0 my $bad_loop = 0;
229 0 ▶ while ($r) {
Branch: 1 branch
BranchTrueFalseTotal
if ($r) 0 0 0
230 0 ▶ if ( ++$count > 13
Branch: 1 branch
BranchTrueFalseTotal
if (++$count > 13 or $r->request->url->as_string eq $referral_uri->as_string) 0 0 0
Condition0%0/3
++$count > 13 or $r->request->url->as_string eq $referral_uri->as_string
l!l&&r!l&&!r
000
MC/DC0%0/2
++$count > 13 or $r->request->url->as_string eq $referral_uri->as_string
++$count > 13 $r->request->url->as_string eq $referral_uri->as_string
Truth table0%0/3
A or B
A= ++$count > 13B= $r->request->url->as_string eq $referral_uri->as_string
ABresult
1X1
011
000
231 || $r->request->url->as_string eq $referral_uri->as_string )
232 {
233 0 $resp->header( "Client-Warning" => "Redirect loop detected" );
234  
235 #if ( $HTTP::DAV::DEBUG ) {
236 # print "*** CLIENT AND SERVER STUCK IN REDIRECT LOOP OR MOVED PERMENANTLY. $count. BREAKING ***\n";
237 # print "*** " . $r->request->url->as_string . "***\n";
238 # print "*** " . $referral_uri->as_string . "***\n";
239 #}
240 0 $bad_loop = 1;
241 0 last;
242 }
243 0 $r = $r->previous;
244 }
245 0 ▶ $resp = $self->do_http_request(
Branch: 1 branch
BranchTrueFalseTotal
unless $bad_loop 0 0 0
246 -method => $method,
247 -url => $referral_uri,
248 -headers => $newheaders,
249 -content => $content,
250 -saveto => $save_to,
251 -callback => $callback_func,
252 -chunk => $chunk,
253 ) unless $bad_loop;
254 }
255  
256 # }}}
257  
258 0 ▶ if ($HTTP::DAV::DEBUG > 1) {
Branch: 1 branch
BranchTrueFalseTotal
if ($HTTP::DAV::DEBUG > 1) 0 0 0
259 4 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
260 #open(DEBUG, ">&STDOUT") || die ("Can't open STDERR");;
261 0 my $old_umask = umask 0077;
262 0 open( DEBUG, ">>/tmp/perldav_debug.txt" );
263 0 print DEBUG "\n" . "-" x 70 . "\n";
264 0 print DEBUG localtime() . "\n";
265 0 print DEBUG "$method REQUEST>>\n" . $req->as_string();
266  
267 0 ▶ if ( $resp->headers->header('Content-Type') =~ /xml/ ) {
Branch: 1 branch
BranchTrueFalseTotal
if ($resp->headers->header('Content-Type') =~ /xml/) { } 0 0 0
268 0 my $body = $resp->as_string();
269 #$body =~ s/>\n*/>\n/g;
270 0 print DEBUG "$method XML RESPONSE>>$body\n";
271 #} elsif ( $resp->headers->header('Content-Type') =~ /text.html/ ) {
272 #require HTML::TreeBuilder;
273 #require HTML::FormatText;
274 #my $tree = HTML::TreeBuilder->new->parse($resp->content());
275 #my $formatter = HTML::FormatText->new(leftmargin => 0);
276 #print DEBUG "$method RESPONSE (HTML)>>\n" . $resp->headers->as_string();
277 #print DEBUG $formatter->format($tree);
278 }
279 else {
280 0 print DEBUG "$method RESPONSE>>\n" . $resp->as_string();
281 }
282 0 close DEBUG;
283 0 umask $old_umask;
284 }
285  
286 ####
287 # Copy the HTTP:Response into a HTTP::DAV::Response. It specifically
288 # knows details about DAV Status Codes and their associated
289 # messages.
290 0 my $dav_resp = HTTP::DAV::Response->clone_http_resp($resp);
291 0 $dav_resp->set_message( $resp->code );
292  
293 ####
294 # Save the req and resp objects as the "last used"
295 0 $self->_set_last_request($req);
296 0 $self->_set_last_response($dav_resp);
297  
298 0 $self->_set_server_type( $url_obj->host_port,
299 $dav_resp->headers->header("Server") );
300  
301 0 return $dav_resp;
302 }
303  
304 0 ▶sub credentials {
Subroutine credentials: not called CC=1 SCAR=6.9
Pod undocumented
305 0 my ( $self, @p ) = @_;
306 0 my ( $user, $pass, $url, $realm )
307 = HTTP::DAV::Utils::rearrange( [ 'USER', 'PASS', 'URL', 'REALM' ],
308 @p );
309 0 $self->{_user_agent}->credentials( $url, $realm, $user, $pass );
310 }
311  
312 ###########################################################################
313 # We make our own specialization of LWP::UserAgent
314 # called HTTP::DAV::UserAgent.
315 # The variations allow us to have various levels of protection.
316 # Where the user hasn't specified what Realm to use we pass the
317 # userpass combo to all realms of that host
318 # Also this UserAgent remembers a user on the next request.
319 # The standard UserAgent doesn't.
320 {
321  
322 package HTTP::DAV::UserAgent;
323  
324 4 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
325 4 ▶ use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
326  
327 4 @ISA = qw(LWP::UserAgent);
328  
329 #require LWP::UserAgent;
330  
331 3 ▶ sub new {
Subroutine new: called CC=1 SCAR=0.0
332 3 my $self = LWP::UserAgent::new(@_);
333 3 $self->agent("lwp-request/$HTTP::DAV::VERSION");
334 3 $self;
335 }
336  
337 7 ▶ sub credentials {
Subroutine credentials: called CC=12 SCAR=24.9
338 7 my ( $self, $netloc, $realm, $user, $pass ) = @_;
339  
340 7 ▶ $realm = 'default' unless $realm;
Branch: 1 branch
BranchTrueFalseTotal
unless $realm 0 7 7
341  
342 7 ▶ if ($netloc) {
Branch: 1 branch
BranchTrueFalseTotal
if ($netloc) { } 7 0 7
343 7 ▶ $netloc = "http://$netloc" unless $netloc =~ m{^http};
Branch: 1 branch
BranchTrueFalseTotal
unless $netloc =~ /^http/ 7 0 7
344 7 my $uri = URI->new($netloc);
345 7 $netloc = $uri->host_port;
346 }
347 else {
348 0 $netloc = 'default';
349 }
350  
351 {
352 4 ▶ no warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
353 7 ▶ if ($HTTP::DAV::DEBUG > 2) {
Branch: 1 branch
BranchTrueFalseTotal
if ($HTTP::DAV::DEBUG > 2) 4 3 7
354 4 ▶ if (defined $user) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $user) { } 1 3 4
355 1 print "Setting auth details for $netloc, $realm to '$user', '$pass'\n";
356 }
357 else {
358 3 print "Resetting user and password for $netloc, $realm\n";
359 }
360 }
361 }
362  
363 # Pay attention to not autovivify the hash value (RT #47500)
364 7 my $cred;
365 7 ▶ if (
Branch: 1 branch
BranchTrueFalseTotal
if (exists $self->{'basic_authentication'}{$netloc} and exists $self->{'basic_authentication'}{$netloc}{$realm}) { } 3 4 7
Condition100%3/3
exists $self->{"basic_authentication"}{$netloc} and exists $self->{"basic_authentication"}{$netloc}{$realm}
!ll&&!rl&&r
313
MC/DC100%2/2
exists $self->{"basic_authentication"}{$netloc} and exists $self->{"basic_authentication"}{$netloc}{$realm}
exists $self->{"basic_authentication"}{$netloc} exists $self->{"basic_authentication"}{$netloc}{$realm}
Truth table100%3/3
A and B
A= exists $self->{"basic_authentication"}{$netloc}B= exists $self->{"basic_authentication"}{$netloc}{$realm}
ABresult
0X0
100
111
366 exists $self->{basic_authentication}->{$netloc} &&
367 exists $self->{basic_authentication}->{$netloc}->{$realm}) {
368 3 $cred = $self->{basic_authentication}->{$netloc}->{$realm};
369 }
370 else {
371 4 $cred = [];
372 }
373  
374 # Replace with new credentials (if any)
375 7 ▶ if (defined $user) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $user) 2 5 7
376 2 $self->{basic_authentication}->{$netloc}->{$realm}->[0] = $user;
377 2 $self->{basic_authentication}->{$netloc}->{$realm}->[1] = $pass;
378 2 $cred = $self->{basic_authentication}->{$netloc}->{$realm};
379 }
380  
381 # Return current values
382 7 ▶ if (! @{$cred}) {
Branch: 1 branch
BranchTrueFalseTotal
unless (@{$cred;}) 2 5 7
383 2 ▶ return wantarray ? () : undef;
Branch: 1 branch
BranchTrueFalseTotal
wantarray ? : 0 2 2
384 }
385  
386 # User/password pair
387 5 ▶ if (wantarray) { return @{$cred} }
Branch: 1 branch
BranchTrueFalseTotal
if (wantarray) 2 3 5
388  
389 # As string: 'user:password'
390 3 return join( ':', @{$cred} );
391 }
392  
393 0 ▶ sub get_basic_credentials {
Subroutine get_basic_credentials: not called CC=5 SCAR=30.3
394 0 my ( $self, $realm, $uri ) = @_;
395  
396 0 $uri = HTTP::DAV::Utils::make_uri($uri);
397 0 my $netloc = $uri->host_port;
398  
399 0 my $userpass;
400 {
401 0 ▶ no warnings; # SHUTUP with your silly warnings.
Subroutine BEGIN: called CC=1 SCAR=0.2
402 $userpass
403 = $self->{'basic_authentication'}{$netloc}{$realm}
404 || $self->{'basic_authentication'}{default}{$realm}
405 || $self->{'basic_authentication'}{$netloc}{default}
406 0 ▶ || [];
Condition0%0/8
$self->{'basic_authentication'}{$netloc}{$realm} || $self->{'basic_authentication'}{'default'}{$realm} || $self->{'basic_authentication'}{$netloc}{'default'} || []
l!l
00
$self->{"basic_authentication"}{$netloc}{$realm} or $self->{"basic_authentication"}{"default"}{$realm} or $self->{"basic_authentication"}{$netloc}{"default"}
l!l&&r!l&&!r
000
$self->{"basic_authentication"}{$netloc}{$realm} or $self->{"basic_authentication"}{"default"}{$realm}
l!l&&r!l&&!r
000
MC/DC0%0/3
$self->{'basic_authentication'}{$netloc}{$realm} || $self->{'basic_authentication'}{'default'}{$realm} || $self->{'basic_authentication'}{$netloc}{'default'} || []
$self->{"basic_authentication"}{$netloc}{$realm} $self->{"basic_authentication"}{"default"}{$realm} $self->{"basic_authentication"}{$netloc}{"default"}
Truth table0%0/4
A or B or C
A= $self->{"basic_authentication"}{$netloc}{$realm}B= $self->{"basic_authentication"}{"default"}{$realm}C= $self->{"basic_authentication"}{$netloc}{"default"}
ABCresult
1XX1
01X1
0011
0000
407  
408 0 ▶ print "Using user/pass combo: @$userpass. For $realm, $uri\n"
Branch: 1 branch
BranchTrueFalseTotal
if $HTTP::DAV::DEBUG > 2 0 0 0
409 if $HTTP::DAV::DEBUG > 2;
410  
411 }
412 0 return @$userpass;
413 }
414  
415 # Override to disallow redirects. Also, see RT #19616
416 0 ▶ sub redirect_ok {
Subroutine redirect_ok: not called CC=1 SCAR=6.9
417 0 return 0;
418 }
419  
420 }
421  
422 ###########################################################################
423 # We make our own special version of HTTP::Headers
424 # called HTTP::DAV::Headers. This is because we want to add
425 # a new method called add_headers
426 {
427  
428 4 package HTTP::DAV::Headers;
429  
430 4 ▶ use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
431 4 ▶ use vars qw(@ISA);
Subroutine BEGIN: called CC=1 SCAR=0.0
432  
433 4 @ISA = qw( HTTP::Headers );
434 4 require HTTP::Headers;
435  
436 # $dav_headers = HTTP::DAV::Headers->clone( $http_headers );
437  
438 0 ▶ sub to_http_headers {
Subroutine to_http_headers: not called CC=1 SCAR=6.9
439 0 my ($self) = @_;
440 0 my %clone = %{$self};
441 0 bless {%clone}, "HTTP::Headers";
442 }
443  
444 0 ▶ sub clone {
Subroutine clone: not called CC=2 SCAR=17.9
445 0 my ( $class, $headers ) = @_;
446 0 my %clone = %{$headers};
447 0 ▶ bless {%clone}, ref($class) || $class;
Condition0%0/3
ref $class || $class
l!l&&r!l&&!r
000
MC/DC0%0/2
ref $class || $class
ref $class $class
Truth table0%0/3
A || B
A= ref $classB= $class
ABresult
1X1
011
000
448 }
449  
450 0 ▶ sub add_headers {
Subroutine add_headers: not called CC=4 SCAR=30.0
451 0 my ( $self, $headers ) = @_;
452 0 ▶ return unless ( defined $headers && ref($headers) =~ /Headers/ );
Branch: 1 branch
BranchTrueFalseTotal
unless defined $headers and ref($headers) =~ /Headers/ 0 0 0
Condition0%0/3
defined $headers and ref($headers) =~ /Headers/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $headers and ref($headers) =~ /Headers/
defined $headers ref($headers) =~ /Headers/
Truth table0%0/3
A and B
A= defined $headersB= ref($headers) =~ /Headers/
ABresult
0X0
100
111
453  
454 #print "About to add headers!!\n";
455 #print Data::Dumper->Dump( [$headers] , [ '$headers' ] );
456 0 foreach my $key ( sort keys %$headers ) {
457 0 $self->header( $key, $headers->{$key} );
458 }
459 }
460 }
461  
462 4 1;
↑ Summary DAV/Resource.pm »