#!/usr/bin/perl
 
# perl cookbook recipie 20.1
# titlebytes - find the titile and size of documents
use LWP::UserAgent;
use HTTP::Request;
use HTTP::Response;
use URI::Heuristic;

my $raw_url = shift   or die "usage: $0 url\n";
my $url = URI::Heuristic::uf_urlstr($raw_url);

$| = 1;   # to flush next line

printf "%s =>\n\t", $url;

#creat the object user agent
my $ua = LWP::UserAgent->new();
  $ua->agent("ALL-YOUR-BASE-ARE-BELONG-TO-US/v9.14 Platinum"); #fake browser identity

#create the object request 
my $req = HTTP::Request->new(GET=>$url);
  $req->referer("http://your_mama.org");   #fake referer

# create the object response, feed it the request object
my $response = $ua->request($req);
    
# check to see if we got an error
if ($response->is_error()){
  printf " %s\n", $response->status_line;
} else {
  # assign the returned text to the string $content
  my $content = $response->content() ;
  #printf "%s \n", $content;
  my $bytes = length $content;
  my $count = ( $content =~ tr/\n/\n/);
  printf "%s (%d lines, %d bytes)\n", $response->title(), $count, $bytes; 
}

