The Perl Toolchain Summit 2025 Needs You: You can help 🙏 Learn more

package Fetcher;
use strict;
use Carp;
#ץȡָ¶¨Á´½Ó£¬·µ»ØÄÚÈÝ»òÕß¿Õ
sub fetch{
my $class = shift ;
my $seed = shift || Carp->croak("ÐèÒªseed¡£¡£¡£¡£¡£");
my $ua = LWP::UserAgent->new;
$ua->agent("MyApp/0.1 ");
###¶à¸öÍøÕ¾####µÃÑо¿ÍøÕ¾µÄ½á¹¹£¬±éÀúÊ÷£¬¹Ø¼ü´Ê¹ýÂË¡£
# Create a request
my $req = HTTP::Request->new(GET => $seed);
# Pass request to the user agent and get a response back
my $res = $ua->request($req);
# Check the outcome of the response
if ($res->is_success) {
my $content = $res->content;
return $content;
}
else {
#print $res->status_line, "\n";
return undef;
}
}
1;