HTTP::Message uses top-level require where its siblings use "use Foo ()"
Chưa có ai nhận issue này.
Đánh giá
- Độ khó
- 1/5
- Thời gian dự kiến
- Dưới một giờ
- Mức phù hợp với người mới
- 88/100
Hướng nghiên cứu
Mở lib/HTTP/Message.pm và kiểm tra hai câu lệnh require ở cấp cao nhất cùng với các import tương ứng trong lib/HTTP/Headers.pm và lib/HTTP/Request/Common.pm. Chỉ thay đổi các dòng cấp cao nhất đó để sử dụng các danh sách import rỗng, giữ nguyên các lazy requires được thụt lề và phần phá vỡ phụ thuộc vòng. Hoàn tất khi các import ở cấp cao nhất khớp với các import của các module cùng nhóm mà không thay đổi hành vi lúc chạy.
Do mô hình lập chỉ mục viết ra từ nội dung của issue.
Mô tả
lib/HTTP/Message.pm opens with two top-level requires:
require HTTP::Headers;
require Carp;
Its sibling lib/HTTP/Headers.pm does the same job with the modern idiom:
use Carp ();
as does lib/HTTP/Request/Common.pm (use Carp();). Message.pm is the odd one out. Digging into why turned out to be more interesting than "old code".
History
The require Carp is not drift -- it was a deliberate change, and the commit message says so outright:
commit 25b4071747eb0bcaddd3978e0a2f17f7d84ce34c
Author: Gisle Aas <[email protected]>
Date: Sun Aug 27 22:32:25 1995 +0000
Cange "use Carp;" into "require Carp;"
require HTTP::Headers;
-use Carp;
+require Carp;
The intent was load it, don't import it, and the call sites were qualified to match. That intent still holds today: Message.pm has 14 fully-qualified Carp:: calls and zero bare croak/carp. HTTP::Headers exports nothing at all, so neither line wants an import.
Critically, that 1995 commit touched both Message.pm and Headers.pm -- they were changed in lockstep.
They stopped being in lockstep two and a half years later. In January 1998, in a commit whose message is just Added $VERSION., Headers.pm was modernized as a drive-by:
commit 7d89cffe...
Author: Gisle Aas <[email protected]>
Date: Tue Jan 6 1998
+use vars qw($VERSION);
+$VERSION = sprintf("%d.%02d", q$Revision: 1.31 $ =~ /(\d+)\.(\d+)/);
-require Carp;
+use Carp ();
Message.pm never got the same treatment. So the inconsistency is a 28-year-old missed edit, buried in a commit that wasn't about imports and wouldn't turn up in any search for one.
require HTTP::Headers is older still -- it dates from ef6daa1c (9 Aug 1995, "Renamed to HTTP::Message, and use HTTP::Headers.") and was written as a require from the start.
What should NOT change
Message.pm has ~25 further requires indented inside subs. Almost all are deliberate and need to stay:
- Optional / heavy dependencies loaded on demand --
Compress::Raw::Zlib,Compress::Raw::Bzip2,IO::Uncompress::*,IO::Compress::*,Encode,MIME::Base64,MIME::QuotedPrint,IO::HTML. Lazy loading is the entire point. - A circular-dependency break at lines 793-794:
Both of those dorequire HTTP::Request; require HTTP::Response;use parent 'HTTP::Message', soMessage.pmcannot load them at file scope. This one is load-bearing.
Any "prefer use over require" sweep over this file would be wrong for roughly 23 of the 25.
Proposed change
Only the two top-level lines:
-require HTTP::Headers;
-require Carp;
+use HTTP::Headers ();
+use Carp ();
This is cosmetic. At file scope both forms execute during the enclosing load, so there is no behaviour change; use merely fails at compile time rather than run time, and the file stops contradicting its own siblings.
I checked for a dependency cycle before proposing it: HTTP::Headers does not reference HTTP::Message anywhere (the require HTTP::Headers in Headers.pm is inside the SYNOPSIS pod, after __END__). Within the distribution only Request.pm and Response.pm load HTTP::Message, and that cycle is already handled at lines 793-794. So promoting these two to compile time is safe.
Happy to send a PR if this is wanted. Equally happy for it to be closed as not worth the churn -- the code has been correct for 30 years and this is purely a consistency argument.
- Ngôn ngữ chính
- Perl
- Star
- 32
- Fork
- 62
- Chỉ số merge pull request
- Không có pull request nào được merge trong 30 ngày
Chuẩn bị môi trường
- Không có Dockerfile hay tệp Docker Compose
- Không có mẫu pull request
- Đọc hướng dẫn đóng góp
Bắt đầu từ đâu
- Đọc hết issue, rồi đọc hướng dẫn đóng góp của dự án.
- Bình luận trên issue rằng bạn sẽ nhận — tránh hai người làm cùng một việc.
- Fork repository và làm thay đổi trên một nhánh.
- Mở pull request có tham chiếu số hiệu của issue.
Issue khác của libwww-perl/HTTP-Message
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 72/100
libwww-perl/HTTP-Message#236 ·
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 82/100
libwww-perl/HTTP-Message#227 ·
-
Độ khó 3/5 1-2 ngày Mức phù hợp với người mới 42/100
libwww-perl/HTTP-Message#216 ·
-
Please add a security policyĐang mở
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 35/100
libwww-perl/HTTP-Message#207 · 1 bình luận ·
-
Decoding of deflate content-encoding doesn't respect max_body_sizeCó thể đã có người làm @simbabque đã nhận 555 ngày trước. Đang mở
libwww-perl/HTTP-Message#206 · 1 bình luận · 1 người được giao ·
Tất cả issue của libwww-perl/HTTP-Message
Issue tương tự
-
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 88/100
virtualmin/virtualmin-gpl#1325 ·
-
check_keywords.pl dies before reporting an unknown keyword categoryCó thể đã có người làm @zhaohai666 đã nhận 1 ngày trước. Đang mở
Độ khó 1/5 Dưới một giờ Mức phù hợp với người mới 87/100
Maintainer thường phản hồi trong vòng 1 ngày
-
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 76/100
-
1.severity: security
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 68/100
Maintainer thường phản hồi trong vòng 1 ngày
-
wave-followup
Độ khó 2/5 1-3 giờ Mức phù hợp với người mới 74/100