Skip to content

Commit a9c6608

Browse files
oaldersclaude
andcommitted
guard method with defined to avoid uninitialized warning on Perl < 5.12
length(undef) warns "Use of uninitialized value in length" under use warnings on Perl < 5.12, which is reachable via as_string/dump on a request with no method (e.g. HTTP::Request->new). This module supports back to 5.008001, so guard with defined first, matching the uri handling on the same line. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
1 parent 2e1c50d commit a9c6608

1 file changed

Lines changed: 2 additions & 2 deletions

File tree

lib/HTTP/Request.pm

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ sub as_string
119119
$eol = "\n" unless defined $eol;
120120

121121
# method must be at least one char, matching ^[a-zA-Z0-9!#$%&'*+.^_`|~-]+$
122-
my $req_line = (length $self->method) ? $self->method : "-";
122+
my $req_line = (defined $self->method && length $self->method) ? $self->method : "-";
123123
my $uri = $self->uri;
124124
$uri = (defined $uri) ? $uri->as_string : "-";
125125
$req_line .= " $uri";
@@ -132,7 +132,7 @@ sub as_string
132132
sub dump
133133
{
134134
my $self = shift;
135-
my @pre = ((length $self->method) ? $self->method : "-", (defined $self->uri) ? $self->uri : "-");
135+
my @pre = ((defined $self->method && length $self->method) ? $self->method : "-", (defined $self->uri) ? $self->uri : "-");
136136
if (my $prot = $self->protocol) {
137137
push(@pre, $prot);
138138
}

0 commit comments

Comments
 (0)