$ ./1.lwp.pl execution here execution there $ cat 1.lwp.pl #!/usr/bin/perl use 5.016; use warnings; use LWP::Online 'online'; say "execution here"; # "Is the internet working?" die "NO INTARWWEB!!!" unless online(); say "execution there"; __END__ $ #### # Set up configuration data use vars qw{%SUPPORTED @RELIABLE_HTTP}; BEGIN { # What transports do we support %SUPPORTED = map { $_ => 1 } qw{ http }; # (Relatively) reliable websites @RELIABLE_HTTP = ( # These are some initial trivial checks. # The regex are case-sensitive to at least # deal with the "couldn't get site.com case". 'http://www.msftncsi.com/ncsi.txt' => sub { $_ eq 'Microsoft NCSI' }, 'http://google.com/' => sub { /About Google/ }, 'http://yahoo.com/' => sub { /Yahoo!/ }, 'http://amazon.com/' => sub { /Amazon/ and /Cart/ }, 'http://cnn.com/' => sub { /CNN/ }, ); } #### use LWP::Simple 5.805 qw{ get $ua }; use vars qw{$VERSION @ISA @EXPORT_OK}; BEGIN { $VERSION = '1.08'; # We are an Exporter require Exporter; @ISA = qw{ Exporter }; @EXPORT_OK = qw{ online offline }; # Set the useragent timeout $ua->timeout(30); } #### sub get ($) { my $response = $ua->get(shift); return $response->decoded_content if $response->is_success; return undef; }